sincos does not give same values as separate sin and cos

Bug #2076653 reported by Carl Dehlin
6
This bug affects 1 person
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://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]

Revision history for this message
Carl Dehlin (cdeln-ubuntu) wrote :

Found duplicate bug report in glibc bug tracker: https://sourceware.org/bugzilla/show_bug.cgi?id=29193
This is fixed in glibc 2.36

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.