Skip to content

Commit c47a573

Browse files
authored
[libc] Fix conversion warnings for float16 tests. (#124830)
Fixes #124801.
1 parent 9f66062 commit c47a573

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_fp_unittest(
4545
DEPENDS
4646
libc.src.errno.errno
4747
libc.src.math.cospif16
48+
libc.src.__support.FPUtil.cast
4849
)
4950

5051
add_fp_unittest(
@@ -69,6 +70,7 @@ add_fp_unittest(
6970
DEPENDS
7071
libc.src.errno.errno
7172
libc.src.math.sinf16
73+
libc.src.__support.FPUtil.cast
7274
)
7375

7476
add_fp_unittest(
@@ -1251,6 +1253,7 @@ add_fp_unittest(
12511253
libc.hdr.fenv_macros
12521254
libc.src.errno.errno
12531255
libc.src.math.exp2m1f16
1256+
libc.src.__support.FPUtil.cast
12541257
)
12551258

12561259
add_fp_unittest(

libc/test/src/math/smoke/cospif16_test.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/FPUtil/cast.h"
910
#include "src/errno/libc_errno.h"
1011
#include "src/math/cospif16.h"
1112
#include "test/UnitTest/FPMatcher.h"
@@ -19,10 +20,10 @@ TEST_F(LlvmLibcCospif16Test, SpecialNumbers) {
1920
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(aNaN));
2021
EXPECT_MATH_ERRNO(0);
2122

22-
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(zero));
23+
EXPECT_FP_EQ(FPBits::one().get_val(), LIBC_NAMESPACE::cospif16(zero));
2324
EXPECT_MATH_ERRNO(0);
2425

25-
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(neg_zero));
26+
EXPECT_FP_EQ(FPBits::one().get_val(), LIBC_NAMESPACE::cospif16(neg_zero));
2627
EXPECT_MATH_ERRNO(0);
2728

2829
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(inf));
@@ -33,12 +34,24 @@ TEST_F(LlvmLibcCospif16Test, SpecialNumbers) {
3334
}
3435

3536
TEST_F(LlvmLibcCospif16Test, Integers) {
36-
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(-0x420));
37-
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(-0x1.4p+14));
38-
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::cospif16(0x421));
39-
EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::cospif16(0x333));
40-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(-0x1.28p4));
41-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(-0x1.ffcp9));
42-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(0x1.01p7));
43-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(0x1.f6cp9));
37+
EXPECT_FP_EQ(FPBits::one().get_val(),
38+
LIBC_NAMESPACE::cospif16(
39+
LIBC_NAMESPACE::fputil::cast<float16>(-0x420.0p0)));
40+
EXPECT_FP_EQ(FPBits::one().get_val(),
41+
LIBC_NAMESPACE::cospif16(
42+
LIBC_NAMESPACE::fputil::cast<float16>(-0x1.4p+14)));
43+
EXPECT_FP_EQ(FPBits::one(Sign::NEG).get_val(),
44+
LIBC_NAMESPACE::cospif16(
45+
LIBC_NAMESPACE::fputil::cast<float16>(0x421.0p0)));
46+
EXPECT_FP_EQ(FPBits::one(Sign::NEG).get_val(),
47+
LIBC_NAMESPACE::cospif16(
48+
LIBC_NAMESPACE::fputil::cast<float16>(0x333.0p0)));
49+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
50+
LIBC_NAMESPACE::fputil::cast<float16>(-0x1.28p4)));
51+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
52+
LIBC_NAMESPACE::fputil::cast<float16>(-0x1.ffcp9)));
53+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
54+
LIBC_NAMESPACE::fputil::cast<float16>(0x1.01p7)));
55+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
56+
LIBC_NAMESPACE::fputil::cast<float16>(0x1.f6cp9)));
4457
}

libc/test/src/math/smoke/exp2m1f16_test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "hdr/fenv_macros.h"
10+
#include "src/__support/FPUtil/cast.h"
1011
#include "src/errno/libc_errno.h"
1112
#include "src/math/exp2m1f16.h"
1213
#include "test/UnitTest/FPMatcher.h"
@@ -44,7 +45,7 @@ TEST_F(LlvmLibcExp2m1f16Test, Overflow) {
4445
FE_OVERFLOW | FE_INEXACT);
4546
EXPECT_MATH_ERRNO(ERANGE);
4647

47-
float16 x = 16.0;
48+
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(16.0);
4849

4950
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(
5051
inf, LIBC_NAMESPACE::exp2m1f16(x), FE_OVERFLOW | FE_INEXACT);
@@ -69,9 +70,11 @@ TEST_F(LlvmLibcExp2m1f16Test, ResultNearNegOne) {
6970
EXPECT_FP_EQ_WITH_EXCEPTION(-1.0, LIBC_NAMESPACE::exp2m1f16(neg_max_normal),
7071
FE_INEXACT);
7172

72-
EXPECT_FP_EQ_ALL_ROUNDING(-0x1.ffcp-1, LIBC_NAMESPACE::exp2m1f16(-11.0));
73+
EXPECT_FP_EQ_ALL_ROUNDING(
74+
-0x1.ffcp-1,
75+
LIBC_NAMESPACE::exp2m1f16(LIBC_NAMESPACE::fputil::cast<float16>(-11.0)));
7376

74-
float16 x = -12.0;
77+
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(-12.0);
7578

7679
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(
7780
-1.0, LIBC_NAMESPACE::exp2m1f16(x), FE_INEXACT);

libc/test/src/math/smoke/sinpif16_test.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/FPUtil/cast.h"
910
#include "src/errno/libc_errno.h"
1011
#include "src/math/sinpif16.h"
1112
#include "test/UnitTest/FPMatcher.h"
@@ -33,10 +34,18 @@ TEST_F(LlvmLibcSinpif16Test, SpecialNumbers) {
3334
}
3435

3536
TEST_F(LlvmLibcSinpif16Test, Integers) {
36-
EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::sinpif16(-0x420));
37-
EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::sinpif16(-0x1p+10));
38-
EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::sinpif16(-0x1.4p+14));
39-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(0x420));
40-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(0x1.cp+15));
41-
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(0x1.cp+7));
37+
EXPECT_FP_EQ(neg_zero,
38+
LIBC_NAMESPACE::sinpif16(
39+
LIBC_NAMESPACE::fputil::cast<float16>(-0x420.0p0)));
40+
EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::sinpif16(
41+
LIBC_NAMESPACE::fputil::cast<float16>(-0x1p+10)));
42+
EXPECT_FP_EQ(neg_zero,
43+
LIBC_NAMESPACE::sinpif16(
44+
LIBC_NAMESPACE::fputil::cast<float16>(-0x1.4p+14)));
45+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(
46+
LIBC_NAMESPACE::fputil::cast<float16>(0x420.0p0)));
47+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(
48+
LIBC_NAMESPACE::fputil::cast<float16>(0x1.cp+15)));
49+
EXPECT_FP_EQ(zero, LIBC_NAMESPACE::sinpif16(
50+
LIBC_NAMESPACE::fputil::cast<float16>(0x1.cp+7)));
4251
}

0 commit comments

Comments
 (0)