sincos does not give same values as separate sin and cos
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
glibc (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
sincos does not give the same result as sin and cos for certain double precision floating point values.
As documented at https:/
However, I can find no documentation that sincos might give different values than sin and cos (https:/
This might seem like a non-issue, until compilers assume that a pair of sin and cos can be optimized to a sincos call without turning on fast/unsafe math optimizations.
To reproduce, compile the following test case with gcc -ffloat-store -fexcess-
=======
Test case source code
=======
#define _GNU_SOURCE
#include <assert.h>
#include <math.h>
#include <stdio.h>
int main()
{
double x;
if (!scanf("%lf", &x)) {
return 1;
}
double c, s;
sincos(x, &s, &c);
printf("sin(x) = %a\ncos(x) = %a\n", s, c);
printf("cos(x) = %a\n", cos(x));
assert(c == cos(x));
return 0;
}
================
Test case output
================
sin(x) = 0x1.e57cdd3c834
cos(x) = 0x1.453e098c304
cos(x) = 0x1.453e098c304bp-2
a.out: sincos.c:16: main: Assertion `c == cos(x)' failed.
Aborted (core dumped)
==================
System information
==================
OS version : Ubuntu 22.04.2 LTS
libc6 version: 2.35-0ubuntu3.8 [installed through build-essential]
gcc version: gcc (Ubuntu 11.4.0-
Found duplicate bug report in glibc bug tracker: https:/ /sourceware. org/bugzilla/ show_bug. cgi?id= 29193
This is fixed in glibc 2.36