add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / mathieeedoubtrans / ieeedpcos.c
blob80c96441bdb35f706d238fc307277a8a720b017a
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeedoubtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate the cosine of a given IEEE double precision number in radians
12 RESULT
13 IEEE double precision floating point number
15 flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : 0
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
29 cos (x) = sin (x+ pi/2);
31 HISTORY
34 AROS_LHQUAD1(double, IEEEDPCos,
35 AROS_LHAQUAD(double, y, D0, D1),
36 struct MathIeeeDoubTransBase *, MathIeeeDoubTransBase, 7, MathIeeeDoubTrans
39 AROS_LIBFUNC_INIT
41 LONG tmp;
42 QUAD z,Res, ysquared, yabs, Qtmp;
43 AND64C
45 yabs, y,
46 (IEEEDPMantisse_Mask_Hi | IEEEDPExponent_Mask_Hi),
47 (IEEEDPMantisse_Mask_Lo | IEEEDPExponent_Mask_Lo)
50 if (is_eqC(yabs, IEEEDPPInfty_Hi, IEEEDPPInfty_Lo))
52 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
53 Set_Value64C(Res, IEEEDPNAN_Hi, IEEEDPNAN_Lo);
54 return Res;
57 z = IEEEDPFloor(IEEEDPDiv(yabs, pi));
58 Qtmp = IEEEDPMul(z,pi);
59 OR64QC(tmp, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo) /* Qtmp=-Qtmp */
60 yabs = IEEEDPAdd(yabs, Qtmp);
61 if (is_greaterC(yabs, pio2_Hi, pio2_Lo))
63 OR64QC(Qtmp, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo) /* Qtmp=-Qtmp */
64 yabs =IEEEDPAdd(pi, yabs);
65 tmp = TRUE;
67 else
69 tmp = FALSE;
72 ysquared = IEEEDPMul(yabs,yabs);
73 Res = IEEEDPAdd(cosf1,
74 IEEEDPMul(ysquared,
75 IEEEDPAdd(cosf2,
76 IEEEDPMul(ysquared,
77 IEEEDPAdd(cosf3,
78 IEEEDPMul(ysquared,
79 IEEEDPAdd(cosf4,
80 IEEEDPMul(ysquared,
81 IEEEDPAdd(cosf5,
82 IEEEDPMul(ysquared,
83 IEEEDPAdd(cosf6,
84 IEEEDPMul(ysquared,
85 IEEEDPAdd(cosf7,
86 IEEEDPMul(ysquared, cosf8))))))))))))));
88 if (is_eqC(Res, 0x0, 0x0))
90 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
91 Set_Value64C(Res, 0x0, 0x0);
92 return Res;
95 if (TRUE == intern_IEEEDPisodd(z))
97 XOR64QC(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
100 if (TRUE == tmp)
102 XOR64QC(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
105 if (is_lessSC(Res, 0x0, 0x0))
107 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
110 return Res;
112 AROS_LIBFUNC_EXIT