blob: d3ac1c4c8c29e11067d55a3a99fa82eb888c5dd5 [file] [log] [blame]
Rich Felker007c03f2012-07-02 20:25:28 -04001#define _GNU_SOURCE
nsz0144b452012-03-15 08:17:28 +01002#include "libm.h"
3
4#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
5void sincosl(long double x, long double *sin, long double *cos)
6{
Szabolcs Nagy73c870e2014-04-11 17:57:30 +02007 double sind, cosd;
8 sincos(x, &sind, &cosd);
9 *sin = sind;
10 *cos = cosd;
nsz0144b452012-03-15 08:17:28 +010011}
12#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
nsz0144b452012-03-15 08:17:28 +010013void sincosl(long double x, long double *sin, long double *cos)
14{
Szabolcs Nagyea9bb952013-09-03 18:50:58 +000015 union ldshape u = {x};
Szabolcs Nagybfda3792013-05-18 14:40:22 +000016 unsigned n;
nsz0144b452012-03-15 08:17:28 +010017 long double y[2], s, c;
18
Szabolcs Nagyea9bb952013-09-03 18:50:58 +000019 u.i.se &= 0x7fff;
20 if (u.i.se == 0x7fff) {
nsz0144b452012-03-15 08:17:28 +010021 *sin = *cos = x - x;
22 return;
23 }
Szabolcs Nagyea9bb952013-09-03 18:50:58 +000024 if (u.f < M_PI_4) {
25 if (u.i.se < 0x3fff - LDBL_MANT_DIG) {
Szabolcs Nagybfda3792013-05-18 14:40:22 +000026 /* raise underflow if subnormal */
Szabolcs Nagyea9bb952013-09-03 18:50:58 +000027 if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f);
Szabolcs Nagybfda3792013-05-18 14:40:22 +000028 *sin = x;
29 /* raise inexact if x!=0 */
30 *cos = 1.0 + x;
31 return;
32 }
nsz0144b452012-03-15 08:17:28 +010033 *sin = __sinl(x, 0, 0);
34 *cos = __cosl(x, 0);
35 return;
36 }
nsz0144b452012-03-15 08:17:28 +010037 n = __rem_pio2l(x, y);
38 s = __sinl(y[0], y[1], 1);
39 c = __cosl(y[0], y[1]);
40 switch (n & 3) {
41 case 0:
42 *sin = s;
43 *cos = c;
44 break;
45 case 1:
46 *sin = c;
47 *cos = -s;
48 break;
49 case 2:
50 *sin = -s;
51 *cos = -c;
52 break;
53 case 3:
54 default:
55 *sin = -c;
56 *cos = s;
57 break;
58 }
59}
60#endif