[Fortran, Patch] PR 34192 - Fix compile-time evaluation of NEAREST

Tobias Burnus burnus@net-b.de
Sat Nov 24 18:46:00 GMT 2007


FX Coudert wrote:
>> PS: Any idea how to test for INF and NAN? If I do "0.0/0.0" I get a
>> compile-time error and -fno-range-check does not help. I cannot assign
>> to a variable first as otherwise NEAREST is not evaluated at compile
>> time.
> You should be able to get an NaN by 0. / 0. with -fno-range-check, and
> same for Inf.
I think I used yesterday -fno-bounds-check instead of -fno-range-check,
which obviously does not work.

Now that it works, I committed additional NAN/INF tests for
nearest_2.f90; see attachment (Rev. 130396).

> PS: can someone confirm that the following is wrong?
>
> $ cat a.f90
>   real, parameter :: y = exp(log(huge(y))+20)
>   real, parameter :: x = log(y)
>   print *, x, y
>   end
> $ gfortran a.f90 -fno-range-check && ./a.out
>    108.72284           +Infinity
I agree that the logarithm of INF should be INF.

This is also what is printed at run time. I fail, however, to see why it
fails. Using a simple MPFR program (see below), it does give the
expected +INF. Could it be related to having the wrong emax at some point?

Can you fill a bugreport?

Tobias


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

int main()
{
  mpfr_t x, y;
  mpfr_set_default_prec (GFC_REAL_8_DIGITS);
  mpfr_init(x);
  mpfr_init(y);
  mpfr_set_inf (y, 1);
  mpfr_log(x, y, GMP_RNDN);
  printf("y = %g\n", mpfr_get_d(y, GMP_RNDN));
  printf("x = %g\n", mpfr_get_d(x, GMP_RNDN));
  return 0;
}
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: committed.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071124/b27d1b06/attachment.ksh>


More information about the Gcc-patches mailing list