[libc-commits] [libc] [libc][math] Fix `tanpif` and `tanpif16` error handling (PR #235296)
via libc-commits
libc-commits at lists.llvm.org
Sat Oct 24 09:15:32 PDT 2026
================
@@ -53,13 +53,24 @@ LIBC_INLINE float16 tanpif16(float16 x) {
if (LIBC_UNLIKELY(x_abs == 0U))
return x;
+ // tanpi(x) underflows for 0 < |x| <= 0x1.45p-16.
+ if (LIBC_UNLIKELY(x_abs <= 0x0145U)) {
+ fputil::set_errno_if_required(ERANGE);
+ fputil::raise_except_if_required(FE_UNDERFLOW | FE_INEXACT);
+ }
+
if (LIBC_UNLIKELY(fputil::is_integer(x))) {
// Preserve the input sign for even integers and flip it for odd integers.
Sign sign =
fputil::is_odd_integer(x) ? xbits.sign().negate() : xbits.sign();
return FPBits::zero(sign).get_val();
}
+ // Odd multiples of 1/4 have exact results of +1 or -1.
+ float xf = x;
+ if (LIBC_UNLIKELY(fputil::is_odd_integer(4.0f * xf)))
+ return fputil::is_odd_integer(2.0f * xf - 0.5f) ? -1.0f16 : 1.0f16;
----------------
lntue wrote:
use `multiply_add`.
https://github.com/llvm/llvm-project/pull/235296
More information about the libc-commits
mailing list