Improved layout calculation.
[cake.git] / rom / mathffp / spfix.c
blob21852366e8e0ff3a30e9020876df85fad29c1465
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*
9 FUNCTION
10 Convert ffp-number to integer
12 RESULT
13 absolute value of fnum1
15 Flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : ffp out of integer-range
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
29 INTERNALS
31 HISTORY
34 AROS_LH1(LONG, SPFix,
35 AROS_LHA(float, fnum, D0),
36 struct LibHeader *, MathBase, 5, Mathffp
39 AROS_LIBFUNC_INIT
41 LONG Res;
42 BYTE Shift;
44 if ((fnum & FFPExponent_Mask) > 0x60 )
46 if(fnum < 0) /* don`t hurt the SR! */
48 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
49 return 0x80000000;
51 else
53 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
54 return 0x7fffffff;
59 Shift = (fnum & FFPExponent_Mask) - 0x40;
60 Res = ((ULONG)(fnum & FFPMantisse_Mask)) >> (32 - Shift);
62 if (0 == Res)
64 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
65 return 0;
68 if (0x80000000 == Res) return 0x7fffffff;
71 /* Test for a negative sign */
72 if ((char)fnum < 0)
74 Res = -Res;
75 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
78 kprintf("SPFix(%x)=%d\n",fnum,Res);
80 return Res;
82 AROS_LIBFUNC_EXIT