The following program program chop real o, t, td, tu, x, y o = 1. t = tiny(o) td = nearest(t,-1.0) x = td/2.0 y = nearest(tiny(o),-1.0)/2.0 print *, x, y, x - y end program chop gives 5.8774718E-39 5.8774704E-39 1.4012985E-45 on OSX 10.3.9 and GNU Fortran 95 (GCC) 4.2.0 20060401 (experimental). I.e, nearest(tiny(o),-1.0)/2.0 does not give the same result as td = nearest(t,-1.0) x = td/2.0 Dominique
on x86-linux gfortran 5.8774718E-39 5.8774704E-39 1.4012985E-45 f90 5.8774718E-39 5.8774718E-39 0.0000000E+00 pgf90 5.8774718E-39 5.8774718E-39 0.0000000
I sent a preliminary patch for this problem to fortran@ http://gcc.gnu.org/ml/fortran/2006-04/msg00084.html
Subject: Bug 27021 Author: kargl Date: Wed Sep 27 20:15:22 2006 New Revision: 117257 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117257 Log: * configure.in: Check for GMP 4.1 or newer. Check for MPFR 2.2.0 or newer. * configure: Regenerated. * doc/install.texi: Document required versions of GMP and MPFR. * fortran/arith.c: Conditionally include arctangent2(). (gfc_check_real_range): Use mpfr_subnormalize in preference to local hack. * fortran/trans-intrinsic.c (gfc_get_intrinsic_lib_fndecl): Append l for long double functions. * fortran/simplify.c: Wrap Copyright to new line. (gfc_simplify_atan2): Use mpfr_atan2 in preference to arctangent2(). (gfc_simplify_log): Ditto. PR fortran/28276 * fortran/simplify.c (gfc_simplify_exponent): Use mpfr_get_exp in preference to broken local hack. PR fortran/27021 * fortran/simplify.c (gfc_simplify_nearest): Use mpfr_nexttoward and mpfr_subnormalize to handle numbers near zero in preference to broken local hack. PR fortran/28276 * testsuite/gfortran.dg/exponent_1.f90: New test. PR fortran/27021 * testsuite/gfortran.dg/nearest_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/exponent_1.f90 trunk/gcc/testsuite/gfortran.dg/nearest_1.f90 Modified: trunk/ChangeLog trunk/configure trunk/configure.in trunk/gcc/ChangeLog trunk/gcc/doc/install.texi trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/arith.c trunk/gcc/fortran/simplify.c trunk/gcc/fortran/trans-intrinsic.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk. Won't be fixed on 4.1.