Skip to content

Commit aa994f7

Browse files
committed
[libc][math][c23] Reduce MPFR to 0.5.
1 parent 0640c54 commit aa994f7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libc/src/math/generic/acoshf16.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
namespace LIBC_NAMESPACE_DECL {
2020

21-
static constexpr size_t N_EXCEPTS = 1;
21+
static constexpr size_t N_EXCEPTS = 2;
2222
static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ACOSHF16_EXCEPTS{
2323
{// (input, RZ output, RU offset, RD offset, RN offset)
24-
{0x41B7, 0x3ED8, 0, 1, 0}}};
24+
{0x41B7, 0x3ED8, 1, 0, 0},
25+
{0x3CE4, 0x393E, 1, 0, 1}}};
2526

2627
LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
2728
using FPBits = fputil::FPBits<float16>;
@@ -59,8 +60,11 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
5960
if (LIBC_UNLIKELY(x_u == 0x3c00U))
6061
return float16(0.0f);
6162

62-
float xf32 = x;
63+
if (auto r = ACOSHF16_EXCEPTS.lookup(xbits.uintval());
64+
LIBC_UNLIKELY(r.has_value()))
65+
return r.value();
6366

67+
float xf32 = x;
6468
// High precision for inputs very close to 1.0
6569
if (LIBC_UNLIKELY(xf32 < 1.25f)) {
6670
float delta = xf32 - 1.0f;
@@ -73,10 +77,6 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
7377
return fputil::cast<float16>(approx);
7478
}
7579

76-
if (auto r = ACOSHF16_EXCEPTS.lookup(xbits.uintval());
77-
LIBC_UNLIKELY(r.has_value()))
78-
return r.value();
79-
8080
// Standard computation for general case.
8181
float sqrt_term =
8282
fputil::sqrt<float>(fputil::multiply_add(xf32, xf32, -1.0f));

libc/test/src/math/acoshf16_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TEST_F(LlvmLibcAcoshf16Test, PositiveRange) {
4848
float16 x = FPBits(v).get_val();
4949

5050
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
51-
LIBC_NAMESPACE::acoshf16(x), 1.0);
51+
LIBC_NAMESPACE::acoshf16(x), 0.5);
5252
}
5353
}
5454

0 commit comments

Comments
 (0)