[cfp-interest 3459] Re: nexttoward

Jim Thomas jaswthomas at sbcglobal.net
Wed May 14 15:03:43 PDT 2025


If the library implementation does not claim conformance to Annex F it can choose to not report an underflow range error, even if math_errhandling & MATH_ERREXCEPT is nonzero. This means the (non-Annex F) implementation can choose to not raise the floating-point exceptions in these cases.

However, Annex F conformance requires the floating-point exceptions in these cases. F.10.9.3 says

— nextafter(x, y) raises the "underflow" and "inexact" floating-point exceptions for the function value subnormal or zero and x ≠ y.

Annex F took this spec from IEEE 754-1985 and retains it as a legacy feature though revisions of IEEE 754 do not include the nextafter functions.

- Jim Thomas

> On May 14, 2025, at 8:29 AM, LNT <lntue.h at gmail.com> wrote:
> 
> Sorry for a late reply / update about nexttoward / nextafter issue with underflow exceptions.
> 
> On the latest draft of C2y, section 7.12.2.7 about underflow is as follow:
> 
> The result underflows if a nonzero result value with ordinary accuracy would have magnitude (absolute value) less than the minimum normalized number in the type;
> however a zero result that is specified to be an exact zero does not underflow. Also, a result with ordinary accuracy and the magnitude of the minimum normalized number may underflow.274)
> If the result underflows, the function returns an implementation-defined value whose magnitude is no greater than the smallest normalized positive number in the specified type;
> if the integer expression math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the value ERANGE is implementation-defined;
> if the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, whether the "underflow" floating-point exception is raised is implementation-defined.
> 
> So does it mean that the library implementation can choose to not raise the floating point exceptions in this case (and document the decision) and still conform to the standard?
> 
> Thanks,
>    Tue
> 
> On Tue, Mar 4, 2025 at 8:47 AM Vincent Lefevre <vincent at vinc17.net <mailto:vincent at vinc17.net>> wrote:
>> On 2025-03-04 09:12:36 +0100, Paul Zimmermann wrote:
>> > but there is no underflow requirement in 754-2008 nor in 754-2019
>> > (where the only related functions are nextUp and nextDown).
>> 
>> Indeed, the overflow/underflow/inexact exceptions for nextafter
>> in 754-1985 were nonsense since there is no rounding (note that
>> the "as if the exponent range were unbounded" cannot be used
>> here, as nextafter would not return the expected result).
>> 
>> -- 
>> Vincent Lefèvre <vincent at vinc17.net <mailto:vincent at vinc17.net>> - Web: <https://www.vinc17.net/>
>> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
>> Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
>> _______________________________________________
>> cfp-interest mailing list
>> cfp-interest at oakapple.net <mailto:cfp-interest at oakapple.net>
>> http://mailman.oakapple.net/mailman/listinfo/cfp-interest
> _______________________________________________
> cfp-interest mailing list
> cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20250514/4d6b3531/attachment.htm>


More information about the cfp-interest mailing list