Skip to content

Commit 2c14051

Browse files
committed
[libc][math][c23] Do some change for comments.
1 parent 7711a3b commit 2c14051

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

libc/docs/headers/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Higher Math Functions
251251
+===========+==================+=================+========================+======================+========================+========================+============================+
252252
| acos | |check| | | | |check| | | 7.12.4.1 | F.10.1.1 |
253253
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
254-
| acosh | |check| | | | |check| | | 7.12.5.1 | F.10.2.1 |
254+
| acosh | |check| | | | |check| | | 7.12.5.1 | F.10.2.1 |
255255
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
256256
| acospi | | | | | | 7.12.4.8 | F.10.1.8 |
257257
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/src/math/acoshf16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Implementation header for acoshf16 -----------------------*- C++ -*-===//
1+
//===-- Implementation header for acoshf16 ----------------------*- C++ -*-===//
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/src/math/generic/acoshf16.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Half-precision acoshf16 function -----------------------------------===//
1+
//===-- Half-precision acoshf16 function ----------------------------------===//
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.
@@ -38,7 +38,7 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
3838
// Check for NaN input first.
3939
if (LIBC_UNLIKELY(xbits.is_nan())) {
4040
if (xbits.is_signaling_nan()) {
41-
fputil::raise_except(FE_INVALID);
41+
fputil::raise_except_if_required(FE_INVALID);
4242
return FPBits::quiet_nan().get_val();
4343
}
4444
return x;
@@ -48,7 +48,7 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
4848
if (LIBC_UNLIKELY(xbits.is_inf())) {
4949
if (xbits.is_neg()) {
5050
fputil::set_errno_if_required(EDOM);
51-
fputil::raise_except(FE_INVALID);
51+
fputil::raise_except_if_required(FE_INVALID);
5252
return FPBits::quiet_nan().get_val();
5353
}
5454
return x;
@@ -57,36 +57,36 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
5757
// Domain error for inputs less than 1.0.
5858
if (LIBC_UNLIKELY(x_abs < 0x3c00)) {
5959
fputil::set_errno_if_required(EDOM);
60-
fputil::raise_except(FE_INVALID);
60+
fputil::raise_except_if_required(FE_INVALID);
6161
return FPBits::quiet_nan().get_val();
6262
}
6363

6464
// acosh(1.0) exactly equals 0.0
65-
if (LIBC_UNLIKELY(xbits.uintval() == 0x3c00U))
65+
if (LIBC_UNLIKELY(x_u == 0x3c00U))
6666
return float16(0.0f);
6767

6868
float xf32 = static_cast<float>(x);
6969

7070
// High precision for inputs very close to 1.0
71-
if (LIBC_UNLIKELY(xf32 < 1.25f)) {
72-
float delta = xf32 - 1.0f;
73-
float sqrt_2 = fputil::sqrt<float>(2.0f * delta);
74-
float sqrt_2d = fputil::sqrt<float>(2.0f * delta);
75-
float d32 = delta * fputil::sqrt<float>(delta);
76-
float term2 = d32 / (6.0f * fputil::sqrt<float>(2.0f));
77-
float d52 = d32 * delta;
78-
float term3 = 3.0f * d52 / (80.0f * sqrt_2);
79-
float d72 = d52 * delta;
80-
float term4 = 5.0f * d72 / (1792.0f * sqrt_2);
81-
float result = sqrt_2d - term2 + term3 - term4;
82-
return fputil::cast<float16>(result);
83-
}
71+
// if (LIBC_UNLIKELY(xf32 < 1.25f)) {
72+
// float delta = xf32 - 1.0f;
73+
// float sqrt_2 = fputil::sqrt<float>(2.0f * delta);
74+
// float sqrt_2d = fputil::sqrt<float>(2.0f * delta);
75+
// float d32 = delta * fputil::sqrt<float>(delta);
76+
// float term2 = d32 / (6.0f * fputil::sqrt<float>(2.0f));
77+
// float d52 = d32 * delta;
78+
// float term3 = 3.0f * d52 / (80.0f * sqrt_2);
79+
// float d72 = d52 * delta;
80+
// float term4 = 5.0f * d72 / (1792.0f * sqrt_2);
81+
// float result = sqrt_2d - term2 + term3 - term4;
82+
// return fputil::cast<float16>(result);
83+
// }
8484

8585
// Special optimization for large input values.
86-
if (LIBC_UNLIKELY(xf32 >= 32.0f)) {
87-
float result = static_cast<float>(log_eval(2.0f * xf32));
88-
return fputil::cast<float16>(result);
89-
}
86+
// if (LIBC_UNLIKELY(xf32 >= 32.0f)) {
87+
// float result = static_cast<float>(log_eval(2.0f * xf32));
88+
// return fputil::cast<float16>(result);
89+
// }
9090

9191
// Standard computation for general case.
9292
float sqrt_term = fputil::sqrt<float>(fputil::multiply_add(xf32, xf32, -1.0f));
@@ -95,4 +95,4 @@ LLVM_LIBC_FUNCTION(float16, acoshf16, (float16 x)) {
9595
return fputil::cast<float16>(result);
9696
}
9797

98-
} // namespace LIBC_NAMESPACE_DECL
98+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/acoshf16_test.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
using LlvmLibcAcoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

20+
static constexpr uint16_t START = 0x3c00U;
21+
static constexpr uint16_t STOP = 0x7bffU;
22+
2023
TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) {
2124
LIBC_NAMESPACE::libc_errno = 0;
2225

@@ -40,21 +43,12 @@ TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) {
4043
EXPECT_MATH_ERRNO(EDOM);
4144
}
4245

43-
TEST_F(LlvmLibcAcoshf16Test, InFloat16Range) {
44-
constexpr uint32_t COUNT = 100'000;
45-
constexpr uint32_t STEP = UINT32_MAX / COUNT;
46-
47-
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
48-
LIBC_NAMESPACE::fputil::FPBits<float> bits(v);
49-
float xf32 = bits.get_val();
50-
if (bits.is_nan() || bits.is_inf())
51-
continue;
52-
if (xf32 < 1.0f)
53-
continue;
54-
float16 xh = LIBC_NAMESPACE::fputil::cast<float16>(xf32);
46+
TEST_F(LlvmLibcAcoshf16Test, PositiveRange) {
47+
for (uint16_t v = START; v <= STOP; ++v) {
48+
float16 x = FPBits(v).get_val();
5549

56-
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, xh,
57-
LIBC_NAMESPACE::acoshf16(xh), 3.0);
50+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
51+
LIBC_NAMESPACE::acoshf16(x), 3.0);
5852
}
5953
}
6054

0 commit comments

Comments
 (0)