Skip to content

Commit a4061e1

Browse files
committed
[libc] Update COEFF.
1 parent 735a667 commit a4061e1

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

libc/src/math/generic/atanhf16.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222

2323
namespace LIBC_NAMESPACE_DECL {
2424

25-
static constexpr size_t N_EXCEPTS = 4;
25+
static constexpr size_t N_EXCEPTS = 1;
2626
static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ATANHF16_EXCEPTS{{
2727
// (input, RZ output, RU offset, RD offset, RN offset)
2828
// x = 0x1.a5cp-4, atanhf16(x) = 0x1.a74p-4 (RZ)
2929
{0x2E97, 0x2E9D, 1, 0, 0},
30-
// x = -0x1.a5cp-4, atanhf16(x) = -0x1.a74p-4 (RZ)
31-
{0xAE97, 0xAE9D, 0, 1, 0},
32-
// x = -0x1.99cp-4, atanhf16(x) = -0x1.9bp-4 (RZ)
33-
{0xAE67, 0xAE6C, 0, 1, 1},
34-
// x = -0x1.b8cp-3, atanhf16(x) = -0x1.bfcp-3 (RZ)
35-
{0xB2E3, 0xB2FF, 0, 1, 0},
3630
}};
3731

3832
LLVM_LIBC_FUNCTION(float16, atanhf16, (float16 x)) {
@@ -76,9 +70,9 @@ LLVM_LIBC_FUNCTION(float16, atanhf16, (float16 x)) {
7670
// The Taylor expansion of atanh(x) is:
7771
// atanh(x) = x + x^3/3 + x^5/5 + x^7/7 + x^9/9 + x^11/11
7872
// = x * [1 + x^2/3 + x^4/5 + x^6/7 + x^8/9 + x^10/11]
79-
// When |x| < 2^-16, this can be approximated by:
73+
// When |x| < 2^-6 (0x2400U), this can be approximated by:
8074
// atanh(x) ≈ x + (1/3)*x^3
81-
if (LIBC_UNLIKELY(x_abs < 0x0100U)) {
75+
if (LIBC_UNLIKELY(x_abs < 0x2400U)) {
8276
float xf = x;
8377
return fputil::cast<float16>(xf + 0x1.555556p-2f * xf * xf * xf);
8478
}

libc/src/math/generic/explogxf.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,13 @@ LIBC_INLINE static float log_eval_f(float x) {
314314
// dx = (mx - p1*2^(-7)) / (1 + p1*2^(-7)).
315315
float dx = (xbits.get_val() - 1.0f) * ONE_OVER_F_FLOAT[p1];
316316

317-
// Minimax polynomial of log(1 + dx) generated by Sollya with:
318-
// > P = fpminimax(log(1 + x)/x, 6, [|D...|], [0, 2^-7]);
319-
const float COEFFS[6] = {-0x1.fffffep-2f, 0x1.555556p-2f, -0x1.fffefep-3f,
320-
0x1.99999ap-3f, -0x1.554318p-3f, 0x1.1dc5c4p-3f};
317+
// Minimax polynomial for log(1 + dx), generated using Sollya:
318+
// > P = fpminimax(log(1 + x)/x, 6, [|SG...|], [0, 2^-7]);
319+
// > Q = (P - 1) / x;
320+
// > for i from 0 to degree(Q) do print(coeff(Q, i));
321+
static constexpr float COEFFS[6] = {-0x1p-1f, 0x1.555556p-2f,
322+
-0x1.00022ep-2f, 0x1.9ea056p-3f,
323+
-0x1.e50324p-2f, 0x1.c018fp3f};
321324

322325
float dx2 = dx * dx;
323326

@@ -330,7 +333,7 @@ LIBC_INLINE static float log_eval_f(float x) {
330333
// Generated by Sollya with the following commands:
331334
// > display = hexadecimal;
332335
// > round(log(2), SG, RN);
333-
static constexpr float LOGF_2 = 0x1.62e43p-1f;
336+
constexpr float LOGF_2 = 0x1.62e43p-1f;
334337

335338
float result = fputil::multiply_add(ex, LOGF_2, LOG_F_FLOAT[p1] + p);
336339
return result;

0 commit comments

Comments
 (0)