Skip to content

Commit

Permalink
Merge pull request #11485 from mixxxdj/denormals_test_fix
Browse files Browse the repository at this point in the history
Fix MathUtil.Denormals with clang 15/16
  • Loading branch information
Swiftb0y authored Apr 17, 2023
2 parents 16c4343 + c9342ec commit 0c4e1e3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/test/mathutiltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@ TEST_F(MathUtilTest, Denormal) {
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);

volatile float fDenormal = std::numeric_limits<float>::min() / 2.0f;
// Note: The volatile keyword makes sure that the division is executed on the target
// and not by the pre-processor. In case of clang >= 15 the pre-processor flushes to
// zero with -ffast-math enabled.
volatile float fDenormal = std::numeric_limits<float>::min();
fDenormal /= 2.0f;
EXPECT_NE(0.0f, fDenormal);

volatile double dDenormal = std::numeric_limits<double>::min() / 2.0;
volatile double dDenormal = std::numeric_limits<double>::min();
dDenormal /= 2.0;
EXPECT_NE(0.0, dDenormal);

_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);

fDenormal = std::numeric_limits<float>::min() / 2.0f;
fDenormal = std::numeric_limits<float>::min();
fDenormal /= 2.0f;
EXPECT_EQ(0.0f, fDenormal);

dDenormal = std::numeric_limits<double>::min() / 2.0;
dDenormal = std::numeric_limits<double>::min();
dDenormal /= 2.0;
EXPECT_EQ(0.0, dDenormal);

#endif
Expand Down

0 comments on commit 0c4e1e3

Please sign in to comment.