Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / mathieeesingbas / ieeespadd.c
blob52c112b7b11a7ca508ecedb039daf49ce1494522
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingbas_intern.h"
8 /*
9 FUNCTION
10 Calculate the sum of two IEEE single precision numbers
12 RESULT
13 sum of y and z
15 Flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : result is too large or too small for IEEESP format
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
29 INTERNALS
31 HISTORY
34 AROS_LH2(float, IEEESPAdd,
35 AROS_LHA(float, y, D0),
36 AROS_LHA(float, z, D1),
37 struct LibHeader *, MathIeeeSingBasBase, 11, Mathieeesingbas
40 AROS_LIBFUNC_INIT
42 LONG Res;
43 LONG Mant1, Mant2;
44 LONG Shift;
45 LONG Exponent;
47 SetSR(0, Zero_Bit | Overflow_Bit | Negative_Bit );
49 Shift = ((y & IEEESPExponent_Mask) -
50 (z & IEEESPExponent_Mask)) >> 23;
52 if (y != 0 && y != IEEESPSign_Mask )
54 Mant1 = (y & IEEESPMantisse_Mask) | 0x00800000;
56 else
58 Mant1 = 0;
61 if (z != 0 && z != IEEESPSign_Mask )
63 Mant2 = (z & IEEESPMantisse_Mask) | 0x00800000;
65 else
67 Mant2 = 0;
70 if (Shift > 0)
72 Mant2 >>= Shift;
73 Exponent = (y & IEEESPExponent_Mask);
75 else
77 Mant1 >>= (-Shift);
78 Exponent = (z & IEEESPExponent_Mask);
81 /* sign(fnum1) == sign(fnum2)
82 ** simple addition
83 ** 0.25 <= res < 1
85 if ( (z & IEEESPSign_Mask) - ( y & IEEESPSign_Mask) == 0)
87 Res = y & IEEESPSign_Mask;
88 Mant1 += Mant2;
89 if ( (Mant1 & 0x01000000) != 0)
91 Exponent += 0x00800000;
92 Mant1 >>= 1;
94 Mant1 &= IEEESPMantisse_Mask;
96 /* second case: sign(fnum1) != sign(fnum2)
97 ** -1 <= res < 1
99 else
101 if ( y < 0)
103 Mant1 = Mant2 - Mant1;
105 else /* fnum2 < 0 */
107 Mant1 = Mant1 - Mant2;
109 /*if the result is below zero */
110 if ( Mant1 < 0)
112 Res = IEEESPSign_Mask;
113 Mant1 =-Mant1;
114 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
116 else
118 Res = 0;
121 if (0 == Mant1)
123 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
124 return 0;
126 else
128 /* normalize the mantisse */
129 while ( (Mant1 & 0x00800000) == 0)
131 Mant1 += Mant1; /*one bit to the left. */
132 Exponent -= 0x00800000;
134 Mant1 &= IEEESPMantisse_Mask;
135 } /* else */
137 } /* else */
139 if ( Exponent < 0)
141 SetSR(Overflow_Bit, Zero_Bit | Overflow_Bit);
142 /* do NOT change Negative_Bit! */
143 return (Res | (IEEESPMantisse_Mask | IEEESPExponent_Mask));
146 Res |= Mant1 | Exponent;
147 return Res;
149 AROS_LIBFUNC_EXIT