Issue
Sample code (t0.c):
#include <stdio.h> // fix for clang, see https://stackoverflow.com/q/69976945/1778275
#if __STDC_IEC_559__ == 1
#pragma message "__STDC_IEC_559__ is 1"
#else
#pragma message "__STDC_IEC_559__ is not 1"
#endif
Invocations:
# gcc 11.2 on Linux on x86-64
$ gcc t0.c -std=c11 -pedantic -Wall -Wextra -fno-rounding-math
t0.c:3:9: note: '#pragma message: __STDC_IEC_559__ is 1'
# clang 13.0.0 on Linux on x86-64
$ clang t0.c -std=c11 -pedantic -Wall -Wextra -ffp-model=fast
t0.c:3:9: warning: __STDC_IEC_559__ is 1 [-W#pragma-messages]
# icc 2021.1.2 on Linux on x86-64
$ icc t0.c -std=c11 -pedantic -Wall -Wextra -fp-model=fast
__STDC_IEC_559__ is 1
Here we see that non-strict floating-point models does not change the value 1
of __STDC_IEC_559__
. Why?
UPD20211126: Re:
The switch itself does not change the rounding behaviour, and thus does not change whether the macro is defined.
Now gcc under -fno-rounding-math
miscompiles the following program (t1.c):
#include <stdio.h>
#include <float.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
int main(void)
{
#if __STDC_IEC_559__ == 1
if (fesetround(FE_UPWARD) == 0)
{
printf("%a\n", FLT_MIN / 1.0000001f);
}
#endif
return 0;
}
Invocation & execution:
# gcc 11.2 on Linux on x86-64
gcc t1.c -std=c11 -pedantic -Wall -Wextra -lm -fno-rounding-math && ./a.out
t1.c:5: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]
0x1.fffffcp-127
# gcc 11.2 on Linux on x86-64
gcc t1.c -std=c11 -pedantic -Wall -Wextra -lm -frounding-math && ./a.out
t1.c:5: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]
0x1p-126
Here we see that under __STDC_IEC_559__ == 1
the results are different. Unexpected.
Note: Yes, in gcc Pragma STDC * (C99 FP) unimplemented.
UPD20211130. Out of curiosity: if these implementations under non-strict floating-point models do not conform to the specifications in the Annex F, then for which purpose they define __STDC_IEC_559__
to 1
?
Solution
Because it seems that they are buggy.
UPD.
- Defining
__STDC_IEC_559__
to1
in case of no conformance to the specifications in the Annex F is not a bug. - Usually non-strict floating-point models imply no conformance to the specifications in the Annex F. If so, then it is unclear, for which purpose
__STDC_IEC_559__
is defined to1
.
Answered By - pmor Answer Checked By - Timothy Miller (WPSolving Admin)