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.
--
Joseph S. Myers
[email protected]