Skip to content

Commit d599ed4

Browse files
author
Siva Chandra Reddy
committed
[libc][NFC] Use ASSERT_FP_EQ to comapre NaN values in tests.
This is a continuation of the previous CL which did a similar change in other tests. To elaborate a little about why we need this - under C++ compilation with headers not from LLVM libc, libraries like libc++ and libstdc++ provide their own math.h which undefine macros like `isnan` and provide the overloaded C++ isnan functions which return a boolean value instead of an integer value returned by the isnan macro.
1 parent fdd6ed8 commit d599ed4

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

libc/test/src/math/FDimTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FDimTestTemplate : public __llvm_libc::testing::Test {
2626
EXPECT_FP_EQ(nan, func(negZero, nan));
2727
EXPECT_FP_EQ(nan, func(nan, T(-1.2345)));
2828
EXPECT_FP_EQ(nan, func(T(1.2345), nan));
29-
EXPECT_NE(isnan(func(nan, nan)), 0);
29+
EXPECT_FP_EQ(func(nan, nan), nan);
3030
}
3131

3232
void testInfArg(FuncPtr func) {

libc/test/src/math/RemQuoTest.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ class RemQuoTestTemplate : public __llvm_libc::testing::Test {
3838

3939
y = T(1.0);
4040
x = inf;
41-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
41+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
4242
x = negInf;
43-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
43+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
4444

4545
x = T(1.0);
4646
y = zero;
47-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
47+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
4848
y = negZero;
49-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
49+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
5050

5151
y = nan;
5252
x = T(1.0);
53-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
53+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
5454

5555
y = T(1.0);
5656
x = nan;
57-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
57+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
5858

5959
x = nan;
6060
y = nan;
61-
EXPECT_NE(isnan(func(x, y, &quotient)), 0);
61+
EXPECT_FP_EQ(nan, func(x, y, &quotient));
6262

6363
x = zero;
6464
y = T(1.0);

libc/test/src/math/fmax_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FmaxTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0, __llvm_libc::fmax(-0.0, aNaN));
2424
EXPECT_FP_EQ(-1.2345, __llvm_libc::fmax(aNaN, -1.2345));
2525
EXPECT_FP_EQ(1.2345, __llvm_libc::fmax(1.2345, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fmax(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fmax(aNaN, aNaN));
2727
}
2828

2929
TEST(FmaxTest, InfArg) {

libc/test/src/math/fmaxf_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FmaxfTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0f, __llvm_libc::fmaxf(-0.0f, aNaN));
2424
EXPECT_FP_EQ(-1.2345f, __llvm_libc::fmaxf(aNaN, -1.2345f));
2525
EXPECT_FP_EQ(1.2345f, __llvm_libc::fmaxf(1.2345f, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fmaxf(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fmaxf(aNaN, aNaN));
2727
}
2828

2929
TEST(FmaxfTest, InfArg) {

libc/test/src/math/fmaxl_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FmaxlTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0L, __llvm_libc::fmaxl(-0.0L, aNaN));
2424
EXPECT_FP_EQ(-1.2345L, __llvm_libc::fmaxl(aNaN, -1.2345L));
2525
EXPECT_FP_EQ(1.2345L, __llvm_libc::fmaxl(1.2345L, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fmaxl(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fmaxl(aNaN, aNaN));
2727
}
2828

2929
TEST(FmaxlTest, InfArg) {

libc/test/src/math/fmin_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FminTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0, __llvm_libc::fmin(-0.0, aNaN));
2424
EXPECT_FP_EQ(-1.2345, __llvm_libc::fmin(aNaN, -1.2345));
2525
EXPECT_FP_EQ(1.2345, __llvm_libc::fmin(1.2345, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fmin(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fmin(aNaN, aNaN));
2727
}
2828

2929
TEST(FminTest, InfArg) {

libc/test/src/math/fminf_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FminfTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0f, __llvm_libc::fminf(-0.0f, aNaN));
2424
EXPECT_FP_EQ(-1.2345f, __llvm_libc::fminf(aNaN, -1.2345f));
2525
EXPECT_FP_EQ(1.2345f, __llvm_libc::fminf(1.2345f, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fminf(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fminf(aNaN, aNaN));
2727
}
2828

2929
TEST(FminfTest, InfArg) {

libc/test/src/math/fminl_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(FminlTest, NaNArg) {
2323
EXPECT_FP_EQ(-0.0L, __llvm_libc::fminl(-0.0L, aNaN));
2424
EXPECT_FP_EQ(-1.2345L, __llvm_libc::fminl(aNaN, -1.2345L));
2525
EXPECT_FP_EQ(1.2345L, __llvm_libc::fminl(1.2345L, aNaN));
26-
EXPECT_NE(isnan(__llvm_libc::fminl(aNaN, aNaN)), 0);
26+
EXPECT_FP_EQ(aNaN, __llvm_libc::fminl(aNaN, aNaN));
2727
}
2828

2929
TEST(FminlTest, InfArg) {

0 commit comments

Comments
 (0)