1/*===--------------------------------------------------------------------------
2 *                   ROCm Device Libraries
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *===------------------------------------------------------------------------*/
7
8#include "mathD.h"
9#include "trigredD.h"
10
11double
12MATH_MANGLE(sincos)(double x, __private double * cp)
13{
14    struct redret r = MATH_PRIVATE(trigred)(BUILTIN_ABS_F64(x));
15    struct scret sc = MATH_PRIVATE(sincosred2)(r.hi, r.lo);
16
17    int flip = r.i > 1 ? (int)0x80000000 : 0;
18    bool odd = (r.i & 1) != 0;
19
20    int2 s = AS_INT2(odd ? sc.c : sc.s);
21    s.hi ^= flip ^ (AS_INT2(x).hi &(int)0x80000000);
22    sc.s = -sc.s;
23    int2 c = AS_INT2(odd ? sc.s : sc.c);
24    c.hi ^= flip;
25
26    if (!FINITE_ONLY_OPT()) {
27        bool nori = BUILTIN_CLASS_F64(x, CLASS_SNAN|CLASS_QNAN|CLASS_NINF|CLASS_PINF);
28        s = nori ? AS_INT2(QNANBITPATT_DP64) : s;
29        c = nori ? AS_INT2(QNANBITPATT_DP64) : c;
30    }
31
32    *cp = AS_DOUBLE(c);
33    return AS_DOUBLE(s);
34}
35
36