2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 #include "mathieeesingbas_intern.h"
10 Calculate the sum of two IEEE single precision numbers
17 negative : result is negative
18 overflow : result is too large or too small for IEEESP format
34 AROS_LH2(float, IEEESPAdd
,
35 AROS_LHA(float, y
, D0
),
36 AROS_LHA(float, z
, D1
),
37 struct LibHeader
*, MathIeeeSingBasBase
, 11, Mathieeesingbas
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;
61 if (z
!= 0 && z
!= IEEESPSign_Mask
)
63 Mant2
= (z
& IEEESPMantisse_Mask
) | 0x00800000;
73 Exponent
= (y
& IEEESPExponent_Mask
);
78 Exponent
= (z
& IEEESPExponent_Mask
);
81 /* sign(fnum1) == sign(fnum2)
85 if ( (z
& IEEESPSign_Mask
) - ( y
& IEEESPSign_Mask
) == 0)
87 Res
= y
& IEEESPSign_Mask
;
89 if ( (Mant1
& 0x01000000) != 0)
91 Exponent
+= 0x00800000;
94 Mant1
&= IEEESPMantisse_Mask
;
96 /* second case: sign(fnum1) != sign(fnum2)
103 Mant1
= Mant2
- Mant1
;
107 Mant1
= Mant1
- Mant2
;
109 /*if the result is below zero */
112 Res
= IEEESPSign_Mask
;
114 SetSR(Negative_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
123 SetSR(Zero_Bit
, Zero_Bit
| Negative_Bit
| Overflow_Bit
);
128 /* normalize the mantisse */
129 while ( (Mant1
& 0x00800000) == 0)
131 Mant1
+= Mant1
; /*one bit to the left. */
132 Exponent
-= 0x00800000;
134 Mant1
&= IEEESPMantisse_Mask
;
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
;