grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathtrans / spacos.c
blob6bd00a770b444c30994ab564e10f26c849187159
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunSoft, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 #include "mathtrans_intern.h"
19 /*****************************************************************************
21 NAME */
23 AROS_LH1(float, SPAcos,
25 /* SYNOPSIS */
26 AROS_LHA(float, fnum1, D0),
28 /* LOCATION */
29 struct Library *, MathTransBase, 20, MathTrans)
31 /* FUNCTION
32 Calculate arcuscos of the given number
34 INPUTS
36 RESULT
37 Motorola fast floating point number
39 flags:
40 zero : Result is zero
41 negative : 0 (not possible)
42 overflow : fnum < -1 or fnum > 1
44 BUGS
46 INTERNALS
48 HISTORY
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
54 /* 1> |x| >= 0.5 */
55 LONG z,p,q,r,w,s,c,ix,df;
56 ix = fnum1 & (FFPMantisse_Mask | FFPExponent_Mask); /* ix = |fnum| */
58 z = SPCmp(ix,one);
60 if (1==z) /* |fnum1| > 1 */
62 SetSR(Overflow_Bit, Zero_Bit | Overflow_Bit | Negative_Bit);
63 return -1;
66 if (0==z) /* |fnum1| = 1 */
68 if (fnum1 & FFPSign_Mask) /* |fnum| = -1 */ return pi;
69 SetSR(Zero_Bit, Zero_Bit | Overflow_Bit | Negative_Bit);
70 return 0;
73 /* error: 1 ulp (unit in the last place) */
74 if (-1 == SPCmp(ix,onehalf)) /* |fnum1| < 0.5 */
76 z = SPMul(fnum1, fnum1);
77 p = SPMul(z, SPAdd(pS0,
78 SPMul(z, SPAdd(pS1,
79 SPMul(z, SPAdd(pS2,
80 SPMul(z, SPAdd(pS3,
81 SPMul(z, SPAdd(pS4,
82 SPMul(z, pS5)))))))))));
83 q = SPAdd(one,
84 SPMul(z, SPAdd(qS1,
85 SPMul(z, SPAdd(qS2,
86 SPMul(z, SPAdd(qS3,
87 SPMul(z, qS4))))))));
88 r = SPDiv(q, p);
89 return (SPSub(SPAdd(fnum1,SPMul(fnum1,r)),pio2));
92 /* error: 1 ulp */
93 if (fnum1 & FFPSign_Mask) /* fnum1 < -0.5 */
95 z = SPMul(onehalf, SPAdd(one, fnum1));
96 p = SPMul(z, SPAdd(pS0,
97 SPMul(z, SPAdd(pS1,
98 SPMul(z, SPAdd(pS2,
99 SPMul(z, SPAdd(pS3,
100 SPMul(z, SPAdd(pS4,
101 SPMul(z, pS5)))))))))));
102 q = SPAdd(one,
103 SPMul(z, SPAdd(qS1,
104 SPMul(z, SPAdd(qS2,
105 SPMul(z, SPAdd(qS3,
106 SPMul(z, qS4))))))));
107 s = SPSqrt(z);
108 r = SPDiv(q,p); /* r = p/q; */
109 w = SPMul(r,s);
110 return SPSub(SPMul(two, SPAdd(s, w)) ,pi);
113 /* error: 8 ulp (this is bad !!!!) */
114 /* fnum1 > 0.5 */
115 z = SPMul(onehalf, SPSub(fnum1, one));
116 s = SPSqrt(z);
117 df = s;
118 df = df & 0xfff000ff;
119 c = SPDiv(SPAdd(df,s), SPSub( SPMul(df,df), z));
120 p = SPMul(z, SPAdd(pS0,
121 SPMul(z, SPAdd(pS1,
122 SPMul(z, SPAdd(pS2,
123 SPMul(z, SPAdd(pS3,
124 SPMul(z, SPAdd(pS4,
125 SPMul(z, pS5)))))))))));
126 q = SPAdd(one,
127 SPMul(z, SPAdd(qS1,
128 SPMul(z, SPAdd(qS2,
129 SPMul(z, SPAdd(qS3,
130 SPMul(z, qS4))))))));
131 r = SPDiv(q, p);
132 w = SPAdd(c, SPMul(r,s));
134 return SPAdd(SPMul(two, SPAdd(df,w)),0x800000a9);
136 AROS_LIBFUNC_EXIT