grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathieeedoubtrans / ieeedpcos.c
blob02ac9306e39677b228e6da2cc1ee42c8c730f037
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeedoubtrans_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LHQUAD1(double, IEEEDPCos,
14 /* SYNOPSIS */
15 AROS_LHAQUAD(double, y, D0, D1),
17 /* LOCATION */
18 struct MathIeeeDoubTransBase *, MathIeeeDoubTransBase, 7, MathIeeeDoubTrans)
20 /* FUNCTION
21 Calculate the cosine of a given IEEE double precision number in radians
23 INPUTS
25 RESULT
26 IEEE double precision floating point number
28 flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : 0
33 BUGS
35 INTERNALS
36 cos (x) = sin (x+ pi/2);
38 *****************************************************************************/
40 AROS_LIBFUNC_INIT
42 LONG tmp;
43 QUAD z,Res, ysquared, yabs, Qtmp;
44 AND64C
46 yabs, y,
47 (IEEEDPMantisse_Mask_Hi | IEEEDPExponent_Mask_Hi),
48 (IEEEDPMantisse_Mask_Lo | IEEEDPExponent_Mask_Lo)
51 if (is_eqC(yabs, IEEEDPPInfty_Hi, IEEEDPPInfty_Lo))
53 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
54 Set_Value64C(Res, IEEEDPNAN_Hi, IEEEDPNAN_Lo);
55 return Res;
58 z = IEEEDPFloor(IEEEDPDiv(yabs, pi));
59 Qtmp = IEEEDPMul(z,pi);
60 OR64QC(Qtmp, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo) /* Qtmp=-Qtmp */
61 yabs = IEEEDPAdd(yabs, Qtmp);
62 if (is_greaterC(yabs, pio2_Hi, pio2_Lo))
64 OR64QC(Qtmp, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo) /* Qtmp=-Qtmp */
65 yabs =IEEEDPAdd(pi, yabs);
66 tmp = TRUE;
68 else
70 tmp = FALSE;
73 ysquared = IEEEDPMul(yabs,yabs);
74 Res = IEEEDPAdd(cosf1,
75 IEEEDPMul(ysquared,
76 IEEEDPAdd(cosf2,
77 IEEEDPMul(ysquared,
78 IEEEDPAdd(cosf3,
79 IEEEDPMul(ysquared,
80 IEEEDPAdd(cosf4,
81 IEEEDPMul(ysquared,
82 IEEEDPAdd(cosf5,
83 IEEEDPMul(ysquared,
84 IEEEDPAdd(cosf6,
85 IEEEDPMul(ysquared,
86 IEEEDPAdd(cosf7,
87 IEEEDPMul(ysquared, cosf8))))))))))))));
89 if (is_eqC(Res, 0x0, 0x0))
91 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
92 Set_Value64C(Res, 0x0, 0x0);
93 return Res;
96 if (TRUE == intern_IEEEDPisodd(z))
98 XOR64QC(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
101 if (TRUE == tmp)
103 XOR64QC(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
106 if (is_lessSC(Res, 0x0, 0x0))
108 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
111 return Res;
113 AROS_LIBFUNC_EXIT