If the presence of subnormal numbers is optional (HAS_SUBNORM
feature macros), then why the presence of FP_SUBNORMAL
classification macro is mandatory?
Reason of the question: in this (still unanswered) question it was concluded / hypothesized that:
In case if HAS_SUBNORM is 0 the execution of any FP operation with inputs represented by manually constructed subnormal numbers (constructed using type punning via union, using memcpy, reading from file, etc.) leads to undefined behavior (UB).
This conclusion / hypothesis leads to multiple questions:
- Does it mean that in case of
HAS_SUBNORM is 0
it is not possible using C standard library to even detect the presence of subnormal numbers provided, for example, by the user?
Example:
float value = get_value(); // user input
#if FLT_HAS_SUBNORM == 0
int class = fpclassify( value ); // leads to UB if value is subnormal number
if ( class == FP_SUBNORMAL )
{
error( "subnormal numbers are not supported" );
}
#endif
- Should the presence of
FP_SUBNORMAL
depend on disjunction ofHAS_SUBNORM
macros set to1
? I.e.:
#if FLT_HAS_SUBNORM == 1 || DBL_HAS_SUBNORM == 1 || LDBL_HAS_SUBNORM == 1
// FP_SUBNORMAL is present
#else
// FP_SUBNORMAL is absent
#endif
- Does the fact that the
FP_SUBNORMAL
classification macro is mandatory signify that in case ofHAS_SUBNORM is 0
the execution offpclassify
macro with inputs represented by manually constructed subnormal numbers shall lead to well-defined behavior?
UPD 20210527. In comparison with rounding modes (C11, 7.6.8) (emphasis added):
Each of the macros FE_DOWNWARD ... is defined if and only if the implementation supports getting and setting the represented rounding direction by means of the fegetround and fesetround functions.