Skip to content

Commit c092cad

Browse files
committed
[libc][math] Update for comments.
1 parent 2a2c9ff commit c092cad

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4040,6 +4040,7 @@ add_entrypoint_object(
40404040
libc.hdr.errno_macros
40414041
libc.hdr.fenv_macros
40424042
libc.src.__support.FPUtil.cast
4043+
libc.src.__support.FPUtil.except_value_utils
40434044
libc.src.__support.FPUtil.fenv_impl
40444045
libc.src.__support.FPUtil.fp_bits
40454046
libc.src.__support.FPUtil.multiply_add

libc/src/math/generic/atanhf16.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,20 @@ LLVM_LIBC_FUNCTION(float16, atanhf16, (float16 x)) {
6161

6262
// For |x| less than approximately 0.10
6363
if (LIBC_UNLIKELY(x_abs <= 0x2e66U)) {
64+
// atanh(+/-0) = +/-0
65+
if (LIBC_UNLIKELY(x_abs == 0U))
66+
return x;
6467
// The Taylor expansion of atanh(x) is:
6568
// atanh(x) = x + x^3/3 + x^5/5 + x^7/7 + x^9/9 + x^11/11
6669
// = x * [1 + x^2/3 + x^4/5 + x^6/7 + x^8/9 + x^10/11]
67-
// When |x| < 0x0100U, this can be approximated by:
70+
// When |x| < 2^-16, this can be approximated by:
6871
// atanh(x) ≈ x + (1/3)*x^3
6972
if (LIBC_UNLIKELY(x_abs < 0x0100U)) {
70-
return static_cast<float16>(
71-
LIBC_UNLIKELY(x_abs == 0) ? x : (x + 0x1.555556p-2f * x * x * x));
73+
float xf = x;
74+
return fputil::cast<float16>(xf + 0x1.555556p-2f * xf * xf * xf);
7275
}
7376

74-
// For 0x0100U <= |x| <= 0x2e66U:
77+
// For 2^-16 <= |x| <= 0x1.998p-4 (~0.10):
7578
// Let t = x^2.
7679
// Define P(t) ≈ (1/3)*t + (1/5)*t^2 + (1/7)*t^3 + (1/9)*t^4 + (1/11)*t^5.
7780
// Coefficients (from Sollya, RN, hexadecimal):
@@ -86,7 +89,7 @@ LLVM_LIBC_FUNCTION(float16, atanhf16, (float16 x)) {
8689
}
8790

8891
float xf = x;
89-
return fputil::cast<float16>(0.5f * log_eval((xf + 1.0f) / (xf - 1.0f)));
92+
return fputil::cast<float16>(0.5 * log_eval((xf + 1.0f) / (xf - 1.0f)));
9093
}
9194

9295
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/atanhf16_test.cpp

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

9-
#include "src/__support/FPUtil/FPBits.h"
109
#include "src/math/atanhf16.h"
1110
#include "test/UnitTest/FPMatcher.h"
1211
#include "test/UnitTest/Test.h"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,7 @@ add_fp_unittest(
39563956
DEPENDS
39573957
libc.src.errno.errno
39583958
libc.src.math.atanhf16
3959-
libc.src.__support.FPUtil.fp_bits
3959+
libc.src.__support.FPUtil.cast
39603960
)
39613961

39623962
add_fp_unittest(

0 commit comments

Comments
 (0)