https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120993

--- Comment #5 from Paul Eggert <eggert at cs dot ucla.edu> ---
(In reply to Bruno Haible from comment #4)
> in order to get a practically useful model, one should choose the
> maximum possible value of p.
> 
> In the case of the 'double-double' representation, this value is p = 106.

That depends on what one means by "useful". Gnulib takes "useful" to mean
"numbers are representable in this binary format", and for this meaning, p =
106 indeed makes sense. However, as I understand it GCC takes "useful" to mean
"arithmetic works usefully on these numbers", for which p = 106 is excessive.

For example, GCC's LDBL_NORM_MAX is (2**1023 - 2**917), and in GCC
(LDBL_NORM_MAX - 0x1p917L) yields 2**1023 - 2**918 which is exactly correct. In
contrast Gnulib's LDBL_NORM_MAX is (2**1024 - 2**918) and in Gnulib
(LDBL_NORM_MAX - 0x1p918L) yields infinity, which is completely bogus as the
mathematical result is exactly representable. It's hard to argue that Gnulib
conforms to C23 here, unless one takes the position that floating point
operations can result in any value, even if wildly wrong - I wouldn't want to
go there myself.

One possible solution in Gnulib would be to shrink its LDBL_MAX_EXP from 1024
to 1023, and to shrink its LDBL_NORM_MAX to equal GCC's. As far as I know this
would fix the C23 conformance issue. I could easily implement that in Gnulib.

Similarly, GCC could fix its C23 conformance issue by shrinking its
LDBL_MAX_EXP from 1024 to 1023 without changing anything else. This would be
far less disruptive than my earlier proposal of changing LDBL_MANT_DIG,
LDBL_MAX_EXP, and LDBL_NORM_MAX to match their DBL_* counterparts.

Reply via email to