Skip to content

Commit d8fa4dd

Browse files
committed
clang-format
1 parent 9c6454f commit d8fa4dd

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

libc/src/math/generic/asinf16.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include "hdr/fenv_macros.h"
1212
#include "src/__support/FPUtil/FEnvImpl.h"
1313
#include "src/__support/FPUtil/FPBits.h"
14+
#include "src/__support/FPUtil/PolyEval.h"
1415
#include "src/__support/FPUtil/cast.h"
1516
#include "src/__support/FPUtil/multiply_add.h"
16-
#include "src/__support/FPUtil/PolyEval.h"
1717
#include "src/__support/FPUtil/sqrt.h"
1818
#include "src/__support/macros/optimization.h"
1919

@@ -32,17 +32,18 @@ LLVM_LIBC_FUNCTION(float16, asinf16, (float16 x)) {
3232
float xf = x;
3333

3434
float xsq = xf * xf;
35-
35+
3636
// |x| <= 0x1p-1, |x| <= 0.5
37-
if (x_abs <= 0x3800) {
37+
if (x_abs <= 0x3800) {
3838
if (LIBC_UNLIKELY(x_abs <= 0x1a1e)) {
3939
// asinf16(+/-0) = +/-0
4040
if (LIBC_UNLIKELY(x_abs == 0U)) {
4141
return x;
4242
}
43-
43+
4444
// Exhaustive tests show that, when:
45-
// x > 0, and rounding upward, then,
45+
// x > 0, and rounding upward, or
46+
// x < 0, and rounding downward, then,
4647
// asin(x) = x * 2^-11 + x
4748
// else, in other rounding modes,
4849
// asin(x) = x
@@ -57,10 +58,12 @@ LLVM_LIBC_FUNCTION(float16, asinf16, (float16 x)) {
5758

5859
// Degree-6 minimax odd polynomial of asin(x) generated by Sollya with:
5960
// > P = fpminimax(asin(x)/x, [|0, 2, 4, 6, 8|], [|SG...|], [0, 0.5]);
60-
float result = fputil::polyeval(xsq, 0x1.000002p0f, 0x1.554c2ap-3f, 0x1.3541ccp-4f, 0x1.43b2d6p-5f, 0x1.a0d73ep-5f);
61+
float result =
62+
fputil::polyeval(xsq, 0x1.000002p0f, 0x1.554c2ap-3f, 0x1.3541ccp-4f,
63+
0x1.43b2d6p-5f, 0x1.a0d73ep-5f);
6164
return fputil::cast<float16>(xf * result);
6265
}
63-
66+
6467
// |x| > 1, asinf16(x) = NaN
6568
if (LIBC_UNLIKELY(x_abs > 0x3c00)) {
6669
// |x| <= +/-inf
@@ -72,7 +75,7 @@ LLVM_LIBC_FUNCTION(float16, asinf16, (float16 x)) {
7275
return FPBits::quiet_nan().get_val();
7376
}
7477

75-
// When |x| > 0.5, assume that 0.5 < |x| <= 1,
78+
// When |x| > 0.5, assume that 0.5 < |x| <= 1,
7679
//
7780
// Step-by-step range-reduction proof:
7881
// 1: Let y = asin(x), such that, x = sin(y)
@@ -95,26 +98,29 @@ LLVM_LIBC_FUNCTION(float16, asinf16, (float16 x)) {
9598
// y = pi/2 - 2 * arcsin(sqrt(u))
9699
// 10: Recall [1], y = asin(x). Therefore:
97100
// arcsin(x) = pi/2 - 2 * arcsin(sqrt(u))
98-
//
101+
//
99102
// WHY?
100103
// 11: Recall [7], u = (1 - x)/2
101104
// 12: Since 0.5 < x <= 1, therefore:
102105
// 0 <= u <= 0.25 and 0 <= sqrt(u) <= 0.5
103-
//
104-
// Hence, we can reuse the same [0, 0.5] domain polynomial approximation for Step [10]
105-
// as `sqrt(u)` is in range.
106-
106+
//
107+
// Hence, we can reuse the same [0, 0.5] domain polynomial approximation for
108+
// Step [10] as `sqrt(u)` is in range.
109+
107110
// 0x1p-1 < |x| <= 0x1p0, 0.5 < |x| <= 1.0
108111
float xf_abs = (xf < 0 ? -xf : xf);
109112
float sign = ((xbits.uintval() >> 15) == 1 ? -1.0 : 1.0);
110113
float u = fputil::multiply_add(-0.5f, xf_abs, 0.5f);
111114
float u_sqrt = fputil::sqrt<float>(u);
112-
115+
113116
// Degree-6 minimax odd polynomial of asin(x) generated by Sollya with:
114117
// > P = fpminimax(asin(x)/x, [|0, 2, 4, 6, 8|], [|SG...|], [0, 0.5]);
115-
float asin_sqrt_u = u_sqrt * fputil::polyeval(u, 0x1.000002p0f, 0x1.554c2ap-3f, 0x1.3541ccp-4f, 0x1.43b2d6p-5f, 0x1.a0d73ep-5f);
116-
117-
return fputil::cast<float16>(sign * fputil::multiply_add(-2.0f, asin_sqrt_u, PI_2));
118-
}
118+
float asin_sqrt_u =
119+
u_sqrt * fputil::polyeval(u, 0x1.000002p0f, 0x1.554c2ap-3f,
120+
0x1.3541ccp-4f, 0x1.43b2d6p-5f, 0x1.a0d73ep-5f);
119121

122+
return fputil::cast<float16>(sign *
123+
fputil::multiply_add(-2.0f, asin_sqrt_u, PI_2));
120124
}
125+
126+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/asinf16_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ TEST_F(LlvmLibcAsinf16Test, PositiveRange) {
2727
for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
2828
float16 x = FPBits(v).get_val();
2929

30-
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x, LIBC_NAMESPACE::asinf16(x), 0.5);
30+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
31+
LIBC_NAMESPACE::asinf16(x), 0.5);
3132
}
3233
}
3334

3435
TEST_F(LlvmLibcAsinf16Test, NegativeRange) {
3536
for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
3637
float16 x = FPBits(v).get_val();
3738

38-
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x, LIBC_NAMESPACE::asinf16(x), 0.5);
39+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
40+
LIBC_NAMESPACE::asinf16(x), 0.5);
3941
}
4042
}

0 commit comments

Comments
 (0)