On 7/31/2025 1:45 AM, Joseph Myers wrote:
On Sun, 6 Jul 2025, Yuao Ma wrote:

+#ifndef HAVE_COSPI
+#define HAVE_COSPI 1
+double cospi (double);
+
+double
+cospi (double x)
+{
+  return cos (x * pihi_d + x * pilo_d);

For reasonable results for large x you should first reduce mod 2 to the
range [-1, 1] (or reduce mod 1 and keep track of the parity of the integer
you subtracted, etc.), before multiplying.  And for reasonable results for
x near a half-integer, you need to adjust to calling sin in such a case;
cospi (0.5) should be exactly 0, which you won't get from calling cos on
an argument close to pi/2.  See the type-generic templates in glibc for
example logic.  Similar issues apply to all of cospi, sinpi, tanpi, for
all floating-point formats.


Thanks for the suggestions! I'll reference the glibc implementation and update the patch accordingly.

By the way, could you please take another look at the libquadmath update?

https://inbox.sourceware.org/fortran/kl1pr0601mb4291e1457dc09fe3aa6652c884...@kl1pr0601mb4291.apcprd06.prod.outlook.com/

This update uses a script to transform glibc's implementation for libquadmath. I'm wondering if the current implementation is good enough for inclusion in GCC or if we need to address any potential precision issues in glibc first.

Thanks,
Yuao

Reply via email to