This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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


Tobias Burnus wrote:
:ADDPATCH fortran:

We had several problems with the compile-time evaluation for NEAREST for
0.0 and subnormal numbers.

From the standard:

-------------------- cut ---------------


"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."

-------------------- cut ---------------


Problems:


a) gfortran gave an range error for the returned subnormal number
b) gfortran returned 0.0 as nearest number of 0.0, which is plainly wrong.

To (a): With the current patch, only for NaN an error is printed; one
might extend it to +/-INF if it is regarded as useful.

To (b): The fix was done in three steps:

1. Reverting to Steve's old patch
2. Fixing the returned result using Steve's suggestion
3. Fixing rounding of subnormal numbers

Thanks to Steve for the help! And to Paul Zimmermann, who send a similar
suggestion as Steve's for (2).

Build and regression tested on x86-64. OK for the trunk?

Tobias


Tobias, this looks good. OK


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 can write a value to a string and test for "NaN" or "Infinity". Its crude but effective.


Jerry


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