This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/34192] [4.2, 4.3 Regression] NEAREST can return wrong numbers



------- Comment #4 from burnus at gcc dot gnu dot org  2007-11-22 17:08 -------
Regarding the range check: We need to disable the check for denormal numbers;
as overflow etc. cannot occur, this boils down to check only for NaN.


Regarding the result, I think we have a problem with MPFR. The following
program prints:

Result (GMP_RNDN): 0
Result (GMP_RNDU): 4.94066e-324

As mpfr_nexttoward should return a representable number, there should be no
rounding needed, or should it? By the way, changing GFC_REAL_8_DIGITS did not
change the result.

See also:
http://www.mpfr.org/mpfr-2.3.0/mpfr.html#index-mpfr_005fnexttoward-224


#include <gmp.h>
#include <mpfr.h>
#include <stdio.h>
#define GFC_REAL_8_DIGITS 53

int main()
{
  mpfr_t x;
  mpfr_t y;
  int base2prec;
  double result;

  mpfr_set_default_prec (GFC_REAL_8_DIGITS);
  mpfr_init(x);
  mpfr_init(y);
  mpfr_set_d (x, 0.0, GMP_RNDN); /* x = 0.0         */
  mpfr_set_inf (y, 1);           /* y = INF         */
  mpfr_nexttoward (x, y);        /* x = x + epsilon */
  printf("Result (GMP_RNDN): %g\n", mpfr_get_d(x, GMP_RNDN));
  printf("Result (GMP_RNDU): %g\n", mpfr_get_d(x, GMP_RNDU));
  return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34192


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]