Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathieeesingbas / ieeespflt.c
blobc1a00e5d46be8c11b553d89f7a46adab01d69b99
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingbas_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(float, IEEESPFlt,
14 /* SYNOPSIS */
15 AROS_LHA(LONG, y, D0),
17 /* LOCATION */
18 struct LibHeader *, MathIeeeSingBasBase, 6, Mathieeesingbas)
20 /* FUNCTION
22 INPUTS
24 RESULT
25 Flags:
26 zero : result is zero
27 negative : result is negative
28 overflow : IEEE single precision number is not exactly the integer
30 BUGS
32 INTERNALS
34 *****************************************************************************/
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