grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathieeesingtrans / ieeespsin.c
blob168b6e74b8381a4fe49f2a1ceed5907ba54b853c
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(float, IEEESPSin,
14 /* SYNOPSIS */
15 AROS_LHA(float, y, D0),
17 /* LOCATION */
18 struct Library *, MathIeeeSingTransBase, 6, MathIeeeSingTrans)
20 /* FUNCTION
21 Calculate the sine of a given IEEE single precision number in radians
23 INPUTS
25 RESULT
26 IEEE single precision floating point number
28 flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : 0
33 BUGS
35 INTERNALS
36 Algorithm for Calculation of sin(y):
38 z = floor ( |y| / pi );
39 y_1 = |y| - z * pi; => 0 <= y_1 < pi
41 if (y_1 > pi/2 ) then y_1 = pi - y_1;
43 => 0 <= y_1 < pi/2
45 Res = y - y^3/3! + y^5/5! - y^7/7! + y^9/9! - y^11/11! =
46 = y(1+y^2(-1/3!+y^2(1/5!+y^2(-1/7!+y^2(1/9!-1/11!y^2)))));
48 if (y < 0)
49 Res = -Res;
51 if (z was an odd number)
52 Res = -Res;
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 LONG z,Res,ysquared,yabs,tmp;
59 yabs = y & (IEEESPMantisse_Mask + IEEESPExponent_Mask);
61 if (IEEESP_Pinfty == yabs)
63 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
64 return IEEESP_NAN;
67 z = IEEESPFloor(IEEESPDiv(yabs, pi));
68 tmp = IEEESPMul(z,pi);
69 tmp |= IEEESPSign_Mask; /* tmp = -tmp; */
70 yabs = IEEESPAdd(yabs, tmp);
71 if (yabs > pio2)
73 yabs |= IEEESPSign_Mask;
74 yabs =IEEESPAdd(pi, yabs);
76 ysquared = IEEESPMul(yabs,yabs);
77 Res = IEEESPMul(yabs,
78 IEEESPAdd(sinf1,
79 IEEESPMul(ysquared,
80 IEEESPAdd(sinf2,
81 IEEESPMul(ysquared,
82 IEEESPAdd(sinf3,
83 IEEESPMul(ysquared,
84 IEEESPAdd(sinf4,
85 IEEESPMul(ysquared,
86 IEEESPAdd(sinf5,
87 IEEESPMul(ysquared, sinf6)))))))))));
89 if (y < 0 ) Res ^= IEEESPSign_Mask;
90 if (TRUE == intern_IEEESPisodd(z)) Res ^= IEEESPSign_Mask;
92 if (0 == Res)
94 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
95 return 0;
98 if (Res < 0) SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
100 return Res;
102 AROS_LIBFUNC_EXIT