2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include "mathieeesingbas_intern.h"
8 /*****************************************************************************
12 AROS_LH2(float, IEEESPDiv
,
15 AROS_LHA(float, y
, D0
),
16 AROS_LHA(float, z
, D1
),
19 struct LibHeader
*, MathIeeeSingBasBase
, 14, Mathieeesingbas
)
22 Divide two IEEE single precision floating point numbers
30 negative : result is negative
31 overflow : result is out of range
37 Check if fnum2 == 0: result = 0;
38 Check if fnum1 == 0: result = overflow;
39 The further algorithm comes down to a pen & paper division.
41 *****************************************************************************/
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 */
98 if (Res
>= 0x40000000)
99 Res
= Res
- 0x80000000;
101 Exponent
-=0x00800000;
104 if ((char) Res
< 0) Res
+= 0x00000100;
107 Res
&= IEEESPMantisse_Mask
;
109 Res
|= (y
& IEEESPSign_Mask
) ^ (z
& IEEESPSign_Mask
);
111 if (Res
< 0) SetSR(Negative_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
112 if (Exponent
< 0) SetSR(Overflow_Bit
, Negative_Bit
| Overflow_Bit
);