Workaround for includes conflict that stopped compilation with GCC 3.
[cake.git] / rom / mathieeesingbas / ieeespflt.c
blob967a9ed736395ca840677df4dc3091c4614dfdb4
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingbas_intern.h"
8 /*
9 FUNCTION
11 RESULT
12 Flags:
13 zero : result is zero
14 negative : result is negative
15 overflow : IEEE single precision number is not exactly the integer
17 NOTES
19 EXAMPLE
21 BUGS
23 SEE ALSO
26 INTERNALS
28 HISTORY
31 AROS_LH1(float, IEEESPFlt,
32 AROS_LHA(LONG, y, D0),
33 struct LibHeader *, MathIeeeSingBasBase, 6, Mathieeesingbas
36 AROS_LIBFUNC_INIT
38 LONG Exponent = 0;
39 LONG TestMask = 0xFFFFFFFF;
40 LONG Res = 0;
42 if (y == 0)
44 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
45 return 0;
48 if (y < 0)
50 Res = IEEESPSign_Mask;
51 y= -y;
53 /* find out which is the number of the highest set bit */
54 while (TestMask & y)
56 Exponent ++;
57 TestMask <<= 1;
60 if (Exponent >= 26) y >>= (Exponent - 25) & IEEESPMantisse_Mask;
61 else y <<= (25 - Exponent) & IEEESPMantisse_Mask;
63 if ((char) (y & 1) != 0)
65 y ++;
66 if (0x02000000 == y) Exponent++;
69 y >>= 1;
70 y &= IEEESPMantisse_Mask;
72 Exponent += 0x7E;
74 /* adapt Exponent to IEEESP-Format */
75 Exponent <<= 23;
76 Res |= y | Exponent;
78 if (Res < 0) SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
80 /* The resulting IEEESP is lacking precision */
81 if (Exponent > 0x4c800000)
83 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
86 return Res;
88 AROS_LIBFUNC_EXIT