------- Comment #2 from burnus at gcc dot gnu dot org 2007-11-22 16:11 ------- I believe there is indeed a bug in gfortran. The standard says that the "the nearest different machine-representable number" is returned.
However, gfortran returns a number which is not representable (denormal or smaller?) and rounded to zero (= same number). Result (gfortran 4.3.0): a) The program is wrongly rejected b) With -fno-range-check, the wrong number is used. For the example the dump shows: static real(kind=8) C.859 = 0.0; The expected result is some denormal number like: 5.E-324, 4.9406564584124654E-324, 2.225073858507201E-308, 4.94065645841246544E-324, 4.940656458412465E-324. (The ifort result of 2e-308 looks wrong in this regard as there is a nearer number.) gfortran 4.1.3 returns: 4.940656458412465E-324 gfortran 4.2.2 rejects it and has an ICE with -fno-range-check Besides fixing this bug, we should also consider mentioning -fno-range-check in the error message. (Though, in this case -fno-range-check would have concealed the real bug.) The Fortran 2003 standard states: "NEAREST (X, S) Description. Returns the nearest different machine-representable number in a given direction. X shall be of type real. S shall be of type real and not equal to zero. Result Characteristics. Same as X. Result Value. The result has a value equal to the machine-representable number distinct from X and nearest to it in the direction of the infinity with the same sign as S. NOTE 13.16 Unlike other floating-point manipulation functions, NEAREST operates on machine-representable numbers rather than model numbers. On many systems there are machine-representable numbers that lie between adjacent model numbers." -- burnus at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu dot | |org OtherBugsDependingO| |32834 nThis| | GCC host triplet|Linux i686 | Keywords| |rejects-valid, wrong-code Known to fail| |4.2.2 4.3.0 Known to work| |4.1.3 Summary|problem with NEAREST |[4.2, 4.3 Regression] |intrinsic function |NEAREST can return wrong | |numbers http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34192