bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mpf: x / x != 1


From: Peter Moulder
Subject: mpf: x / x != 1
Date: 01 Jul 2001 14:19:37 +1000

GMP Version: 3.1.1

Excerpt from the texinfo documentation for mpf:

     The precision of a calculation is defined as follows: Compute the
  requested operation exactly (with "infinite precision"), and truncate
  the result to the destination variable precision.

To me, the above suggests that x / x should always result in 1 (for
non-zero x), and that a comparison with 1 (using mpf_cmp etc.) would
return 0.

The below program shows that this is not so for x = a tiny
bit less than 40.

  #include <gmp.h>
  
  int main(void)
  {
    mpf_t x, one;
    int r;
  
    mpf_init2( x, 1024);
    mpf_set_si( x, -0x280);
    mpf_div_2exp( x, x, 33*32);
    mpf_add_ui( x, x, 40);
  
    mpf_div( x, x, x);
    r = mpf_cmp_ui( x, 1);
    printf("cmp(x/x, 1) returns %d\n", r);
  }

pjm.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]