Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathffp / spfix.c
blobe722d5b9f5807da2abdd90a59e63414d6c910a2a
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(LONG, SPFix,
14 /* SYNOPSIS */
15 AROS_LHA(float, fnum, D0),
17 /* LOCATION */
18 struct LibHeader *, MathBase, 5, Mathffp)
20 /* FUNCTION
21 Convert ffp-number to integer
23 INPUTS
25 RESULT
26 absolute value of fnum1
28 Flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : ffp out of integer-range
33 BUGS
35 INTERNALS
37 *****************************************************************************/
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 if (Shift > 0) /* > 32 bit LONG shift = undefined */
61 Res = ((ULONG)(fnum & FFPMantisse_Mask)) >> (32 - Shift);
62 else
63 Res = 0;
65 if (0 == Res)
67 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
68 return 0;
71 if (0x80000000 == Res) return 0x7fffffff;
74 /* Test for a negative sign */
75 if ((char)fnum < 0)
77 Res = -Res;
78 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
81 D(kprintf("SPFix(%x) = %d\n", fnum, Res));
83 return Res;
85 AROS_LIBFUNC_EXIT