Skip to content

Commit 8a4e781

Browse files
committed
Migrate to fputil::cast
1 parent 6cbafd0 commit 8a4e781

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5335,6 +5335,7 @@ add_header_library(
53355335
expxf16.h
53365336
DEPENDS
53375337
libc.src.__support.CPP.array
5338+
libc.src.__support.FPUtil.cast
53385339
libc.src.__support.FPUtil.fp_bits
53395340
libc.src.__support.FPUtil.multiply_add
53405341
libc.src.__support.FPUtil.nearest_integer

libc/src/math/generic/expxf16.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/__support/CPP/array.h"
1313
#include "src/__support/FPUtil/FPBits.h"
1414
#include "src/__support/FPUtil/PolyEval.h"
15+
#include "src/__support/FPUtil/cast.h"
1516
#include "src/__support/FPUtil/multiply_add.h"
1617
#include "src/__support/FPUtil/nearest_integer.h"
1718
#include "src/__support/macros/attributes.h"
@@ -279,11 +280,11 @@ template <bool IsSinh> LIBC_INLINE float16 eval_sinh_or_cosh(float16 x) {
279280
// sinh(x) = lo * (0.5 * P_odd * (2^(hi + mid) + 2^(-(hi + mid)))) +
280281
// (0.5 * P_even * (2^(hi + mid) - 2^(-(hi + mid))))
281282
if constexpr (IsSinh)
282-
return static_cast<float16>(fputil::multiply_add(
283+
return fputil::cast<float16>(fputil::multiply_add(
283284
lo, half_p_odd * exp2_hi_mid_sum, half_p_even * exp2_hi_mid_diff));
284285
// cosh(x) = lo * (0.5 * P_odd * (2^(hi + mid) - 2^(-(hi + mid)))) +
285286
// (0.5 * P_even * (2^(hi + mid) + 2^(-(hi + mid))))
286-
return static_cast<float16>(fputil::multiply_add(
287+
return fputil::cast<float16>(fputil::multiply_add(
287288
lo, half_p_odd * exp2_hi_mid_diff, half_p_even * exp2_hi_mid_sum));
288289
}
289290

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,6 +3738,7 @@ add_fp_unittest(
37383738
libc.hdr.fenv_macros
37393739
libc.src.errno.errno
37403740
libc.src.math.coshf16
3741+
libc.src.__support.FPUtil.cast
37413742
)
37423743

37433744
add_fp_unittest(
@@ -3763,6 +3764,7 @@ add_fp_unittest(
37633764
libc.hdr.fenv_macros
37643765
libc.src.errno.errno
37653766
libc.src.math.sinhf16
3767+
libc.src.__support.FPUtil.cast
37663768
)
37673769

37683770
add_fp_unittest(

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

Lines changed: 5 additions & 4 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/coshf16.h"
1213
#include "test/UnitTest/FPMatcher.h"
@@ -29,11 +30,11 @@ TEST_F(LlvmLibcCoshf16Test, SpecialNumbers) {
2930
EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::coshf16(neg_inf));
3031
EXPECT_MATH_ERRNO(0);
3132

32-
EXPECT_FP_EQ_ALL_ROUNDING(static_cast<float16>(1.0),
33+
EXPECT_FP_EQ_ALL_ROUNDING(LIBC_NAMESPACE::fputil::cast<float16>(1.0),
3334
LIBC_NAMESPACE::coshf16(zero));
3435
EXPECT_MATH_ERRNO(0);
3536

36-
EXPECT_FP_EQ_ALL_ROUNDING(static_cast<float16>(1.0),
37+
EXPECT_FP_EQ_ALL_ROUNDING(LIBC_NAMESPACE::fputil::cast<float16>(1.0),
3738
LIBC_NAMESPACE::coshf16(neg_zero));
3839
EXPECT_MATH_ERRNO(0);
3940
}
@@ -50,7 +51,7 @@ TEST_F(LlvmLibcCoshf16Test, Overflow) {
5051
EXPECT_MATH_ERRNO(ERANGE);
5152

5253
// round(acosh(2^16), HP, RU);
53-
float16 x = static_cast<float16>(0x1.794p+3);
54+
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(0x1.794p+3);
5455

5556
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::coshf16(x),
5657
FE_OVERFLOW | FE_INEXACT);
@@ -69,7 +70,7 @@ TEST_F(LlvmLibcCoshf16Test, Overflow) {
6970
EXPECT_MATH_ERRNO(0);
7071

7172
// round(-acosh(2^16), HP, RD);
72-
x = static_cast<float16>(-0x1.794p+3);
73+
x = LIBC_NAMESPACE::fputil::cast<float16>(-0x1.794p+3);
7374

7475
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::coshf16(x),
7576
FE_OVERFLOW | FE_INEXACT);

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

Lines changed: 3 additions & 2 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/sinhf16.h"
1213
#include "test/UnitTest/FPMatcher.h"
@@ -48,7 +49,7 @@ TEST_F(LlvmLibcSinhf16Test, Overflow) {
4849
EXPECT_MATH_ERRNO(ERANGE);
4950

5051
// round(asinh(2^16), HP, RU);
51-
float16 x = static_cast<float16>(0x1.794p+3);
52+
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(0x1.794p+3);
5253

5354
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::sinhf16(x),
5455
FE_OVERFLOW | FE_INEXACT);
@@ -67,7 +68,7 @@ TEST_F(LlvmLibcSinhf16Test, Overflow) {
6768
EXPECT_MATH_ERRNO(0);
6869

6970
// round(asinh(-2^16), HP, RD);
70-
x = static_cast<float16>(-0x1.794p+3);
71+
x = LIBC_NAMESPACE::fputil::cast<float16>(-0x1.794p+3);
7172

7273
EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(
7374
neg_inf, LIBC_NAMESPACE::sinhf16(x), FE_OVERFLOW | FE_INEXACT);

0 commit comments

Comments
 (0)