Skip to content

Commit 6ed131e

Browse files
committed
Address comments.
1 parent 12c7b02 commit 6ed131e

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

libc/src/math/generic/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,12 +4097,16 @@ add_entrypoint_object(
40974097
HDRS
40984098
../asin.h
40994099
DEPENDS
4100+
libc.src.__support.FPUtil.fp_bits
4101+
libc.src.__support.FPUtil.double_double
4102+
libc.src.__support.FPUtil.dyadic_float
4103+
libc.src.__support.FPUtil.fenv_impl
41004104
libc.src.__support.FPUtil.fp_bits
41014105
libc.src.__support.FPUtil.multiply_add
4102-
libc.src.__support.FPUtil.polyeval
4106+
libc.src.__support.FPUtil.poly_eval
41034107
libc.src.__support.FPUtil.sqrt
41044108
libc.src.__support.macros.optimization
4105-
.inv_trigf_utils
4109+
libc.src.__support.macros.properties.cpu_features
41064110
)
41074111

41084112
add_entrypoint_object(

libc/src/math/generic/asin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using DoubleDouble = fputil::DoubleDouble;
2525
using Float128 = fputil::DyadicFloat<128>;
2626

2727
LLVM_LIBC_FUNCTION(double, asin, (double x)) {
28-
using FPBits = typename fputil::FPBits<double>;
28+
using FPBits = fputil::FPBits<double>;
2929

3030
FPBits xbits(x);
3131
int x_exp = xbits.get_biased_exponent();
@@ -138,6 +138,8 @@ LLVM_LIBC_FUNCTION(double, asin, (double x)) {
138138
if (xbits.is_finite()) {
139139
fputil::set_errno_if_required(EDOM);
140140
fputil::raise_except_if_required(FE_INVALID);
141+
} else if (xbits.is_signaling_nan()) {
142+
fputil::raise_except_if_required(FE_INVALID);
141143
}
142144
return FPBits::quiet_nan().get_val();
143145
}
@@ -201,7 +203,7 @@ LLVM_LIBC_FUNCTION(double, asin, (double x)) {
201203
// Polynomial approximation:
202204
// p ~ asin(sqrt(u))/sqrt(u)
203205
unsigned idx;
204-
[[maybe_unused]] double err = vh * 0x1.0p-51;
206+
double err = vh * 0x1.0p-51;
205207

206208
DoubleDouble p = asin_eval(DoubleDouble{0.0, u}, idx, err);
207209

libc/src/math/generic/asin_utils.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,28 +205,24 @@ LIBC_INLINE DoubleDouble asin_eval(const DoubleDouble &u, unsigned &idx,
205205
// };
206206
// > verbosity = 0;
207207
// > procedure ASIN_APPROX(N, Deg) {
208-
// abs_error = 0;
209-
// rel_error = 0;
210-
// for
211-
// i from 1 to N / 4 do {
212-
// Q = fpminimax(asin(sqrt(i / N + x)) / sqrt(i / N + x), Deg,
213-
// [| 128... | ], [ -1 / (2 * N), 1 / (2 * N) ]);
214-
// abs_err = dirtyinfnorm(asin(sqrt(i / N + x)) - sqrt(i / N + x) * Q,
215-
// [ -1 / (2 * N), 1 / (2 * N) ]);
216-
// rel_err = dirtyinfnorm(asin(sqrt(i / N + x)) / sqrt(i / N + x) - Q,
217-
// [ -1 / (2 * N), 1 / (2 * N) ]);
218-
// if (abs_err > abs_error)
219-
// then abs_error = abs_err;
220-
// if (rel_err > rel_error)
221-
// then rel_error = rel_err;
222-
// write("{");
223-
// for
224-
// j from 0 to Deg do PRINTF128(coeff(Q, j));
208+
// abs_error = 0;
209+
// rel_error = 0;
210+
// for i from 1 to N / 4 do {
211+
// Q = fpminimax(asin(sqrt(i / N + x)) / sqrt(i / N + x), Deg,
212+
// [| 128... | ], [ -1 / (2 * N), 1 / (2 * N) ]);
213+
// abs_err = dirtyinfnorm(asin(sqrt(i / N + x)) - sqrt(i / N + x) * Q,
214+
// [ -1 / (2 * N), 1 / (2 * N) ]);
215+
// rel_err = dirtyinfnorm(asin(sqrt(i / N + x)) / sqrt(i / N + x) - Q,
216+
// [ -1 / (2 * N), 1 / (2 * N) ]);
217+
// if (abs_err > abs_error) then abs_error = abs_err;
218+
// if (rel_err > rel_error) then rel_error = rel_err;
219+
// write("{");
220+
// for j from 0 to Deg do PRINTF128(coeff(Q, j));
225221
// print("},");
226-
// };
222+
// };
227223
// print("Absolute Errors:", abs_error);
228224
// print("Relative Errors:", rel_error);
229-
// };
225+
// };
230226
// > ASIN_APPROX(64, 15);
231227
// ...
232228
// Absolute Errors: 0x1.0b3...p-129

libc/test/src/math/asin_test.cpp

Lines changed: 3 additions & 4 deletions
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/asin.h"
1110
#include "test/UnitTest/FPMatcher.h"
1211
#include "test/UnitTest/Test.h"
@@ -20,8 +19,8 @@ using LIBC_NAMESPACE::testing::tlog;
2019

2120
TEST_F(LlvmLibcAsinTest, InDoubleRange) {
2221
constexpr uint64_t COUNT = 123'451;
23-
uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p-60).uintval();
24-
uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(1.0).uintval();
22+
uint64_t START = FPBits(0x1.0p-60).uintval();
23+
uint64_t STOP = FPBits(1.0).uintval();
2524
uint64_t STEP = (STOP - START) / COUNT;
2625

2726
auto test = [&](mpfr::RoundingMode rounding_mode) {
@@ -32,7 +31,7 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) {
3231
uint64_t fails = 0;
3332
uint64_t count = 0;
3433
uint64_t cc = 0;
35-
double mx, mr = 0.0;
34+
double mx = 0.0, mr = 0.0;
3635
double tol = 0.5;
3736

3837
for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,7 +4014,6 @@ add_fp_unittest(
40144014
asin_test.cpp
40154015
DEPENDS
40164016
libc.src.math.asin
4017-
libc.src.__support.FPUtil.fp_bits
40184017
)
40194018

40204019
add_fp_unittest(

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

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

9-
#include "hdr/math_macros.h"
9+
#include "hdr/fenv_macros.h"
1010
#include "src/math/asin.h"
1111
#include "test/UnitTest/FPMatcher.h"
1212
#include "test/UnitTest/Test.h"
1313

1414
using LlvmLibcAsinTest = LIBC_NAMESPACE::testing::FPTest<double>;
1515

1616
TEST_F(LlvmLibcAsinTest, SpecialNumbers) {
17+
EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asin(sNaN),
18+
FE_INVALID);
19+
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asin(aNaN));
1720
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asin(aNaN));
1821
EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::asin(zero));
1922
EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::asin(neg_zero));

0 commit comments

Comments
 (0)