some fixes to accented characters
[tangerine.git] / rom / mathieeesingbas / ieeespdiv.c
blobd490b4760651371ea6905e1bd1f769da0e29fba6
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingbas_intern.h"
8 /*
9 FUNCTION
10 Divide two IEEE single precision floating point numbers
11 x = y / z;
13 RESULT
15 Flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : result is out of range
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
29 INTERNALS
30 ALGORITHM:<br/>
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 &amp; paper division.
34 HISTORY
37 AROS_LH2(float, IEEESPDiv,
38 AROS_LHA(float, y, D0),
39 AROS_LHA(float, z, D1),
40 struct LibHeader *, MathIeeeSingBasBase, 14, Mathieeesingbas
43 AROS_LIBFUNC_INIT
45 LONG Res = 0;
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 */
56 if (0 == z)
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 */
63 if (0 == y)
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)
73 Mant2 -= Mant1;
74 Res |= Bit_Mask;
76 while (Mant2 > 0)
78 Mant2 <<= 1;
79 Bit_Mask >>= 1;
82 while (Mant1 > 0)
84 Mant1 <<=1;
85 Bit_Mask <<=1;
87 } /* if */
88 else
90 Mant1 = (ULONG) Mant1 >> 1;
91 Bit_Mask >>= 1;
93 } /* while */
95 /* normalize the mantisse */
96 while (Res > 0)
98 Res += Res;
99 Exponent -=0x00800000;
102 if ((char) Res < 0) Res += 0x00000100;
103 Res >>= 8;
105 Res &= IEEESPMantisse_Mask;
106 Res |= Exponent;
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);
112 return Res;
114 AROS_LIBFUNC_EXIT