2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include "mathffp_intern.h"
8 /*****************************************************************************
12 AROS_LH2(float, SPDiv
,
15 AROS_LHA(float, fnum1
, D1
),
16 AROS_LHA(float, fnum2
, D0
),
19 struct LibHeader
*, MathBase
, 14, Mathffp
)
22 Divide two ffp numbers
30 negative : result is negative
31 overflow : result is out of range
34 The parameters are swapped!
38 Check if fnum2 == 0: result = 0;
39 Check if fnum1 == 0: result = overflow;
40 The further algorithm comes down to a pen & paper division
42 *****************************************************************************/
47 char Exponent
= ((char) fnum2
& FFPExponent_Mask
) -
48 ((char) fnum1
& FFPExponent_Mask
) + 0x41;
50 LONG Mant2
= ((ULONG
)fnum2
& FFPMantisse_Mask
);
51 LONG Mant1
= ((ULONG
)fnum1
& FFPMantisse_Mask
);
52 ULONG Bit_Mask
= 0x80000000;
54 /* check if the dividend is zero */
57 SetSR(Zero_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
61 /* check for division by zero */
64 SetSR(Overflow_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
68 while (Bit_Mask
>= 0x40 && Mant2
!= 0)
70 if (Mant2
- Mant1
>= 0)
89 Mant1
= (ULONG
) Mant1
>> 1;
94 /* normalize the mantisse */
97 if (Res
>= 0x40000000)
98 Res
= Res
- 0x80000000;
108 Res
&= FFPMantisse_Mask
;
109 Res
|= (Exponent
& 0x7f);
110 Res
|= (fnum1
& FFPSign_Mask
) ^ (fnum2
& FFPSign_Mask
);
114 SetSR(Negative_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
117 if ((char) Exponent
< 0)
119 SetSR(Overflow_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
120 return(Res
| (FFPMantisse_Mask
| FFPExponent_Mask
));
123 D(kprintf("SPDiv(%x / %x) = %x\n", fnum2
, fnum1
, Res
));