[Cfp-interest 2749] Re: macros like DBL_MAX and FLT_EVAL_METHOD

Vincent Lefevre vincent at vinc17.net
Tue Apr 4 05:38:25 PDT 2023


On 2023-04-04 14:28:31 +0200, Vincent Lefevre wrote:
> The N3096 5.2.4.2.2p29 example says:
> 
>   The following describes floating-point representations that also
>   meet the requirements for single-precision and double-precision
>   numbers in IEC 60559,29) and the appropriate values in a <float.h>
>   header for types float and double:
> [...]
>   DBL_MAX  1.7976931348623157E+308 // decimal constant
> 
> But p19 says for FLT_EVAL_METHOD = 2: "evaluate all operations and
> constants to the range and precision of the long double type."
> 
> Note the "and constants". So this seems wrong if FLT_EVAL_METHOD = 2.
> 
> And even
> 
>   ((double) 1.7976931348623157E+308)
> 
> may not be correct, since if the FP_CONTRACT pragma is ON,
> (long double) DBL_MAX might not give the expected value.

Similarly, it gives

  FLT_MAX  3.40282347E+38F // decimal constant

Note that under Linux x86, with the 32-bit ABI:

cventin:~> printf "#include <float.h>\nFLT_EVAL_METHOD\nFLT_MAX\nDBL_MAX\n" | gcc -m32 -xc -E -
[...]
2
3.40282346638528859811704183484516925e+38F
((double)1.79769313486231570814527423731704357e+308L)

The number of digits is large enough to get the expected values.

-- 
Vincent Lefèvre <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 / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list