This is the mail archive of the gcc-patches@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]

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


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;
}
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 130395)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2007-11-24  Tobias Burnus  <burnus@net-b.de>
+
+	PR fortran/34192
+	* gfortran.dg/nearest_2.f90: Add INF/NAN tests.
+
 2007-11-24  Paul Thomas  <pault@gcc.gnu.org>
 
 	PR fortran/33541
Index: gcc/testsuite/gfortran.dg/nearest_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/nearest_2.f90	(revision 130395)
+++ gcc/testsuite/gfortran.dg/nearest_2.f90	(working copy)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-options "-fno-range-check" }
 !
 ! PR fortran/34192
 !
@@ -76,6 +77,15 @@
       /= 42.0) &
     call abort()
 
+  ! INF+ = INF
+  if (nearest(1.0/0.0, 1.0) /= 1.0/0.0) call abort()
+  ! -INF- = -INF
+  if (nearest(-1.0/0.0, -1.0) /= -1.0/0.0) call abort()
+  ! NAN- = NAN
+  if (.not.isnan(nearest(0.0d0/0.0,  1.0))) call abort()
+  ! NAN+ = NAN
+  if (.not.isnan(nearest(0.0d0/0.0, -1.0))) call abort()
+
 ! Double precision
 
   ! 0+ > 0
@@ -144,4 +154,13 @@
   if (nearest(nearest(42.0d0, 1.0), -1.0) &
       /= 42.0d0) &
     call abort()
+
+  ! INF+ = INF
+  if (nearest(1.0d0/0.0d0, 1.0) /= 1.0d0/0.0d0) call abort()
+  ! -INF- = -INF
+  if (nearest(-1.0d0/0.0d0, -1.0) /= -1.0d0/0.0d0) call abort()
+  ! NAN- = NAN
+  if (.not.isnan(nearest(0.0d0/0.0,  1.0))) call abort()
+  ! NAN+ = NAN
+  if (.not.isnan(nearest(0.0d0/0.0, -1.0))) call abort()
 end program test

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