@@ -89,12 +89,12 @@ macro_rules! add {
89
89
if a_exponent. 0 == 0 {
90
90
let ( exponent, significand) = <$ty>:: normalize( a_significand. 0 ) ;
91
91
a_exponent = Wrapping ( exponent) ;
92
- a_significand = Wrapping ( significand) ;
92
+ a_significand = Wrapping ( significand) ;
93
93
}
94
94
if b_exponent. 0 == 0 {
95
95
let ( exponent, significand) = <$ty>:: normalize( b_significand. 0 ) ;
96
96
b_exponent = Wrapping ( exponent) ;
97
- b_significand = Wrapping ( significand) ;
97
+ b_significand = Wrapping ( significand) ;
98
98
}
99
99
100
100
// The sign of the result is the sign of the larger operand, a. If they
@@ -123,8 +123,8 @@ macro_rules! add {
123
123
if subtraction {
124
124
a_significand -= b_significand;
125
125
// If a == -b, return +zero.
126
- if a_significand. 0 == 0 {
127
- return ( <$ty as Float >:: from_repr( 0 ) ) ;
126
+ if a_significand. 0 == 0 {
127
+ return ( <$ty as Float >:: from_repr( 0 ) ) ;
128
128
}
129
129
130
130
// If partial cancellation occured, we need to left-shift the result
@@ -148,7 +148,7 @@ macro_rules! add {
148
148
}
149
149
150
150
// If we have overflowed the type, return +/- infinity:
151
- if a_exponent >= Wrapping ( max_exponent. 0 as i32 ) {
151
+ if a_exponent >= Wrapping ( max_exponent. 0 as i32 ) {
152
152
return ( <$ty>:: from_repr( ( inf_rep | result_sign) . 0 ) ) ;
153
153
}
154
154
@@ -198,117 +198,22 @@ pub extern fn __aeabi_fadd(a: f32, b: f32) -> f32 {
198
198
199
199
#[ cfg( test) ]
200
200
mod tests {
201
- use core:: { f32, f64} ;
202
- use qc:: { U32 , U64 } ;
203
201
use float:: Float ;
202
+ use qc:: { F32 , F64 } ;
204
203
205
- // NOTE The tests below have special handing for NaN values.
206
- // Because NaN != NaN, the floating-point representations must be used
207
- // Because there are many diffferent values of NaN, and the implementation
208
- // doesn't care about calculating the 'correct' one, if both values are NaN
209
- // the values are considered equivalent.
210
-
211
- // TODO: Add F32/F64 to qc so that they print the right values (at the very least)
212
204
quickcheck ! {
213
- fn addsf3( a: U32 , b: U32 ) -> bool {
214
- let ( a, b) = ( f32 :: from_repr ( a. 0 ) , f32 :: from_repr ( b. 0 ) ) ;
205
+ fn addsf3( a: F32 , b: F32 ) -> bool {
206
+ let ( a, b) = ( a. 0 , b. 0 ) ;
215
207
let x = super :: __addsf3( a, b) ;
216
208
let y = a + b;
217
209
x. eq_repr( y)
218
210
}
219
211
220
- fn adddf3( a: U64 , b: U64 ) -> bool {
221
- let ( a, b) = ( f64 :: from_repr ( a. 0 ) , f64 :: from_repr ( b. 0 ) ) ;
212
+ fn adddf3( a: F64 , b: F64 ) -> bool {
213
+ let ( a, b) = ( a. 0 , b. 0 ) ;
222
214
let x = super :: __adddf3( a, b) ;
223
215
let y = a + b;
224
216
x. eq_repr( y)
225
217
}
226
218
}
227
-
228
- // More tests for special float values
229
-
230
- #[ test]
231
- fn test_float_tiny_plus_tiny ( ) {
232
- let tiny = f32:: from_repr ( 1 ) ;
233
- let r = super :: __addsf3 ( tiny, tiny) ;
234
- assert ! ( r. eq_repr( tiny + tiny) ) ;
235
- }
236
-
237
- #[ test]
238
- fn test_double_tiny_plus_tiny ( ) {
239
- let tiny = f64:: from_repr ( 1 ) ;
240
- let r = super :: __adddf3 ( tiny, tiny) ;
241
- assert ! ( r. eq_repr( tiny + tiny) ) ;
242
- }
243
-
244
- #[ test]
245
- fn test_float_small_plus_small ( ) {
246
- let a = f32:: from_repr ( 327 ) ;
247
- let b = f32:: from_repr ( 256 ) ;
248
- let r = super :: __addsf3 ( a, b) ;
249
- assert ! ( r. eq_repr( a + b) ) ;
250
- }
251
-
252
- #[ test]
253
- fn test_double_small_plus_small ( ) {
254
- let a = f64:: from_repr ( 327 ) ;
255
- let b = f64:: from_repr ( 256 ) ;
256
- let r = super :: __adddf3 ( a, b) ;
257
- assert ! ( r. eq_repr( a + b) ) ;
258
- }
259
-
260
- #[ test]
261
- fn test_float_one_plus_one ( ) {
262
- let r = super :: __addsf3 ( 1f32 , 1f32 ) ;
263
- assert ! ( r. eq_repr( 1f32 + 1f32 ) ) ;
264
- }
265
-
266
- #[ test]
267
- fn test_double_one_plus_one ( ) {
268
- let r = super :: __adddf3 ( 1f64 , 1f64 ) ;
269
- assert ! ( r. eq_repr( 1f64 + 1f64 ) ) ;
270
- }
271
-
272
- #[ test]
273
- fn test_float_different_nan ( ) {
274
- let a = f32:: from_repr ( 1 ) ;
275
- let b = f32:: from_repr ( 0b11111111100100010001001010101010 ) ;
276
- let x = super :: __addsf3 ( a, b) ;
277
- let y = a + b;
278
- assert ! ( x. eq_repr( y) ) ;
279
- }
280
-
281
- #[ test]
282
- fn test_double_different_nan ( ) {
283
- let a = f64:: from_repr ( 1 ) ;
284
- let b = f64:: from_repr (
285
- 0b1111111111110010001000100101010101001000101010000110100011101011 ) ;
286
- let x = super :: __adddf3 ( a, b) ;
287
- let y = a + b;
288
- assert ! ( x. eq_repr( y) ) ;
289
- }
290
-
291
- #[ test]
292
- fn test_float_nan ( ) {
293
- let r = super :: __addsf3 ( f32:: NAN , 1.23 ) ;
294
- assert_eq ! ( r. repr( ) , f32 :: NAN . repr( ) ) ;
295
- }
296
-
297
- #[ test]
298
- fn test_double_nan ( ) {
299
- let r = super :: __adddf3 ( f64:: NAN , 1.23 ) ;
300
- assert_eq ! ( r. repr( ) , f64 :: NAN . repr( ) ) ;
301
- }
302
-
303
- #[ test]
304
- fn test_float_inf ( ) {
305
- let r = super :: __addsf3 ( f32:: INFINITY , -123.4 ) ;
306
- assert_eq ! ( r, f32 :: INFINITY ) ;
307
- }
308
-
309
- #[ test]
310
- fn test_double_inf ( ) {
311
- let r = super :: __adddf3 ( f64:: INFINITY , -123.4 ) ;
312
- assert_eq ! ( r, f64 :: INFINITY ) ;
313
- }
314
219
}
0 commit comments