Public bug reported: sincos does not give the same result as sin and cos for certain double precision floating point values.
As documented at https://sourceware.org/glibc/manual/latest/html_mono/libc.html#Known-Maximum-Errors-in-Math-Functions , all three functions have error up to 1 ulp on x86_64 from the correctly rounded value. However, I can find no documentation that sincos might give different values than sin and cos (https://sourceware.org/glibc/manual/latest/html_mono/libc.html#index-sincos). 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-precision=standard -mfpmath=sse -lm (floating point settings is to ensure there can not be any issue with excess precision on x86_64) and run it with 1.2475784324341769870869711667182855308055877685546875 fed to stdin (random precision value found in a fuzz test, the literal can perfectly represented by a double). ===================== 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.e57cdd3c834a3p-1 cos(x) = 0x1.453e098c304afp-2 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-1ubuntu1~22.04) [installed through build-essential] ** Affects: glibc (Ubuntu) Importance: Undecided Status: New -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2076653 Title: sincos does not give same values as separate sin and cos To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2076653/+subscriptions -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs