2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 #include "mathtrans_intern.h"
10 Calculate the cosine of a given ffp number in radians
13 Motorola fast floating point number
17 negative : result is negative
29 Algorithm for Calculation of cos(y):
31 z = floor ( |y| / pi );
32 y_1 = |y| - z * pi; => 0 <= y_1 < pi
34 if (y_1 > pi/2 ) then y_1 = pi - y_1;
38 Res = 1 - y^2/2! + y^4/4! - y^6/6! + y^8/8! - y^10/10! =
39 = 1 -(y^2(-1/2!+y^2(1/4!+y^2(-1/6!+y^2(1/8!-1/10!y^2)))));
41 if (z was an odd number)
44 if (y_1 was greater than pi/2 in the test above)
52 AROS_LH1(float, SPCos
,
53 AROS_LHA(float, fnum1
, D0
),
54 struct Library
*, MathTransBase
, 7, MathTrans
59 LONG z
,Res
,ysquared
,yabs
,tmp
;
60 yabs
= fnum1
& (FFPMantisse_Mask
+ FFPExponent_Mask
);
62 if ((LONG
)FFP_Pinfty
== yabs
)
64 SetSR(Overflow_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
68 z
= SPFloor(SPDiv(pi
, yabs
));
70 tmp
|= FFPSign_Mask
; /* tmp = -tmp; */
71 yabs
= SPAdd(yabs
, tmp
);
75 (char)yabs
> (char)pio2
76 && (yabs
& FFPMantisse_Mask
) > (pio2
& FFPMantisse_Mask
)
80 yabs
=SPAdd(pi
, yabs
);
88 ysquared
= SPMul(yabs
,yabs
);
98 SPMul(ysquared
, cosf6
))))))))));
102 SetSR(Zero_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
106 if (TRUE
== intern_SPisodd(z
)) Res
^= FFPSign_Mask
;
108 if (TRUE
== tmp
) Res
^= FFPSign_Mask
;
110 if ((char)Res
< 0) SetSR(Negative_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);