Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / mathffp / spfloor.c
blob548d01a52c71c2085335f95527e1ffab000718d3
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*
9 FUNCTION
10 Calculate the largest integer ffp-number less than or equal to
11 fnum
13 RESULT
14 FFP number
16 Flags:
17 zero : result is zero
18 negative : result is negative
19 overflow : 0 (???)
21 NOTES
23 EXAMPLE
24 floor(10.5) = 10
25 floor(0.5) = 0
26 floor(-0.5) = -1
27 floor(-10.5)= -11
29 BUGS
31 SEE ALSO
32 @Math.Floor@
34 INTERNALS
35 ALGORITHM:
36 <p>The integer part of a ffp number are the left "exponent"-bits
37 of the mantisse!
38 Therefore:
39 Test the exponent for <code><= 0</code>. This has to be done separately!
40 If the sign is negative then return -1 otherwise return 0.</p>
42 <p>Generate a mask of exponent(y) (where y is the given ffp-number)
43 bits starting with bit 31.
44 If <code>y < 0</code> then test whether it is already an integer. If not
45 then y = y - 1 and generate that mask again. Use the
46 mask on the mantisse.</p>
48 HISTORY
51 AROS_LH1(float, SPFloor,
52 AROS_LHA(float, y, D0),
53 struct LibHeader *, MathBase, 15, Mathffp
56 AROS_LIBFUNC_INIT
58 LONG Mask = 0x80000000;
60 if (((char)y & FFPExponent_Mask) <= 0x40)
62 if ((char)y < 0)
64 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
65 return 0x800000C1; /* -1 */
67 else
69 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
70 return 0;
74 /* |fnum| >= 1 */
75 Mask >>= ( ((char) y & FFPExponent_Mask) - 0x41);
76 Mask |= FFPSign_Mask | FFPExponent_Mask;
78 /* fnum is negative */
79 if ((char) y < 0)
81 /* is there anything behind the dot? */
82 if (0 != (y & (~Mask)) )
84 Mask = 0x80000000;
85 y = SPAdd(y, 0x800000c1); /* y = y -1; */
86 Mask >>= ((char) y & FFPExponent_Mask) - 0x41;
87 Mask |= FFPSign_Mask | FFPExponent_Mask;
91 if((char) y < 0)
93 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
96 return y & Mask;
98 AROS_LIBFUNC_EXIT