Skip to content

Commit 5ce276f

Browse files
committed
fixed comments, minor changes
1 parent 1bb112d commit 5ce276f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

libc/src/math/generic/cosf16.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ LLVM_LIBC_FUNCTION(float16, cosf16, (float16 x)) {
5555

5656
// Handle exceptional values
5757

58-
if (LIBC_UNLIKELY(x_abs == 0x2b7c || x_abs == 0x4ac1 || x_abs == 0x5c49 ||
59-
x_abs == 0x7acc)) {
60-
if (auto r = COSF16_EXCEPTS.lookup(x_abs); LIBC_UNLIKELY(r.has_value()))
61-
return r.value();
62-
}
58+
if (auto r = COSF16_EXCEPTS.lookup(x_abs); LIBC_UNLIKELY(r.has_value()))
59+
return r.value();
6360

61+
// cos(+/-0) = 1
6462
if (LIBC_UNLIKELY(x_abs == 0U))
6563
return fputil::cast<float16>(1.0f);
6664

65+
// cos(+/-inf) = NaN, and cos(NaN) = NaN
6766
if (xbits.is_inf_or_nan()) {
6867
if (xbits.is_inf()) {
6968
fputil::set_errno_if_required(EDOM);
@@ -76,7 +75,9 @@ LLVM_LIBC_FUNCTION(float16, cosf16, (float16 x)) {
7675
float sin_k, cos_k, sin_y, cosm1_y;
7776
sincosf16_eval(xf, sin_k, cos_k, sin_y, cosm1_y);
7877
// Since, cosm1_y = cos_y - 1, therefore:
79-
// cos(x) = cos_k * cosm1_y - sin_k * sin_y
78+
// cos(x) = cos_k * cos_y - sin_k * sin_y
79+
// = cos_k * (cos_y - 1 + 1) - sin_k * sin_y
80+
// = cos_k * cosm1_y - sin_k * sin_y + cos_k
8081
return fputil::cast<float16>(fputil::multiply_add(
8182
cos_k, cosm1_y, fputil::multiply_add(-sin_k, sin_y, cos_k)));
8283
}

libc/src/math/generic/sinf16.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ LLVM_LIBC_FUNCTION(float16, sinf16, (float16 x)) {
5454
// sin(y * pi/32) * cos(k * pi/32)
5555

5656
// Handle exceptional values
57-
if (LIBC_UNLIKELY(x_abs == 0x585c || x_abs == 0x5cb0 || x_abs == 0x51f5 ||
58-
x_abs == 0x2b45)) {
59-
bool x_sign = x_u >> 15;
60-
if (auto r = SINF16_EXCEPTS.lookup_odd(x_abs, x_sign);
57+
bool x_sign = x_u >> 15;
58+
if (auto r = SINF16_EXCEPTS.lookup_odd(x_abs, x_sign);
6159
LIBC_UNLIKELY(r.has_value()))
62-
return r.value();
63-
}
60+
return r.value();
6461

6562
int rounding = fputil::quick_get_round();
6663

0 commit comments

Comments
 (0)