@@ -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}
0 commit comments