From be4c7f273508994638b68d2fae742be37d3cb117 Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Mon, 17 Jul 2023 08:19:28 +0300 Subject: [PATCH] libm: correctly test for for NaN and Infinity in sinpi(), cospi(), and tanpi() The current versions of lib/msun/src/s_cospi.c, s_sinpi.c and s_tanpi.c all exhibit the same defect. After checking for various numeric ranges, they check to see whether the input argument is a NaN or an Infinity. However, the code uses a value of 0x7f80000 instead of the correct value of 0x7ff00000. If you review s_cospif.c, s_sinpif.c, and s_tanpif.c, you will see that the equivalent statements in these functions are accurate and have appropriate source comments. The impact of these defects is to flag some valid input values as invalid and raise a pole error (divide by zero). Reported by: Paul Green PR: 272539 MFC after: 1 week --- lib/msun/src/s_cospi.c | 3 ++- lib/msun/src/s_sinpi.c | 3 ++- lib/msun/src/s_tanpi.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/msun/src/s_cospi.c b/lib/msun/src/s_cospi.c index 860219efd3e..2e2f92733a8 100644 --- a/lib/msun/src/s_cospi.c +++ b/lib/msun/src/s_cospi.c @@ -138,7 +138,8 @@ cospi(double x) return (j0 & 1 ? -c : c); } - if (ix >= 0x7f800000) + /* x = +-inf or nan. */ + if (ix >= 0x7ff00000) return (vzero / vzero); /* diff --git a/lib/msun/src/s_sinpi.c b/lib/msun/src/s_sinpi.c index 858459a5fcb..bc3759e567a 100644 --- a/lib/msun/src/s_sinpi.c +++ b/lib/msun/src/s_sinpi.c @@ -155,7 +155,8 @@ sinpi(double x) return ((hx & 0x80000000) ? -s : s); } - if (ix >= 0x7f800000) + /* x = +-inf or nan. */ + if (ix >= 0x7ff00000) return (vzero / vzero); /* diff --git a/lib/msun/src/s_tanpi.c b/lib/msun/src/s_tanpi.c index 01d4c74367f..f911d56156b 100644 --- a/lib/msun/src/s_tanpi.c +++ b/lib/msun/src/s_tanpi.c @@ -163,7 +163,7 @@ tanpi(double x) } /* x = +-inf or nan. */ - if (ix >= 0x7f800000) + if (ix >= 0x7ff00000) return (vzero / vzero); /*