: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