2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 #include "mathffp_intern.h"
10 Divide two ffp numbers
16 negative : result is negative
17 overflow : result is out of range
24 The parameters are swapped !
31 Check if fnum2 == 0: result = 0;
32 Check if fnum1 == 0: result = overflow;
33 The further algorithm comes down to a pen & paper division
38 AROS_LH2(float, SPDiv
,
39 AROS_LHA(float, fnum1
, D1
),
40 AROS_LHA(float, fnum2
, D0
),
41 struct LibHeader
*, MathBase
, 14, Mathffp
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 */
106 Res
&= FFPMantisse_Mask
;
107 Res
|= (Exponent
& 0x7f);
108 Res
|= (fnum1
& FFPSign_Mask
) ^ (fnum2
& FFPSign_Mask
);
112 SetSR(Negative_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
115 if ((char) Exponent
< 0)
117 SetSR(Overflow_Bit
, Zero_Bit
| Overflow_Bit
| Negative_Bit
);
118 return(Res
| (FFPMantisse_Mask
| FFPExponent_Mask
));
121 kprintf("%x / %x =%x\n",fnum2
,fnum1
,Res
);