2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 #include "mathffp_intern.h"
8 /*****************************************************************************
12 AROS_LH1(float, SPFlt
,
15 AROS_LHA(LONG
, inum
, D0
),
18 struct LibHeader
*, MathBase
, 6, Mathffp
)
29 negative : result is negative
30 overflow : ffp is not exactly the integer
35 Return zero for x == 0.
36 If x < 0 set the sign-bit and calculate the absolute value
38 Find out which bit is the highest-set bit. If the number
39 of that bit <code>> 24</code> then the result has the highest bit
40 of the mantisse set to one and the exponent equals the
41 number of the bit + 2. This is due to the fact that we only
42 have 24 bits for the mantisse.
43 Otherwise rotate the given integer by
44 (32 - (number of highes set bit + 1)) bits to the left and
45 calculate the result from that.
47 *****************************************************************************/
52 LONG TestMask
= 0xFFFFFFFF;
55 D(kprintf("SPFlt(%d) = ",inum
));
59 SetSR(Zero_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
69 /* find out which is the number of the highes set bit */
70 while (TestMask
& inum
)
76 /* Exponent = number of highest set bit + 1 */
78 if (Exponent
> 0) /* > 32 bit LONG shift = undefined */
79 inum
<<= (32 - Exponent
);
82 if ((char) inum
< 0) inum
+=0x100;
83 inum
&= FFPMantisse_Mask
;
85 /* adapt the exponent to the ffp format */
87 Res
|= inum
| Exponent
;
90 SetSR(Negative_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
93 if (Exponent
> (25 + 0x40))
96 SetSR(Overflow_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
99 D(kprintf("%x\n",Res
));