[cfp-interest 3402] Re: nexttoward

Fred J. Tydeman tydeman at tybor.com
Tue Mar 4 03:19:14 PST 2025


On Tue, 04 Mar 2025 09:12:36 +0100 Paul Zimmermann wrote:
>
>> >I have a question about nexttoward(). The Linux man page says:
>> >
>> >       double nexttoward(double x, long double y);
>> >       If x is not equal to y, and the correct function result would be subnor-
>> >       mal, zero, or underflow, a range error occurs, and  either  the  correct
>> >       value (if it can be represented), or 0.0, is returned.
>> >
>> >For example nexttoward (0.0, 1.0) will set errno = ERANGE.
>> >
>> >I wonder why this is so, since for mathematical functions, underflow is not
>> >raised (and thus errno is not set to ERANGE) when the result is exact.
>> >And nexttoward always delivers an exact result.
>> 
>> IEEE-754-1985 "required" underflow for those cases.
>> However, that is in an Appendix of Recommended Functions
>
>but there is no underflow requirement in 754-2008 nor in 754-2019
>(where the only related functions are nextUp and nextDown).

Nexttoward is defined in terms of nextafter.
nextafter was added to C99.
C99 was trying to align with IEEE-754-1985

Once a function is added to C, it is VERY  hard to change its meaning.
So, we are stuck with raising underflow even though many people
on both IEEE 754 and WG14 believe it was a mistake.
That is why nextup and nextdown were added.



---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (702) 608-6093      Vice-chair of INCITS/C (ANSI "C")
Sample C17+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the cfp-interest mailing list