[Cfp-interest 2206] Re: contradiction about the INFINITY macro

Fred J. Tydeman tydeman at tybor.com
Tue Oct 5 18:41:12 PDT 2021


On Wed, 6 Oct 2021 02:38:27 +0200 Vincent Lefevre wrote:
>
>On 2021-10-05 11:13:59 -0700, Jim Thomas wrote:
>> I suggest changing 
>> 
>>      else to a positive constant of type float that overflows at translation time
>> 
>> to
>> 
>>      else to an expression of type float that overflows with positive sign at translation time
>> 
>> This is intended to allow the implementation to use whatever magic is needed.
>> 
>> I had lost track of this issue and neglected to put it on the September CFP agenda. If we can converge on a resolution, 
>and if no one objects, I can submit a paper with our agreed suggested change before the deadline. Please send any 
>comments ASAP.
>
>Wouldn't it be better to require INFINITY to be defined if and only if
>the type float supports infinity, so that this can be tested?
>
>In the comp.std.c thread "contradiction about the INFINITY macro"
>https://groups.google.com/g/comp.std.c/c/XCzEiwD9n_A I started,
>Keith Thompson said:
>
>  (I wonder if it would have been more useful to require that INFINITY not
>  be defined unless it can be defined as an actual infinity, but I haven't
>  given it a lot of thought.)
>
>Note that in the current standard and with the suggested change, if
>infinity is not supported, then the use of INFINITY yields an overflow
>at translation time, which implies undefined behavior (even if the
>value will never be used). This is rather useless.
>
>Moreover, shouldn't infinity be supported for all FP types or none?
>Keith Thompson said:
>
>  The INFINITY and NAN macros are defined only for float.  I think the
>  assumption is that either all floating-point types support infinities,
>  or none do, and likewise for NaNs.  On the other hand, fpclassify() is a
>  macro that can be applied to an expression of any floating-point type.

He also mentioned the C99 rationale:

What is INFINITY on machines that do not support infinity? It should be defined along the
lines of: #define INFINITY 9e99999f, where there are enough 9s in the exponent so that
the value is too large to represent as a float, hence, violates the constraint of 6.4.4 Constants.
In addition, the number classification macro FP_INFINITE should not be defined. That allows
an application to test for the existance of FP_INFINITE as a safe way to determine if infinity is
supported; this is the feature test macro for support for infinity.



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



More information about the Cfp-interest mailing list