Simple question: If FLT_HAS_SUBNORM
is 0, then shall conversion (float)1E-45
return 0x1p-149
?
Reason of the question: ISO/IEC 9899:2011 (E) specifies behavior of FLT_HAS_SUBNORM
/ DBL_HAS_SUBNORM
only wrt floating-point operations. According to H.2.3.2 (Floating-point operations) conversion between floating-point precisions (term which is taken from F.3 Operators and functions) is not floating-point operation. Hence, behavior specified for FLT_HAS_SUBNORM
/ DBL_HAS_SUBNORM
is irrelevant for conversion between floating-point precisions. Therefore, the conclusion is that conversion (float)1E-45
shall return 0x1p-149
. Is this conclusion correct?
UPD: Explanation of the reasons of these questions: currently I have tests which test the correctness of results generated by FP operations (conversions included). I run these tests under environments with FLT_HAS_SUBNORM is 0
and with FLT_HAS_SUBNORM is -1
. The main issue is that in some combinations of compiler options some tests are failing.
For example: under FLT_HAS_SUBNORM is 0
:
- HW (FPU) FP:
(float)1E-45
returns0x1p-149f
- SW (libfp) FP:
(float)1E-45
returns0.0f
Reference value in test: 0.0f
.
Therefore, there is a need to understand if:
- Test has a bug (written incorrectly: for example, no check for
HAS_SUBNORM
); or - Compiler has a bug; or
- SW (libfp) FP has a bug; or
- HW (FPU) FP has a bug (bug in simulator; it happens too); or
- All possible combinations of the previous cases.
The first step is to read the standards (C / IEEE 754) and try to answer the open questions. However, it turns out that wrt FP many aspects are not explicitly defined. Hence, what is the most rational way to handle the situation with existing failing tests?
Please also note that ideally tests are written independently and in a "generic way" (examining the features of the system / environment: checking feature macros, checking limits, etc.), i.e. w/o knowing a particular FP details of a particular compiler used for FP computations (or as people call it FP environment).