Skip to content

Commit 671e4c1

Browse files
committed
feenv tests: add STDC FENV_ACCESS ON
1 parent 33c842b commit 671e4c1

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎c/float32.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ float lkmc_float32_from_bytes(
3939
return *(float*)&bytes;
4040
}
4141

42+
float lkmc_float32_snan(uint32_t i) {
43+
return lkmc_float32_from_bytes(0, 0xFF, 0x200000 + i);
44+
}
45+
4246
int lkmc_float32_equal(
4347
float f,
4448
uint32_t sign,

‎cpp/nan.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "../c/float32.h"
1010

11+
#pragma STDC FENV_ACCESS ON
12+
1113
int main() {
1214
if (
1315
std::numeric_limits<float>::has_signaling_NaN &&

‎glibc/interactive/feenableexcept.cpp‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// In C++ for signling_NaN.
2+
//
3+
// In GCC 8.2, sNaN is only done in -O0 and completely skipped in -O3.
4+
// I'm not sure if there is a way to enforce it to happen.
25

36
#include <cassert>
47
#include <cfenv>
@@ -9,7 +12,10 @@
912
#include <limits> // std::numeric_limits
1013
#include <unistd.h>
1114

15+
#pragma STDC FENV_ACCESS ON
16+
1217
void handler(int signum) {
18+
(void)signum;
1319
char message[] = "handler\n";
1420
write(STDOUT_FILENO, message, sizeof(message));
1521
feclearexcept(FE_ALL_EXCEPT);
@@ -30,12 +36,14 @@ int main() {
3036
// Still no exceptions because qNaN.
3137
f = qnan + 1.0f;
3238
assert(std::isnan(f));
33-
assert(std::fetestexcept(FE_ALL_EXCEPT) == 0);
39+
if (std::fetestexcept(FE_ALL_EXCEPT) == FE_INVALID)
40+
std::cout << "FE_ALL_EXCEPT qnan + 1.0f" << std::endl;
3441

35-
// Now we get an exception because sNaN, but signals are disabled.
42+
// Now we can get an exception because sNaN, but signals are disabled.
3643
f = snan + 1.0f;
3744
assert(std::isnan(f));
38-
assert(std::fetestexcept(FE_ALL_EXCEPT) == FE_INVALID);
45+
if (std::fetestexcept(FE_ALL_EXCEPT) == FE_INVALID)
46+
std::cout << "FE_ALL_EXCEPT snan + 1.0f" << std::endl;
3947
feclearexcept(FE_ALL_EXCEPT);
4048

4149
#if 0
@@ -53,9 +61,8 @@ int main() {
5361
// And now we enable signals and blow up with SIGFPE! >:-)
5462
feenableexcept(FE_INVALID);
5563
f = qnan + 1.0f;
56-
std::cout << "quiet" << std::endl;
64+
std::cout << "feenableexcept qnan + 1.0f" << std::endl;
5765
f = snan + 1.0f;
58-
// Never reached.
59-
std::cout << "signaling" << std::endl;
66+
std::cout << "feenableexcept snan + 1.0f" << std::endl;
6067
}
6168
}

0 commit comments

Comments
 (0)