Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?

If the next representable value after -0.0 is +0.0, then why nextafter(-0.0, INFINITY) does not return +0.0?

like image 932
pmor Avatar asked Oct 29 '25 17:10

pmor


1 Answers

If the next representable value after -0.0 is +0.0 ....

False premise.
-0.0 and +0.0 have the same value.
if (-0.0 == +0.0) is true.

nextafter() "functions determine the next representable value" (C17dr § 7.12.11.3 2)

nextafter(-0.0, INFINITY) and nextafter(+0.0, INFINITY) both return DBL_TRUE_MIN.


+0.0 and -0.0 often make no functional difference. Sometimes they do make a difference.


Advanced: Be prepared for C2X with expected decimal floating point support as there are many encoding sets of decimal64 that have the same value. Repeated use of nextafter() and friends does not form a sequence through all FP encodings.

like image 177
chux - Reinstate Monica Avatar answered Oct 31 '25 06:10

chux - Reinstate Monica