Skip to content

Commit b66aa3b

Browse files
authored
[libc][math][c23] Refactor expf16 (#101373)
Also updates and sorts CMake target dependencies, and corrects the smoke test that expected expf16(sNaN) to return sNaN instead of aNaN, although the test still passed, as FPMatcher only checks whether both sides are NaN, not whether they're the same NaN value.
1 parent 9a10132 commit b66aa3b

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

libc/src/math/generic/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,12 @@ add_entrypoint_object(
12361236
libc.hdr.errno_macros
12371237
libc.hdr.fenv_macros
12381238
libc.src.__support.CPP.array
1239+
libc.src.__support.FPUtil.except_value_utils
12391240
libc.src.__support.FPUtil.fenv_impl
12401241
libc.src.__support.FPUtil.fp_bits
1241-
libc.src.__support.FPUtil.polyeval
12421242
libc.src.__support.FPUtil.multiply_add
12431243
libc.src.__support.FPUtil.nearest_integer
1244+
libc.src.__support.FPUtil.polyeval
12441245
libc.src.__support.FPUtil.rounding_mode
12451246
libc.src.__support.macros.optimization
12461247
COMPILE_OPTIONS

libc/src/math/generic/expf16.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ LLVM_LIBC_FUNCTION(float16, expf16, (float16 x)) {
127127
// > display = hexadecimal;
128128
// > P = fpminimax(expm1(x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
129129
// > 1 + x * P;
130-
float r =
131-
fputil::polyeval(xf, 0x1p+0f, 0x1p+0f, 0x1.0004p-1f, 0x1.555778p-3f);
132-
return static_cast<float16>(r);
130+
return static_cast<float16>(
131+
fputil::polyeval(xf, 0x1p+0f, 0x1p+0f, 0x1.0004p-1f, 0x1.555778p-3f));
133132
}
134133
}
135134

@@ -150,7 +149,7 @@ LLVM_LIBC_FUNCTION(float16, expf16, (float16 x)) {
150149
// respectively. exp(lo) is computed using a degree-3 minimax polynomial
151150
// generated by Sollya.
152151

153-
float xf = static_cast<float>(x);
152+
float xf = x;
154153
float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
155154
int x_hi_mid = static_cast<int>(kf);
156155
int x_hi = x_hi_mid >> 3;

libc/test/src/math/performance_testing/expf16_perf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Performancel test for expf16 --------------------------------------===//
1+
//===-- Performance test for expf16 ---------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TEST_F(LlvmLibcExpf16Test, SpecialNumbers) {
2121
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::expf16(aNaN));
2222
EXPECT_MATH_ERRNO(0);
2323

24-
EXPECT_FP_EQ_WITH_EXCEPTION(sNaN, LIBC_NAMESPACE::expf16(sNaN), FE_INVALID);
24+
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::expf16(sNaN), FE_INVALID);
2525
EXPECT_MATH_ERRNO(0);
2626

2727
EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::expf16(inf));

0 commit comments

Comments
 (0)