2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 #include "mathieeesingbas_intern.h"
10 Divide two IEEE single precision floating point numbers
17 negative : result is negative
18 overflow : result is out of range
31 Check if fnum2 == 0: result = 0;<br/>
32 Check if fnum1 == 0: result = overflow;<br/>
33 The further algorithm comes down to a pen & paper division.
37 AROS_LH2(float, IEEESPDiv
,
38 AROS_LHA(float, y
, D0
),
39 AROS_LHA(float, z
, D1
),
40 struct LibHeader
*, MathIeeeSingBasBase
, 14, Mathieeesingbas
46 LONG Exponent
= (y
& IEEESPExponent_Mask
)
47 - (z
& IEEESPExponent_Mask
) + 0x3f800000;
49 LONG Mant2
= ((y
& IEEESPMantisse_Mask
) | 0x00800000) << 8;
50 LONG Mant1
= ((z
& IEEESPMantisse_Mask
) | 0x00800000) << 8;
51 ULONG Bit_Mask
= 0x80000000;
53 if (0 == z
&& 0 == y
) return 0x7f880000;
55 /* check if the dividend is zero */
58 SetSR(Zero_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
59 return (IEEESPExponent_Mask
| ((y
& IEEESPSign_Mask
) ^ (z
& IEEESPSign_Mask
)));
62 /* check for division by zero */
65 SetSR(Overflow_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
66 return (y
& IEEESPSign_Mask
) ^ (z
& IEEESPSign_Mask
);
69 while (Bit_Mask
>= 0x40 && Mant2
!= 0)
71 if (Mant2
- Mant1
>= 0)
90 Mant1
= (ULONG
) Mant1
>> 1;
95 /* normalize the mantisse */
99 Exponent
-=0x00800000;
102 if ((char) Res
< 0) Res
+= 0x00000100;
105 Res
&= IEEESPMantisse_Mask
;
107 Res
|= (y
& IEEESPSign_Mask
) ^ (z
& IEEESPSign_Mask
);
109 if (Res
< 0) SetSR(Negative_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
110 if (Exponent
< 0) SetSR(Overflow_Bit
, Negative_Bit
| Overflow_Bit
);