remove erroneous spaces
[AROS.git] / compiler / stdc / math / s_sincosf.c
blobff782997af176c1e0c4cbad53bb961a90ed46355
1 /* s_sincosf.c -- float version of s_sincos.c
3 * Copyright (C) 2013 Elliot Saba
4 * Developed at the University of Washington
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
12 #include <aros/debug.h>
14 #include "math.h"
15 #define INLINE_REM_PIO2F
16 #include "math_private.h"
17 #include "e_rem_pio2f.c"
18 #include "k_sincosf.h"
20 /* Small multiples of pi/2 rounded to double precision. */
21 static const double
22 p1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
23 p2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */
24 p3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */
25 p4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */
27 void
28 sincosf(float x, float *sn, float *cs)
30 float c, s;
31 double y;
32 int32_t n, hx, ix;
34 GET_FLOAT_WORD(hx,x);
35 ix = hx & 0x7fffffff;
37 if(ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
38 if(ix<0x39800000) { /* |x| < 2**-12 */
39 if ((int)x == 0) {
40 *sn = x; /* x with inexact if x != 0 */
41 *cs = 1;
42 return;
45 __kernel_sincosdf(x, sn, cs);
46 return;
49 if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
50 if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */
51 if(hx>0) {
52 __kernel_sincosdf(x - p1pio2, cs, sn);
53 *cs = -*cs;
54 } else {
55 __kernel_sincosdf(x + p1pio2, cs, sn);
56 *sn = -*sn;
58 } else {
59 if (hx > 0)
60 __kernel_sincosdf(x - p2pio2, sn, cs);
61 else
62 __kernel_sincosdf(x + p2pio2, sn, cs);
63 *sn = -*sn;
64 *cs = -*cs;
66 return;
69 if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
70 if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */
71 if(hx>0) {
72 __kernel_sincosdf(x - p3pio2, cs, sn);
73 *sn = -*sn;
74 } else {
75 __kernel_sincosdf(x + p3pio2, cs, sn);
76 *cs = -*cs;
78 } else {
79 if (hx > 0)
80 __kernel_sincosdf(x - p4pio2, sn, cs);
81 else
82 __kernel_sincosdf(x + p4pio2, sn, cs);
84 return;
87 /* If x = Inf or NaN, then sin(x) = NaN and cos(x) = NaN. */
88 if (ix >= 0x7f800000) {
89 *sn = x - x;
90 *cs = x - x;
91 return;
94 /* Argument reduction. */
95 n = __ieee754_rem_pio2f(x,&y);
96 __kernel_sincosdf(y, &s, &c);
98 switch(n&3) {
99 case 0:
100 *sn = s;
101 *cs = c;
102 break;
103 case 1:
104 *sn = c;
105 *cs = -s;
106 break;
107 case 2:
108 *sn = -s;
109 *cs = -c;
110 break;
111 default:
112 *sn = -c;
113 *cs = s;