]> git.lizzy.rs Git - rust.git/blob - src/librustc_apfloat/tests/ieee.rs
Auto merge of #59627 - LooMaclin:issue_57128_improve_miri_error_reporting_in_check_in...
[rust.git] / src / librustc_apfloat / tests / ieee.rs
1 // ignore-tidy-filelength
2
3 use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
4 use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status};
5 use rustc_apfloat::ieee::{Half, Single, Double, Quad, X87DoubleExtended};
6 use rustc_apfloat::unpack;
7
8 trait SingleExt {
9     fn from_f32(input: f32) -> Self;
10     fn to_f32(self) -> f32;
11 }
12
13 impl SingleExt for Single {
14     fn from_f32(input: f32) -> Self {
15         Self::from_bits(input.to_bits() as u128)
16     }
17
18     fn to_f32(self) -> f32 {
19         f32::from_bits(self.to_bits() as u32)
20     }
21 }
22
23 trait DoubleExt {
24     fn from_f64(input: f64) -> Self;
25     fn to_f64(self) -> f64;
26 }
27
28 impl DoubleExt for Double {
29     fn from_f64(input: f64) -> Self {
30         Self::from_bits(input.to_bits() as u128)
31     }
32
33     fn to_f64(self) -> f64 {
34         f64::from_bits(self.to_bits() as u64)
35     }
36 }
37
38 #[test]
39 fn is_signaling() {
40     // We test qNaN, -qNaN, +sNaN, -sNaN with and without payloads.
41     let payload = 4;
42     assert!(!Single::qnan(None).is_signaling());
43     assert!(!(-Single::qnan(None)).is_signaling());
44     assert!(!Single::qnan(Some(payload)).is_signaling());
45     assert!(!(-Single::qnan(Some(payload))).is_signaling());
46     assert!(Single::snan(None).is_signaling());
47     assert!((-Single::snan(None)).is_signaling());
48     assert!(Single::snan(Some(payload)).is_signaling());
49     assert!((-Single::snan(Some(payload))).is_signaling());
50 }
51
52 #[test]
53 fn next() {
54     // 1. Test Special Cases Values.
55     //
56     // Test all special values for nextUp and nextDown perscribed by IEEE-754R
57     // 2008. These are:
58     //   1. +inf
59     //   2. -inf
60     //   3. largest
61     //   4. -largest
62     //   5. smallest
63     //   6. -smallest
64     //   7. qNaN
65     //   8. sNaN
66     //   9. +0
67     //   10. -0
68
69     let mut status;
70
71     // nextUp(+inf) = +inf.
72     let test = unpack!(status=, Quad::INFINITY.next_up());
73     let expected = Quad::INFINITY;
74     assert_eq!(status, Status::OK);
75     assert!(test.is_infinite());
76     assert!(!test.is_negative());
77     assert!(test.bitwise_eq(expected));
78
79     // nextDown(+inf) = -nextUp(-inf) = -(-largest) = largest
80     let test = unpack!(status=, Quad::INFINITY.next_down());
81     let expected = Quad::largest();
82     assert_eq!(status, Status::OK);
83     assert!(!test.is_negative());
84     assert!(test.bitwise_eq(expected));
85
86     // nextUp(-inf) = -largest
87     let test = unpack!(status=, (-Quad::INFINITY).next_up());
88     let expected = -Quad::largest();
89     assert_eq!(status, Status::OK);
90     assert!(test.is_negative());
91     assert!(test.bitwise_eq(expected));
92
93     // nextDown(-inf) = -nextUp(+inf) = -(+inf) = -inf.
94     let test = unpack!(status=, (-Quad::INFINITY).next_down());
95     let expected = -Quad::INFINITY;
96     assert_eq!(status, Status::OK);
97     assert!(test.is_infinite() && test.is_negative());
98     assert!(test.bitwise_eq(expected));
99
100     // nextUp(largest) = +inf
101     let test = unpack!(status=, Quad::largest().next_up());
102     let expected = Quad::INFINITY;
103     assert_eq!(status, Status::OK);
104     assert!(test.is_infinite() && !test.is_negative());
105     assert!(test.bitwise_eq(expected));
106
107     // nextDown(largest) = -nextUp(-largest)
108     //                        = -(-largest + inc)
109     //                        = largest - inc.
110     let test = unpack!(status=, Quad::largest().next_down());
111     let expected = "0x1.fffffffffffffffffffffffffffep+16383"
112         .parse::<Quad>()
113         .unwrap();
114     assert_eq!(status, Status::OK);
115     assert!(!test.is_infinite() && !test.is_negative());
116     assert!(test.bitwise_eq(expected));
117
118     // nextUp(-largest) = -largest + inc.
119     let test = unpack!(status=, (-Quad::largest()).next_up());
120     let expected = "-0x1.fffffffffffffffffffffffffffep+16383"
121         .parse::<Quad>()
122         .unwrap();
123     assert_eq!(status, Status::OK);
124     assert!(test.bitwise_eq(expected));
125
126     // nextDown(-largest) = -nextUp(largest) = -(inf) = -inf.
127     let test = unpack!(status=, (-Quad::largest()).next_down());
128     let expected = -Quad::INFINITY;
129     assert_eq!(status, Status::OK);
130     assert!(test.is_infinite() && test.is_negative());
131     assert!(test.bitwise_eq(expected));
132
133     // nextUp(smallest) = smallest + inc.
134     let test = unpack!(status=, "0x0.0000000000000000000000000001p-16382"
135         .parse::<Quad>()
136         .unwrap()
137         .next_up());
138     let expected = "0x0.0000000000000000000000000002p-16382"
139         .parse::<Quad>()
140         .unwrap();
141     assert_eq!(status, Status::OK);
142     assert!(test.bitwise_eq(expected));
143
144     // nextDown(smallest) = -nextUp(-smallest) = -(-0) = +0.
145     let test = unpack!(status=, "0x0.0000000000000000000000000001p-16382"
146         .parse::<Quad>()
147         .unwrap()
148         .next_down());
149     let expected = Quad::ZERO;
150     assert_eq!(status, Status::OK);
151     assert!(test.is_pos_zero());
152     assert!(test.bitwise_eq(expected));
153
154     // nextUp(-smallest) = -0.
155     let test = unpack!(status=, "-0x0.0000000000000000000000000001p-16382"
156         .parse::<Quad>()
157         .unwrap()
158         .next_up());
159     let expected = -Quad::ZERO;
160     assert_eq!(status, Status::OK);
161     assert!(test.is_neg_zero());
162     assert!(test.bitwise_eq(expected));
163
164     // nextDown(-smallest) = -nextUp(smallest) = -smallest - inc.
165     let test = unpack!(status=, "-0x0.0000000000000000000000000001p-16382"
166         .parse::<Quad>()
167         .unwrap()
168         .next_down());
169     let expected = "-0x0.0000000000000000000000000002p-16382"
170         .parse::<Quad>()
171         .unwrap();
172     assert_eq!(status, Status::OK);
173     assert!(test.bitwise_eq(expected));
174
175     // nextUp(qNaN) = qNaN
176     let test = unpack!(status=, Quad::qnan(None).next_up());
177     let expected = Quad::qnan(None);
178     assert_eq!(status, Status::OK);
179     assert!(test.bitwise_eq(expected));
180
181     // nextDown(qNaN) = qNaN
182     let test = unpack!(status=, Quad::qnan(None).next_down());
183     let expected = Quad::qnan(None);
184     assert_eq!(status, Status::OK);
185     assert!(test.bitwise_eq(expected));
186
187     // nextUp(sNaN) = qNaN
188     let test = unpack!(status=, Quad::snan(None).next_up());
189     let expected = Quad::qnan(None);
190     assert_eq!(status, Status::INVALID_OP);
191     assert!(test.bitwise_eq(expected));
192
193     // nextDown(sNaN) = qNaN
194     let test = unpack!(status=, Quad::snan(None).next_down());
195     let expected = Quad::qnan(None);
196     assert_eq!(status, Status::INVALID_OP);
197     assert!(test.bitwise_eq(expected));
198
199     // nextUp(+0) = +smallest
200     let test = unpack!(status=, Quad::ZERO.next_up());
201     let expected = Quad::SMALLEST;
202     assert_eq!(status, Status::OK);
203     assert!(test.bitwise_eq(expected));
204
205     // nextDown(+0) = -nextUp(-0) = -smallest
206     let test = unpack!(status=, Quad::ZERO.next_down());
207     let expected = -Quad::SMALLEST;
208     assert_eq!(status, Status::OK);
209     assert!(test.bitwise_eq(expected));
210
211     // nextUp(-0) = +smallest
212     let test = unpack!(status=, (-Quad::ZERO).next_up());
213     let expected = Quad::SMALLEST;
214     assert_eq!(status, Status::OK);
215     assert!(test.bitwise_eq(expected));
216
217     // nextDown(-0) = -nextUp(0) = -smallest
218     let test = unpack!(status=, (-Quad::ZERO).next_down());
219     let expected = -Quad::SMALLEST;
220     assert_eq!(status, Status::OK);
221     assert!(test.bitwise_eq(expected));
222
223     // 2. Binade Boundary Tests.
224
225     // 2a. Test denormal <-> normal binade boundaries.
226     //     * nextUp(+Largest Denormal) -> +Smallest Normal.
227     //     * nextDown(-Largest Denormal) -> -Smallest Normal.
228     //     * nextUp(-Smallest Normal) -> -Largest Denormal.
229     //     * nextDown(+Smallest Normal) -> +Largest Denormal.
230
231     // nextUp(+Largest Denormal) -> +Smallest Normal.
232     let test = unpack!(status=, "0x0.ffffffffffffffffffffffffffffp-16382"
233         .parse::<Quad>()
234         .unwrap()
235         .next_up());
236     let expected = "0x1.0000000000000000000000000000p-16382"
237         .parse::<Quad>()
238         .unwrap();
239     assert_eq!(status, Status::OK);
240     assert!(!test.is_denormal());
241     assert!(test.bitwise_eq(expected));
242
243     // nextDown(-Largest Denormal) -> -Smallest Normal.
244     let test = unpack!(status=, "-0x0.ffffffffffffffffffffffffffffp-16382"
245         .parse::<Quad>()
246         .unwrap()
247         .next_down());
248     let expected = "-0x1.0000000000000000000000000000p-16382"
249         .parse::<Quad>()
250         .unwrap();
251     assert_eq!(status, Status::OK);
252     assert!(!test.is_denormal());
253     assert!(test.bitwise_eq(expected));
254
255     // nextUp(-Smallest Normal) -> -Largest Denormal.
256     let test = unpack!(status=, "-0x1.0000000000000000000000000000p-16382"
257         .parse::<Quad>()
258         .unwrap()
259         .next_up());
260     let expected = "-0x0.ffffffffffffffffffffffffffffp-16382"
261         .parse::<Quad>()
262         .unwrap();
263     assert_eq!(status, Status::OK);
264     assert!(test.is_denormal());
265     assert!(test.bitwise_eq(expected));
266
267     // nextDown(+Smallest Normal) -> +Largest Denormal.
268     let test = unpack!(status=, "+0x1.0000000000000000000000000000p-16382"
269         .parse::<Quad>()
270         .unwrap()
271         .next_down());
272     let expected = "+0x0.ffffffffffffffffffffffffffffp-16382"
273         .parse::<Quad>()
274         .unwrap();
275     assert_eq!(status, Status::OK);
276     assert!(test.is_denormal());
277     assert!(test.bitwise_eq(expected));
278
279     // 2b. Test normal <-> normal binade boundaries.
280     //     * nextUp(-Normal Binade Boundary) -> -Normal Binade Boundary + 1.
281     //     * nextDown(+Normal Binade Boundary) -> +Normal Binade Boundary - 1.
282     //     * nextUp(+Normal Binade Boundary - 1) -> +Normal Binade Boundary.
283     //     * nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
284
285     // nextUp(-Normal Binade Boundary) -> -Normal Binade Boundary + 1.
286     let test = unpack!(status=, "-0x1p+1".parse::<Quad>().unwrap().next_up());
287     let expected = "-0x1.ffffffffffffffffffffffffffffp+0"
288         .parse::<Quad>()
289         .unwrap();
290     assert_eq!(status, Status::OK);
291     assert!(test.bitwise_eq(expected));
292
293     // nextDown(+Normal Binade Boundary) -> +Normal Binade Boundary - 1.
294     let test = unpack!(status=, "0x1p+1".parse::<Quad>().unwrap().next_down());
295     let expected = "0x1.ffffffffffffffffffffffffffffp+0"
296         .parse::<Quad>()
297         .unwrap();
298     assert_eq!(status, Status::OK);
299     assert!(test.bitwise_eq(expected));
300
301     // nextUp(+Normal Binade Boundary - 1) -> +Normal Binade Boundary.
302     let test = unpack!(status=, "0x1.ffffffffffffffffffffffffffffp+0"
303         .parse::<Quad>()
304         .unwrap()
305         .next_up());
306     let expected = "0x1p+1".parse::<Quad>().unwrap();
307     assert_eq!(status, Status::OK);
308     assert!(test.bitwise_eq(expected));
309
310     // nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
311     let test = unpack!(status=, "-0x1.ffffffffffffffffffffffffffffp+0"
312         .parse::<Quad>()
313         .unwrap()
314         .next_down());
315     let expected = "-0x1p+1".parse::<Quad>().unwrap();
316     assert_eq!(status, Status::OK);
317     assert!(test.bitwise_eq(expected));
318
319     // 2c. Test using next at binade boundaries with a direction away from the
320     // binade boundary. Away from denormal <-> normal boundaries.
321     //
322     // This is to make sure that even though we are at a binade boundary, since
323     // we are rounding away, we do not trigger the binade boundary code. Thus we
324     // test:
325     //   * nextUp(-Largest Denormal) -> -Largest Denormal + inc.
326     //   * nextDown(+Largest Denormal) -> +Largest Denormal - inc.
327     //   * nextUp(+Smallest Normal) -> +Smallest Normal + inc.
328     //   * nextDown(-Smallest Normal) -> -Smallest Normal - inc.
329
330     // nextUp(-Largest Denormal) -> -Largest Denormal + inc.
331     let test = unpack!(status=, "-0x0.ffffffffffffffffffffffffffffp-16382"
332         .parse::<Quad>()
333         .unwrap()
334         .next_up());
335     let expected = "-0x0.fffffffffffffffffffffffffffep-16382"
336         .parse::<Quad>()
337         .unwrap();
338     assert_eq!(status, Status::OK);
339     assert!(test.is_denormal());
340     assert!(test.is_negative());
341     assert!(test.bitwise_eq(expected));
342
343     // nextDown(+Largest Denormal) -> +Largest Denormal - inc.
344     let test = unpack!(status=, "0x0.ffffffffffffffffffffffffffffp-16382"
345         .parse::<Quad>()
346         .unwrap()
347         .next_down());
348     let expected = "0x0.fffffffffffffffffffffffffffep-16382"
349         .parse::<Quad>()
350         .unwrap();
351     assert_eq!(status, Status::OK);
352     assert!(test.is_denormal());
353     assert!(!test.is_negative());
354     assert!(test.bitwise_eq(expected));
355
356     // nextUp(+Smallest Normal) -> +Smallest Normal + inc.
357     let test = unpack!(status=, "0x1.0000000000000000000000000000p-16382"
358         .parse::<Quad>()
359         .unwrap()
360         .next_up());
361     let expected = "0x1.0000000000000000000000000001p-16382"
362         .parse::<Quad>()
363         .unwrap();
364     assert_eq!(status, Status::OK);
365     assert!(!test.is_denormal());
366     assert!(!test.is_negative());
367     assert!(test.bitwise_eq(expected));
368
369     // nextDown(-Smallest Normal) -> -Smallest Normal - inc.
370     let test = unpack!(status=, "-0x1.0000000000000000000000000000p-16382"
371         .parse::<Quad>()
372         .unwrap()
373         .next_down());
374     let expected = "-0x1.0000000000000000000000000001p-16382"
375         .parse::<Quad>()
376         .unwrap();
377     assert_eq!(status, Status::OK);
378     assert!(!test.is_denormal());
379     assert!(test.is_negative());
380     assert!(test.bitwise_eq(expected));
381
382     // 2d. Test values which cause our exponent to go to min exponent. This
383     // is to ensure that guards in the code to check for min exponent
384     // trigger properly.
385     //     * nextUp(-0x1p-16381) -> -0x1.ffffffffffffffffffffffffffffp-16382
386     //     * nextDown(-0x1.ffffffffffffffffffffffffffffp-16382) ->
387     //         -0x1p-16381
388     //     * nextUp(0x1.ffffffffffffffffffffffffffffp-16382) -> 0x1p-16382
389     //     * nextDown(0x1p-16382) -> 0x1.ffffffffffffffffffffffffffffp-16382
390
391     // nextUp(-0x1p-16381) -> -0x1.ffffffffffffffffffffffffffffp-16382
392     let test = unpack!(status=, "-0x1p-16381".parse::<Quad>().unwrap().next_up());
393     let expected = "-0x1.ffffffffffffffffffffffffffffp-16382"
394         .parse::<Quad>()
395         .unwrap();
396     assert_eq!(status, Status::OK);
397     assert!(test.bitwise_eq(expected));
398
399     // nextDown(-0x1.ffffffffffffffffffffffffffffp-16382) ->
400     //         -0x1p-16381
401     let test = unpack!(status=, "-0x1.ffffffffffffffffffffffffffffp-16382"
402         .parse::<Quad>()
403         .unwrap()
404         .next_down());
405     let expected = "-0x1p-16381".parse::<Quad>().unwrap();
406     assert_eq!(status, Status::OK);
407     assert!(test.bitwise_eq(expected));
408
409     // nextUp(0x1.ffffffffffffffffffffffffffffp-16382) -> 0x1p-16381
410     let test = unpack!(status=, "0x1.ffffffffffffffffffffffffffffp-16382"
411         .parse::<Quad>()
412         .unwrap()
413         .next_up());
414     let expected = "0x1p-16381".parse::<Quad>().unwrap();
415     assert_eq!(status, Status::OK);
416     assert!(test.bitwise_eq(expected));
417
418     // nextDown(0x1p-16381) -> 0x1.ffffffffffffffffffffffffffffp-16382
419     let test = unpack!(status=, "0x1p-16381".parse::<Quad>().unwrap().next_down());
420     let expected = "0x1.ffffffffffffffffffffffffffffp-16382"
421         .parse::<Quad>()
422         .unwrap();
423     assert_eq!(status, Status::OK);
424     assert!(test.bitwise_eq(expected));
425
426     // 3. Now we test both denormal/normal computation which will not cause us
427     // to go across binade boundaries. Specifically we test:
428     //   * nextUp(+Denormal) -> +Denormal.
429     //   * nextDown(+Denormal) -> +Denormal.
430     //   * nextUp(-Denormal) -> -Denormal.
431     //   * nextDown(-Denormal) -> -Denormal.
432     //   * nextUp(+Normal) -> +Normal.
433     //   * nextDown(+Normal) -> +Normal.
434     //   * nextUp(-Normal) -> -Normal.
435     //   * nextDown(-Normal) -> -Normal.
436
437     // nextUp(+Denormal) -> +Denormal.
438     let test = unpack!(status=, "0x0.ffffffffffffffffffffffff000cp-16382"
439         .parse::<Quad>()
440         .unwrap()
441         .next_up());
442     let expected = "0x0.ffffffffffffffffffffffff000dp-16382"
443         .parse::<Quad>()
444         .unwrap();
445     assert_eq!(status, Status::OK);
446     assert!(test.is_denormal());
447     assert!(!test.is_negative());
448     assert!(test.bitwise_eq(expected));
449
450     // nextDown(+Denormal) -> +Denormal.
451     let test = unpack!(status=, "0x0.ffffffffffffffffffffffff000cp-16382"
452         .parse::<Quad>()
453         .unwrap()
454         .next_down());
455     let expected = "0x0.ffffffffffffffffffffffff000bp-16382"
456         .parse::<Quad>()
457         .unwrap();
458     assert_eq!(status, Status::OK);
459     assert!(test.is_denormal());
460     assert!(!test.is_negative());
461     assert!(test.bitwise_eq(expected));
462
463     // nextUp(-Denormal) -> -Denormal.
464     let test = unpack!(status=, "-0x0.ffffffffffffffffffffffff000cp-16382"
465         .parse::<Quad>()
466         .unwrap()
467         .next_up());
468     let expected = "-0x0.ffffffffffffffffffffffff000bp-16382"
469         .parse::<Quad>()
470         .unwrap();
471     assert_eq!(status, Status::OK);
472     assert!(test.is_denormal());
473     assert!(test.is_negative());
474     assert!(test.bitwise_eq(expected));
475
476     // nextDown(-Denormal) -> -Denormal
477     let test = unpack!(status=, "-0x0.ffffffffffffffffffffffff000cp-16382"
478         .parse::<Quad>()
479         .unwrap()
480         .next_down());
481     let expected = "-0x0.ffffffffffffffffffffffff000dp-16382"
482         .parse::<Quad>()
483         .unwrap();
484     assert_eq!(status, Status::OK);
485     assert!(test.is_denormal());
486     assert!(test.is_negative());
487     assert!(test.bitwise_eq(expected));
488
489     // nextUp(+Normal) -> +Normal.
490     let test = unpack!(status=, "0x1.ffffffffffffffffffffffff000cp-16000"
491         .parse::<Quad>()
492         .unwrap()
493         .next_up());
494     let expected = "0x1.ffffffffffffffffffffffff000dp-16000"
495         .parse::<Quad>()
496         .unwrap();
497     assert_eq!(status, Status::OK);
498     assert!(!test.is_denormal());
499     assert!(!test.is_negative());
500     assert!(test.bitwise_eq(expected));
501
502     // nextDown(+Normal) -> +Normal.
503     let test = unpack!(status=, "0x1.ffffffffffffffffffffffff000cp-16000"
504         .parse::<Quad>()
505         .unwrap()
506         .next_down());
507     let expected = "0x1.ffffffffffffffffffffffff000bp-16000"
508         .parse::<Quad>()
509         .unwrap();
510     assert_eq!(status, Status::OK);
511     assert!(!test.is_denormal());
512     assert!(!test.is_negative());
513     assert!(test.bitwise_eq(expected));
514
515     // nextUp(-Normal) -> -Normal.
516     let test = unpack!(status=, "-0x1.ffffffffffffffffffffffff000cp-16000"
517         .parse::<Quad>()
518         .unwrap()
519         .next_up());
520     let expected = "-0x1.ffffffffffffffffffffffff000bp-16000"
521         .parse::<Quad>()
522         .unwrap();
523     assert_eq!(status, Status::OK);
524     assert!(!test.is_denormal());
525     assert!(test.is_negative());
526     assert!(test.bitwise_eq(expected));
527
528     // nextDown(-Normal) -> -Normal.
529     let test = unpack!(status=, "-0x1.ffffffffffffffffffffffff000cp-16000"
530         .parse::<Quad>()
531         .unwrap()
532         .next_down());
533     let expected = "-0x1.ffffffffffffffffffffffff000dp-16000"
534         .parse::<Quad>()
535         .unwrap();
536     assert_eq!(status, Status::OK);
537     assert!(!test.is_denormal());
538     assert!(test.is_negative());
539     assert!(test.bitwise_eq(expected));
540 }
541
542 #[test]
543 fn fma() {
544     {
545         let mut f1 = Single::from_f32(14.5);
546         let f2 = Single::from_f32(-14.5);
547         let f3 = Single::from_f32(225.0);
548         f1 = f1.mul_add(f2, f3).value;
549         assert_eq!(14.75, f1.to_f32());
550     }
551
552     {
553         let val2 = Single::from_f32(2.0);
554         let mut f1 = Single::from_f32(1.17549435e-38);
555         let mut f2 = Single::from_f32(1.17549435e-38);
556         f1 /= val2;
557         f2 /= val2;
558         let f3 = Single::from_f32(12.0);
559         f1 = f1.mul_add(f2, f3).value;
560         assert_eq!(12.0, f1.to_f32());
561     }
562
563     // Test for correct zero sign when answer is exactly zero.
564     // fma(1.0, -1.0, 1.0) -> +ve 0.
565     {
566         let mut f1 = Double::from_f64(1.0);
567         let f2 = Double::from_f64(-1.0);
568         let f3 = Double::from_f64(1.0);
569         f1 = f1.mul_add(f2, f3).value;
570         assert!(!f1.is_negative() && f1.is_zero());
571     }
572
573     // Test for correct zero sign when answer is exactly zero and rounding towards
574     // negative.
575     // fma(1.0, -1.0, 1.0) -> +ve 0.
576     {
577         let mut f1 = Double::from_f64(1.0);
578         let f2 = Double::from_f64(-1.0);
579         let f3 = Double::from_f64(1.0);
580         f1 = f1.mul_add_r(f2, f3, Round::TowardNegative).value;
581         assert!(f1.is_negative() && f1.is_zero());
582     }
583
584     // Test for correct (in this case -ve) sign when adding like signed zeros.
585     // Test fma(0.0, -0.0, -0.0) -> -ve 0.
586     {
587         let mut f1 = Double::from_f64(0.0);
588         let f2 = Double::from_f64(-0.0);
589         let f3 = Double::from_f64(-0.0);
590         f1 = f1.mul_add(f2, f3).value;
591         assert!(f1.is_negative() && f1.is_zero());
592     }
593
594     // Test -ve sign preservation when small negative results underflow.
595     {
596         let mut f1 = "-0x1p-1074".parse::<Double>().unwrap();
597         let f2 = "+0x1p-1074".parse::<Double>().unwrap();
598         let f3 = Double::from_f64(0.0);
599         f1 = f1.mul_add(f2, f3).value;
600         assert!(f1.is_negative() && f1.is_zero());
601     }
602
603     // Test x87 extended precision case from http://llvm.org/PR20728.
604     {
605         let mut m1 = X87DoubleExtended::from_u128(1).value;
606         let m2 = X87DoubleExtended::from_u128(1).value;
607         let a = X87DoubleExtended::from_u128(3).value;
608
609         let mut loses_info = false;
610         m1 = m1.mul_add(m2, a).value;
611         let r: Single = m1.convert(&mut loses_info).value;
612         assert!(!loses_info);
613         assert_eq!(4.0, r.to_f32());
614     }
615 }
616
617 #[test]
618 fn min_num() {
619     let f1 = Double::from_f64(1.0);
620     let f2 = Double::from_f64(2.0);
621     let nan = Double::NAN;
622
623     assert_eq!(1.0, f1.min(f2).to_f64());
624     assert_eq!(1.0, f2.min(f1).to_f64());
625     assert_eq!(1.0, f1.min(nan).to_f64());
626     assert_eq!(1.0, nan.min(f1).to_f64());
627 }
628
629 #[test]
630 fn max_num() {
631     let f1 = Double::from_f64(1.0);
632     let f2 = Double::from_f64(2.0);
633     let nan = Double::NAN;
634
635     assert_eq!(2.0, f1.max(f2).to_f64());
636     assert_eq!(2.0, f2.max(f1).to_f64());
637     assert_eq!(1.0, f1.max(nan).to_f64());
638     assert_eq!(1.0, nan.max(f1).to_f64());
639 }
640
641 #[test]
642 fn denormal() {
643     // Test single precision
644     {
645         assert!(!Single::from_f32(0.0).is_denormal());
646
647         let mut t = "1.17549435082228750797e-38".parse::<Single>().unwrap();
648         assert!(!t.is_denormal());
649
650         let val2 = Single::from_f32(2.0e0);
651         t /= val2;
652         assert!(t.is_denormal());
653     }
654
655     // Test double precision
656     {
657         assert!(!Double::from_f64(0.0).is_denormal());
658
659         let mut t = "2.22507385850720138309e-308".parse::<Double>().unwrap();
660         assert!(!t.is_denormal());
661
662         let val2 = Double::from_f64(2.0e0);
663         t /= val2;
664         assert!(t.is_denormal());
665     }
666
667     // Test Intel double-ext
668     {
669         assert!(!X87DoubleExtended::from_u128(0).value.is_denormal());
670
671         let mut t = "3.36210314311209350626e-4932"
672             .parse::<X87DoubleExtended>()
673             .unwrap();
674         assert!(!t.is_denormal());
675
676         t /= X87DoubleExtended::from_u128(2).value;
677         assert!(t.is_denormal());
678     }
679
680     // Test quadruple precision
681     {
682         assert!(!Quad::from_u128(0).value.is_denormal());
683
684         let mut t = "3.36210314311209350626267781732175260e-4932"
685             .parse::<Quad>()
686             .unwrap();
687         assert!(!t.is_denormal());
688
689         t /= Quad::from_u128(2).value;
690         assert!(t.is_denormal());
691     }
692 }
693
694 #[test]
695 fn decimal_strings_without_null_terminators() {
696     // Make sure that we can parse strings without null terminators.
697     // rdar://14323230.
698     let val = "0.00"[..3].parse::<Double>().unwrap();
699     assert_eq!(val.to_f64(), 0.0);
700     let val = "0.01"[..3].parse::<Double>().unwrap();
701     assert_eq!(val.to_f64(), 0.0);
702     let val = "0.09"[..3].parse::<Double>().unwrap();
703     assert_eq!(val.to_f64(), 0.0);
704     let val = "0.095"[..4].parse::<Double>().unwrap();
705     assert_eq!(val.to_f64(), 0.09);
706     let val = "0.00e+3"[..7].parse::<Double>().unwrap();
707     assert_eq!(val.to_f64(), 0.00);
708     let val = "0e+3"[..4].parse::<Double>().unwrap();
709     assert_eq!(val.to_f64(), 0.00);
710
711 }
712
713 #[test]
714 fn from_zero_decimal_string() {
715     assert_eq!(0.0, "0".parse::<Double>().unwrap().to_f64());
716     assert_eq!(0.0, "+0".parse::<Double>().unwrap().to_f64());
717     assert_eq!(-0.0, "-0".parse::<Double>().unwrap().to_f64());
718
719     assert_eq!(0.0, "0.".parse::<Double>().unwrap().to_f64());
720     assert_eq!(0.0, "+0.".parse::<Double>().unwrap().to_f64());
721     assert_eq!(-0.0, "-0.".parse::<Double>().unwrap().to_f64());
722
723     assert_eq!(0.0, ".0".parse::<Double>().unwrap().to_f64());
724     assert_eq!(0.0, "+.0".parse::<Double>().unwrap().to_f64());
725     assert_eq!(-0.0, "-.0".parse::<Double>().unwrap().to_f64());
726
727     assert_eq!(0.0, "0.0".parse::<Double>().unwrap().to_f64());
728     assert_eq!(0.0, "+0.0".parse::<Double>().unwrap().to_f64());
729     assert_eq!(-0.0, "-0.0".parse::<Double>().unwrap().to_f64());
730
731     assert_eq!(0.0, "00000.".parse::<Double>().unwrap().to_f64());
732     assert_eq!(0.0, "+00000.".parse::<Double>().unwrap().to_f64());
733     assert_eq!(-0.0, "-00000.".parse::<Double>().unwrap().to_f64());
734
735     assert_eq!(0.0, ".00000".parse::<Double>().unwrap().to_f64());
736     assert_eq!(0.0, "+.00000".parse::<Double>().unwrap().to_f64());
737     assert_eq!(-0.0, "-.00000".parse::<Double>().unwrap().to_f64());
738
739     assert_eq!(0.0, "0000.00000".parse::<Double>().unwrap().to_f64());
740     assert_eq!(0.0, "+0000.00000".parse::<Double>().unwrap().to_f64());
741     assert_eq!(-0.0, "-0000.00000".parse::<Double>().unwrap().to_f64());
742 }
743
744 #[test]
745 fn from_zero_decimal_single_exponent_string() {
746     assert_eq!(0.0, "0e1".parse::<Double>().unwrap().to_f64());
747     assert_eq!(0.0, "+0e1".parse::<Double>().unwrap().to_f64());
748     assert_eq!(-0.0, "-0e1".parse::<Double>().unwrap().to_f64());
749
750     assert_eq!(0.0, "0e+1".parse::<Double>().unwrap().to_f64());
751     assert_eq!(0.0, "+0e+1".parse::<Double>().unwrap().to_f64());
752     assert_eq!(-0.0, "-0e+1".parse::<Double>().unwrap().to_f64());
753
754     assert_eq!(0.0, "0e-1".parse::<Double>().unwrap().to_f64());
755     assert_eq!(0.0, "+0e-1".parse::<Double>().unwrap().to_f64());
756     assert_eq!(-0.0, "-0e-1".parse::<Double>().unwrap().to_f64());
757
758
759     assert_eq!(0.0, "0.e1".parse::<Double>().unwrap().to_f64());
760     assert_eq!(0.0, "+0.e1".parse::<Double>().unwrap().to_f64());
761     assert_eq!(-0.0, "-0.e1".parse::<Double>().unwrap().to_f64());
762
763     assert_eq!(0.0, "0.e+1".parse::<Double>().unwrap().to_f64());
764     assert_eq!(0.0, "+0.e+1".parse::<Double>().unwrap().to_f64());
765     assert_eq!(-0.0, "-0.e+1".parse::<Double>().unwrap().to_f64());
766
767     assert_eq!(0.0, "0.e-1".parse::<Double>().unwrap().to_f64());
768     assert_eq!(0.0, "+0.e-1".parse::<Double>().unwrap().to_f64());
769     assert_eq!(-0.0, "-0.e-1".parse::<Double>().unwrap().to_f64());
770
771     assert_eq!(0.0, ".0e1".parse::<Double>().unwrap().to_f64());
772     assert_eq!(0.0, "+.0e1".parse::<Double>().unwrap().to_f64());
773     assert_eq!(-0.0, "-.0e1".parse::<Double>().unwrap().to_f64());
774
775     assert_eq!(0.0, ".0e+1".parse::<Double>().unwrap().to_f64());
776     assert_eq!(0.0, "+.0e+1".parse::<Double>().unwrap().to_f64());
777     assert_eq!(-0.0, "-.0e+1".parse::<Double>().unwrap().to_f64());
778
779     assert_eq!(0.0, ".0e-1".parse::<Double>().unwrap().to_f64());
780     assert_eq!(0.0, "+.0e-1".parse::<Double>().unwrap().to_f64());
781     assert_eq!(-0.0, "-.0e-1".parse::<Double>().unwrap().to_f64());
782
783
784     assert_eq!(0.0, "0.0e1".parse::<Double>().unwrap().to_f64());
785     assert_eq!(0.0, "+0.0e1".parse::<Double>().unwrap().to_f64());
786     assert_eq!(-0.0, "-0.0e1".parse::<Double>().unwrap().to_f64());
787
788     assert_eq!(0.0, "0.0e+1".parse::<Double>().unwrap().to_f64());
789     assert_eq!(0.0, "+0.0e+1".parse::<Double>().unwrap().to_f64());
790     assert_eq!(-0.0, "-0.0e+1".parse::<Double>().unwrap().to_f64());
791
792     assert_eq!(0.0, "0.0e-1".parse::<Double>().unwrap().to_f64());
793     assert_eq!(0.0, "+0.0e-1".parse::<Double>().unwrap().to_f64());
794     assert_eq!(-0.0, "-0.0e-1".parse::<Double>().unwrap().to_f64());
795
796
797     assert_eq!(0.0, "000.0000e1".parse::<Double>().unwrap().to_f64());
798     assert_eq!(0.0, "+000.0000e+1".parse::<Double>().unwrap().to_f64());
799     assert_eq!(-0.0, "-000.0000e+1".parse::<Double>().unwrap().to_f64());
800 }
801
802 #[test]
803 fn from_zero_decimal_large_exponent_string() {
804     assert_eq!(0.0, "0e1234".parse::<Double>().unwrap().to_f64());
805     assert_eq!(0.0, "+0e1234".parse::<Double>().unwrap().to_f64());
806     assert_eq!(-0.0, "-0e1234".parse::<Double>().unwrap().to_f64());
807
808     assert_eq!(0.0, "0e+1234".parse::<Double>().unwrap().to_f64());
809     assert_eq!(0.0, "+0e+1234".parse::<Double>().unwrap().to_f64());
810     assert_eq!(-0.0, "-0e+1234".parse::<Double>().unwrap().to_f64());
811
812     assert_eq!(0.0, "0e-1234".parse::<Double>().unwrap().to_f64());
813     assert_eq!(0.0, "+0e-1234".parse::<Double>().unwrap().to_f64());
814     assert_eq!(-0.0, "-0e-1234".parse::<Double>().unwrap().to_f64());
815
816     assert_eq!(0.0, "000.0000e1234".parse::<Double>().unwrap().to_f64());
817     assert_eq!(0.0, "000.0000e-1234".parse::<Double>().unwrap().to_f64());
818 }
819
820 #[test]
821 fn from_zero_hexadecimal_string() {
822     assert_eq!(0.0, "0x0p1".parse::<Double>().unwrap().to_f64());
823     assert_eq!(0.0, "+0x0p1".parse::<Double>().unwrap().to_f64());
824     assert_eq!(-0.0, "-0x0p1".parse::<Double>().unwrap().to_f64());
825
826     assert_eq!(0.0, "0x0p+1".parse::<Double>().unwrap().to_f64());
827     assert_eq!(0.0, "+0x0p+1".parse::<Double>().unwrap().to_f64());
828     assert_eq!(-0.0, "-0x0p+1".parse::<Double>().unwrap().to_f64());
829
830     assert_eq!(0.0, "0x0p-1".parse::<Double>().unwrap().to_f64());
831     assert_eq!(0.0, "+0x0p-1".parse::<Double>().unwrap().to_f64());
832     assert_eq!(-0.0, "-0x0p-1".parse::<Double>().unwrap().to_f64());
833
834
835     assert_eq!(0.0, "0x0.p1".parse::<Double>().unwrap().to_f64());
836     assert_eq!(0.0, "+0x0.p1".parse::<Double>().unwrap().to_f64());
837     assert_eq!(-0.0, "-0x0.p1".parse::<Double>().unwrap().to_f64());
838
839     assert_eq!(0.0, "0x0.p+1".parse::<Double>().unwrap().to_f64());
840     assert_eq!(0.0, "+0x0.p+1".parse::<Double>().unwrap().to_f64());
841     assert_eq!(-0.0, "-0x0.p+1".parse::<Double>().unwrap().to_f64());
842
843     assert_eq!(0.0, "0x0.p-1".parse::<Double>().unwrap().to_f64());
844     assert_eq!(0.0, "+0x0.p-1".parse::<Double>().unwrap().to_f64());
845     assert_eq!(-0.0, "-0x0.p-1".parse::<Double>().unwrap().to_f64());
846
847
848     assert_eq!(0.0, "0x.0p1".parse::<Double>().unwrap().to_f64());
849     assert_eq!(0.0, "+0x.0p1".parse::<Double>().unwrap().to_f64());
850     assert_eq!(-0.0, "-0x.0p1".parse::<Double>().unwrap().to_f64());
851
852     assert_eq!(0.0, "0x.0p+1".parse::<Double>().unwrap().to_f64());
853     assert_eq!(0.0, "+0x.0p+1".parse::<Double>().unwrap().to_f64());
854     assert_eq!(-0.0, "-0x.0p+1".parse::<Double>().unwrap().to_f64());
855
856     assert_eq!(0.0, "0x.0p-1".parse::<Double>().unwrap().to_f64());
857     assert_eq!(0.0, "+0x.0p-1".parse::<Double>().unwrap().to_f64());
858     assert_eq!(-0.0, "-0x.0p-1".parse::<Double>().unwrap().to_f64());
859
860
861     assert_eq!(0.0, "0x0.0p1".parse::<Double>().unwrap().to_f64());
862     assert_eq!(0.0, "+0x0.0p1".parse::<Double>().unwrap().to_f64());
863     assert_eq!(-0.0, "-0x0.0p1".parse::<Double>().unwrap().to_f64());
864
865     assert_eq!(0.0, "0x0.0p+1".parse::<Double>().unwrap().to_f64());
866     assert_eq!(0.0, "+0x0.0p+1".parse::<Double>().unwrap().to_f64());
867     assert_eq!(-0.0, "-0x0.0p+1".parse::<Double>().unwrap().to_f64());
868
869     assert_eq!(0.0, "0x0.0p-1".parse::<Double>().unwrap().to_f64());
870     assert_eq!(0.0, "+0x0.0p-1".parse::<Double>().unwrap().to_f64());
871     assert_eq!(-0.0, "-0x0.0p-1".parse::<Double>().unwrap().to_f64());
872
873
874     assert_eq!(0.0, "0x00000.p1".parse::<Double>().unwrap().to_f64());
875     assert_eq!(0.0, "0x0000.00000p1".parse::<Double>().unwrap().to_f64());
876     assert_eq!(0.0, "0x.00000p1".parse::<Double>().unwrap().to_f64());
877     assert_eq!(0.0, "0x0.p1".parse::<Double>().unwrap().to_f64());
878     assert_eq!(0.0, "0x0p1234".parse::<Double>().unwrap().to_f64());
879     assert_eq!(-0.0, "-0x0p1234".parse::<Double>().unwrap().to_f64());
880     assert_eq!(0.0, "0x00000.p1234".parse::<Double>().unwrap().to_f64());
881     assert_eq!(0.0, "0x0000.00000p1234".parse::<Double>().unwrap().to_f64());
882     assert_eq!(0.0, "0x.00000p1234".parse::<Double>().unwrap().to_f64());
883     assert_eq!(0.0, "0x0.p1234".parse::<Double>().unwrap().to_f64());
884 }
885
886 #[test]
887 fn from_decimal_string() {
888     assert_eq!(1.0, "1".parse::<Double>().unwrap().to_f64());
889     assert_eq!(2.0, "2.".parse::<Double>().unwrap().to_f64());
890     assert_eq!(0.5, ".5".parse::<Double>().unwrap().to_f64());
891     assert_eq!(1.0, "1.0".parse::<Double>().unwrap().to_f64());
892     assert_eq!(-2.0, "-2".parse::<Double>().unwrap().to_f64());
893     assert_eq!(-4.0, "-4.".parse::<Double>().unwrap().to_f64());
894     assert_eq!(-0.5, "-.5".parse::<Double>().unwrap().to_f64());
895     assert_eq!(-1.5, "-1.5".parse::<Double>().unwrap().to_f64());
896     assert_eq!(1.25e12, "1.25e12".parse::<Double>().unwrap().to_f64());
897     assert_eq!(1.25e+12, "1.25e+12".parse::<Double>().unwrap().to_f64());
898     assert_eq!(1.25e-12, "1.25e-12".parse::<Double>().unwrap().to_f64());
899     assert_eq!(1024.0, "1024.".parse::<Double>().unwrap().to_f64());
900     assert_eq!(1024.05, "1024.05000".parse::<Double>().unwrap().to_f64());
901     assert_eq!(0.05, ".05000".parse::<Double>().unwrap().to_f64());
902     assert_eq!(2.0, "2.".parse::<Double>().unwrap().to_f64());
903     assert_eq!(2.0e2, "2.e2".parse::<Double>().unwrap().to_f64());
904     assert_eq!(2.0e+2, "2.e+2".parse::<Double>().unwrap().to_f64());
905     assert_eq!(2.0e-2, "2.e-2".parse::<Double>().unwrap().to_f64());
906     assert_eq!(2.05e2, "002.05000e2".parse::<Double>().unwrap().to_f64());
907     assert_eq!(2.05e+2, "002.05000e+2".parse::<Double>().unwrap().to_f64());
908     assert_eq!(2.05e-2, "002.05000e-2".parse::<Double>().unwrap().to_f64());
909     assert_eq!(2.05e12, "002.05000e12".parse::<Double>().unwrap().to_f64());
910     assert_eq!(
911         2.05e+12,
912         "002.05000e+12".parse::<Double>().unwrap().to_f64()
913     );
914     assert_eq!(
915         2.05e-12,
916         "002.05000e-12".parse::<Double>().unwrap().to_f64()
917     );
918
919     // These are "carefully selected" to overflow the fast log-base
920     // calculations in the implementation.
921     assert!("99e99999".parse::<Double>().unwrap().is_infinite());
922     assert!("-99e99999".parse::<Double>().unwrap().is_infinite());
923     assert!("1e-99999".parse::<Double>().unwrap().is_pos_zero());
924     assert!("-1e-99999".parse::<Double>().unwrap().is_neg_zero());
925
926     assert_eq!(2.71828, "2.71828".parse::<Double>().unwrap().to_f64());
927 }
928
929 #[test]
930 fn from_hexadecimal_string() {
931     assert_eq!(1.0, "0x1p0".parse::<Double>().unwrap().to_f64());
932     assert_eq!(1.0, "+0x1p0".parse::<Double>().unwrap().to_f64());
933     assert_eq!(-1.0, "-0x1p0".parse::<Double>().unwrap().to_f64());
934
935     assert_eq!(1.0, "0x1p+0".parse::<Double>().unwrap().to_f64());
936     assert_eq!(1.0, "+0x1p+0".parse::<Double>().unwrap().to_f64());
937     assert_eq!(-1.0, "-0x1p+0".parse::<Double>().unwrap().to_f64());
938
939     assert_eq!(1.0, "0x1p-0".parse::<Double>().unwrap().to_f64());
940     assert_eq!(1.0, "+0x1p-0".parse::<Double>().unwrap().to_f64());
941     assert_eq!(-1.0, "-0x1p-0".parse::<Double>().unwrap().to_f64());
942
943
944     assert_eq!(2.0, "0x1p1".parse::<Double>().unwrap().to_f64());
945     assert_eq!(2.0, "+0x1p1".parse::<Double>().unwrap().to_f64());
946     assert_eq!(-2.0, "-0x1p1".parse::<Double>().unwrap().to_f64());
947
948     assert_eq!(2.0, "0x1p+1".parse::<Double>().unwrap().to_f64());
949     assert_eq!(2.0, "+0x1p+1".parse::<Double>().unwrap().to_f64());
950     assert_eq!(-2.0, "-0x1p+1".parse::<Double>().unwrap().to_f64());
951
952     assert_eq!(0.5, "0x1p-1".parse::<Double>().unwrap().to_f64());
953     assert_eq!(0.5, "+0x1p-1".parse::<Double>().unwrap().to_f64());
954     assert_eq!(-0.5, "-0x1p-1".parse::<Double>().unwrap().to_f64());
955
956
957     assert_eq!(3.0, "0x1.8p1".parse::<Double>().unwrap().to_f64());
958     assert_eq!(3.0, "+0x1.8p1".parse::<Double>().unwrap().to_f64());
959     assert_eq!(-3.0, "-0x1.8p1".parse::<Double>().unwrap().to_f64());
960
961     assert_eq!(3.0, "0x1.8p+1".parse::<Double>().unwrap().to_f64());
962     assert_eq!(3.0, "+0x1.8p+1".parse::<Double>().unwrap().to_f64());
963     assert_eq!(-3.0, "-0x1.8p+1".parse::<Double>().unwrap().to_f64());
964
965     assert_eq!(0.75, "0x1.8p-1".parse::<Double>().unwrap().to_f64());
966     assert_eq!(0.75, "+0x1.8p-1".parse::<Double>().unwrap().to_f64());
967     assert_eq!(-0.75, "-0x1.8p-1".parse::<Double>().unwrap().to_f64());
968
969
970     assert_eq!(8192.0, "0x1000.000p1".parse::<Double>().unwrap().to_f64());
971     assert_eq!(8192.0, "+0x1000.000p1".parse::<Double>().unwrap().to_f64());
972     assert_eq!(-8192.0, "-0x1000.000p1".parse::<Double>().unwrap().to_f64());
973
974     assert_eq!(8192.0, "0x1000.000p+1".parse::<Double>().unwrap().to_f64());
975     assert_eq!(8192.0, "+0x1000.000p+1".parse::<Double>().unwrap().to_f64());
976     assert_eq!(
977         -8192.0,
978         "-0x1000.000p+1".parse::<Double>().unwrap().to_f64()
979     );
980
981     assert_eq!(2048.0, "0x1000.000p-1".parse::<Double>().unwrap().to_f64());
982     assert_eq!(2048.0, "+0x1000.000p-1".parse::<Double>().unwrap().to_f64());
983     assert_eq!(
984         -2048.0,
985         "-0x1000.000p-1".parse::<Double>().unwrap().to_f64()
986     );
987
988
989     assert_eq!(8192.0, "0x1000p1".parse::<Double>().unwrap().to_f64());
990     assert_eq!(8192.0, "+0x1000p1".parse::<Double>().unwrap().to_f64());
991     assert_eq!(-8192.0, "-0x1000p1".parse::<Double>().unwrap().to_f64());
992
993     assert_eq!(8192.0, "0x1000p+1".parse::<Double>().unwrap().to_f64());
994     assert_eq!(8192.0, "+0x1000p+1".parse::<Double>().unwrap().to_f64());
995     assert_eq!(-8192.0, "-0x1000p+1".parse::<Double>().unwrap().to_f64());
996
997     assert_eq!(2048.0, "0x1000p-1".parse::<Double>().unwrap().to_f64());
998     assert_eq!(2048.0, "+0x1000p-1".parse::<Double>().unwrap().to_f64());
999     assert_eq!(-2048.0, "-0x1000p-1".parse::<Double>().unwrap().to_f64());
1000
1001
1002     assert_eq!(16384.0, "0x10p10".parse::<Double>().unwrap().to_f64());
1003     assert_eq!(16384.0, "+0x10p10".parse::<Double>().unwrap().to_f64());
1004     assert_eq!(-16384.0, "-0x10p10".parse::<Double>().unwrap().to_f64());
1005
1006     assert_eq!(16384.0, "0x10p+10".parse::<Double>().unwrap().to_f64());
1007     assert_eq!(16384.0, "+0x10p+10".parse::<Double>().unwrap().to_f64());
1008     assert_eq!(-16384.0, "-0x10p+10".parse::<Double>().unwrap().to_f64());
1009
1010     assert_eq!(0.015625, "0x10p-10".parse::<Double>().unwrap().to_f64());
1011     assert_eq!(0.015625, "+0x10p-10".parse::<Double>().unwrap().to_f64());
1012     assert_eq!(-0.015625, "-0x10p-10".parse::<Double>().unwrap().to_f64());
1013
1014     assert_eq!(1.0625, "0x1.1p0".parse::<Double>().unwrap().to_f64());
1015     assert_eq!(1.0, "0x1p0".parse::<Double>().unwrap().to_f64());
1016
1017     assert_eq!(
1018         "0x1p-150".parse::<Double>().unwrap().to_f64(),
1019         "+0x800000000000000001.p-221"
1020             .parse::<Double>()
1021             .unwrap()
1022             .to_f64()
1023     );
1024     assert_eq!(
1025         2251799813685248.5,
1026         "0x80000000000004000000.010p-28"
1027             .parse::<Double>()
1028             .unwrap()
1029             .to_f64()
1030     );
1031 }
1032
1033 #[test]
1034 fn to_string() {
1035     let to_string = |d: f64, precision: usize, width: usize| {
1036         let x = Double::from_f64(d);
1037         if precision == 0 {
1038             format!("{:1$}", x, width)
1039         } else {
1040             format!("{:2$.1$}", x, precision, width)
1041         }
1042     };
1043     assert_eq!("10", to_string(10.0, 6, 3));
1044     assert_eq!("1.0E+1", to_string(10.0, 6, 0));
1045     assert_eq!("10100", to_string(1.01E+4, 5, 2));
1046     assert_eq!("1.01E+4", to_string(1.01E+4, 4, 2));
1047     assert_eq!("1.01E+4", to_string(1.01E+4, 5, 1));
1048     assert_eq!("0.0101", to_string(1.01E-2, 5, 2));
1049     assert_eq!("0.0101", to_string(1.01E-2, 4, 2));
1050     assert_eq!("1.01E-2", to_string(1.01E-2, 5, 1));
1051     assert_eq!(
1052         "0.78539816339744828",
1053         to_string(0.78539816339744830961, 0, 3)
1054     );
1055     assert_eq!(
1056         "4.9406564584124654E-324",
1057         to_string(4.9406564584124654e-324, 0, 3)
1058     );
1059     assert_eq!("873.18340000000001", to_string(873.1834, 0, 1));
1060     assert_eq!("8.7318340000000001E+2", to_string(873.1834, 0, 0));
1061     assert_eq!(
1062         "1.7976931348623157E+308",
1063         to_string(1.7976931348623157E+308, 0, 0)
1064     );
1065
1066     let to_string = |d: f64, precision: usize, width: usize| {
1067         let x = Double::from_f64(d);
1068         if precision == 0 {
1069             format!("{:#1$}", x, width)
1070         } else {
1071             format!("{:#2$.1$}", x, precision, width)
1072         }
1073     };
1074     assert_eq!("10", to_string(10.0, 6, 3));
1075     assert_eq!("1.000000e+01", to_string(10.0, 6, 0));
1076     assert_eq!("10100", to_string(1.01E+4, 5, 2));
1077     assert_eq!("1.0100e+04", to_string(1.01E+4, 4, 2));
1078     assert_eq!("1.01000e+04", to_string(1.01E+4, 5, 1));
1079     assert_eq!("0.0101", to_string(1.01E-2, 5, 2));
1080     assert_eq!("0.0101", to_string(1.01E-2, 4, 2));
1081     assert_eq!("1.01000e-02", to_string(1.01E-2, 5, 1));
1082     assert_eq!(
1083         "0.78539816339744828",
1084         to_string(0.78539816339744830961, 0, 3)
1085     );
1086     assert_eq!(
1087         "4.94065645841246540e-324",
1088         to_string(4.9406564584124654e-324, 0, 3)
1089     );
1090     assert_eq!("873.18340000000001", to_string(873.1834, 0, 1));
1091     assert_eq!("8.73183400000000010e+02", to_string(873.1834, 0, 0));
1092     assert_eq!(
1093         "1.79769313486231570e+308",
1094         to_string(1.7976931348623157E+308, 0, 0)
1095     );
1096 }
1097
1098 #[test]
1099 fn to_integer() {
1100     let mut is_exact = false;
1101
1102     assert_eq!(
1103         Status::OK.and(10),
1104         "10".parse::<Double>().unwrap().to_u128_r(
1105             5,
1106             Round::TowardZero,
1107             &mut is_exact,
1108         )
1109     );
1110     assert!(is_exact);
1111
1112     assert_eq!(
1113         Status::INVALID_OP.and(0),
1114         "-10".parse::<Double>().unwrap().to_u128_r(
1115             5,
1116             Round::TowardZero,
1117             &mut is_exact,
1118         )
1119     );
1120     assert!(!is_exact);
1121
1122     assert_eq!(
1123         Status::INVALID_OP.and(31),
1124         "32".parse::<Double>().unwrap().to_u128_r(
1125             5,
1126             Round::TowardZero,
1127             &mut is_exact,
1128         )
1129     );
1130     assert!(!is_exact);
1131
1132     assert_eq!(
1133         Status::INEXACT.and(7),
1134         "7.9".parse::<Double>().unwrap().to_u128_r(
1135             5,
1136             Round::TowardZero,
1137             &mut is_exact,
1138         )
1139     );
1140     assert!(!is_exact);
1141
1142     assert_eq!(
1143         Status::OK.and(-10),
1144         "-10".parse::<Double>().unwrap().to_i128_r(
1145             5,
1146             Round::TowardZero,
1147             &mut is_exact,
1148         )
1149     );
1150     assert!(is_exact);
1151
1152     assert_eq!(
1153         Status::INVALID_OP.and(-16),
1154         "-17".parse::<Double>().unwrap().to_i128_r(
1155             5,
1156             Round::TowardZero,
1157             &mut is_exact,
1158         )
1159     );
1160     assert!(!is_exact);
1161
1162     assert_eq!(
1163         Status::INVALID_OP.and(15),
1164         "16".parse::<Double>().unwrap().to_i128_r(
1165             5,
1166             Round::TowardZero,
1167             &mut is_exact,
1168         )
1169     );
1170     assert!(!is_exact);
1171 }
1172
1173 #[test]
1174 fn nan() {
1175     fn nanbits<T: Float>(signaling: bool, negative: bool, fill: u128) -> u128 {
1176         let x = if signaling {
1177             T::snan(Some(fill))
1178         } else {
1179             T::qnan(Some(fill))
1180         };
1181         if negative {
1182             (-x).to_bits()
1183         } else {
1184             x.to_bits()
1185         }
1186     }
1187
1188     assert_eq!(0x7fc00000, nanbits::<Single>(false, false, 0));
1189     assert_eq!(0xffc00000, nanbits::<Single>(false, true, 0));
1190     assert_eq!(0x7fc0ae72, nanbits::<Single>(false, false, 0xae72));
1191     assert_eq!(0x7fffae72, nanbits::<Single>(false, false, 0xffffae72));
1192     assert_eq!(0x7fa00000, nanbits::<Single>(true, false, 0));
1193     assert_eq!(0xffa00000, nanbits::<Single>(true, true, 0));
1194     assert_eq!(0x7f80ae72, nanbits::<Single>(true, false, 0xae72));
1195     assert_eq!(0x7fbfae72, nanbits::<Single>(true, false, 0xffffae72));
1196
1197     assert_eq!(0x7ff8000000000000, nanbits::<Double>(false, false, 0));
1198     assert_eq!(0xfff8000000000000, nanbits::<Double>(false, true, 0));
1199     assert_eq!(0x7ff800000000ae72, nanbits::<Double>(false, false, 0xae72));
1200     assert_eq!(
1201         0x7fffffffffffae72,
1202         nanbits::<Double>(false, false, 0xffffffffffffae72)
1203     );
1204     assert_eq!(0x7ff4000000000000, nanbits::<Double>(true, false, 0));
1205     assert_eq!(0xfff4000000000000, nanbits::<Double>(true, true, 0));
1206     assert_eq!(0x7ff000000000ae72, nanbits::<Double>(true, false, 0xae72));
1207     assert_eq!(
1208         0x7ff7ffffffffae72,
1209         nanbits::<Double>(true, false, 0xffffffffffffae72)
1210     );
1211 }
1212
1213 #[test]
1214 fn string_decimal_death() {
1215     assert_eq!(
1216         "".parse::<Double>(),
1217         Err(ParseError("Invalid string length"))
1218     );
1219     assert_eq!(
1220         "+".parse::<Double>(),
1221         Err(ParseError("String has no digits"))
1222     );
1223     assert_eq!(
1224         "-".parse::<Double>(),
1225         Err(ParseError("String has no digits"))
1226     );
1227
1228     assert_eq!(
1229         "\0".parse::<Double>(),
1230         Err(ParseError("Invalid character in significand"))
1231     );
1232     assert_eq!(
1233         "1\0".parse::<Double>(),
1234         Err(ParseError("Invalid character in significand"))
1235     );
1236     assert_eq!(
1237         "1\02".parse::<Double>(),
1238         Err(ParseError("Invalid character in significand"))
1239     );
1240     assert_eq!(
1241         "1\02e1".parse::<Double>(),
1242         Err(ParseError("Invalid character in significand"))
1243     );
1244     assert_eq!(
1245         "1e\0".parse::<Double>(),
1246         Err(ParseError("Invalid character in exponent"))
1247     );
1248     assert_eq!(
1249         "1e1\0".parse::<Double>(),
1250         Err(ParseError("Invalid character in exponent"))
1251     );
1252     assert_eq!(
1253         "1e1\02".parse::<Double>(),
1254         Err(ParseError("Invalid character in exponent"))
1255     );
1256
1257     assert_eq!(
1258         "1.0f".parse::<Double>(),
1259         Err(ParseError("Invalid character in significand"))
1260     );
1261
1262     assert_eq!(
1263         "..".parse::<Double>(),
1264         Err(ParseError("String contains multiple dots"))
1265     );
1266     assert_eq!(
1267         "..0".parse::<Double>(),
1268         Err(ParseError("String contains multiple dots"))
1269     );
1270     assert_eq!(
1271         "1.0.0".parse::<Double>(),
1272         Err(ParseError("String contains multiple dots"))
1273     );
1274 }
1275
1276 #[test]
1277 fn string_decimal_significand_death() {
1278     assert_eq!(
1279         ".".parse::<Double>(),
1280         Err(ParseError("Significand has no digits"))
1281     );
1282     assert_eq!(
1283         "+.".parse::<Double>(),
1284         Err(ParseError("Significand has no digits"))
1285     );
1286     assert_eq!(
1287         "-.".parse::<Double>(),
1288         Err(ParseError("Significand has no digits"))
1289     );
1290
1291
1292     assert_eq!(
1293         "e".parse::<Double>(),
1294         Err(ParseError("Significand has no digits"))
1295     );
1296     assert_eq!(
1297         "+e".parse::<Double>(),
1298         Err(ParseError("Significand has no digits"))
1299     );
1300     assert_eq!(
1301         "-e".parse::<Double>(),
1302         Err(ParseError("Significand has no digits"))
1303     );
1304
1305     assert_eq!(
1306         "e1".parse::<Double>(),
1307         Err(ParseError("Significand has no digits"))
1308     );
1309     assert_eq!(
1310         "+e1".parse::<Double>(),
1311         Err(ParseError("Significand has no digits"))
1312     );
1313     assert_eq!(
1314         "-e1".parse::<Double>(),
1315         Err(ParseError("Significand has no digits"))
1316     );
1317
1318     assert_eq!(
1319         ".e1".parse::<Double>(),
1320         Err(ParseError("Significand has no digits"))
1321     );
1322     assert_eq!(
1323         "+.e1".parse::<Double>(),
1324         Err(ParseError("Significand has no digits"))
1325     );
1326     assert_eq!(
1327         "-.e1".parse::<Double>(),
1328         Err(ParseError("Significand has no digits"))
1329     );
1330
1331
1332     assert_eq!(
1333         ".e".parse::<Double>(),
1334         Err(ParseError("Significand has no digits"))
1335     );
1336     assert_eq!(
1337         "+.e".parse::<Double>(),
1338         Err(ParseError("Significand has no digits"))
1339     );
1340     assert_eq!(
1341         "-.e".parse::<Double>(),
1342         Err(ParseError("Significand has no digits"))
1343     );
1344 }
1345
1346 #[test]
1347 fn string_decimal_exponent_death() {
1348     assert_eq!(
1349         "1e".parse::<Double>(),
1350         Err(ParseError("Exponent has no digits"))
1351     );
1352     assert_eq!(
1353         "+1e".parse::<Double>(),
1354         Err(ParseError("Exponent has no digits"))
1355     );
1356     assert_eq!(
1357         "-1e".parse::<Double>(),
1358         Err(ParseError("Exponent has no digits"))
1359     );
1360
1361     assert_eq!(
1362         "1.e".parse::<Double>(),
1363         Err(ParseError("Exponent has no digits"))
1364     );
1365     assert_eq!(
1366         "+1.e".parse::<Double>(),
1367         Err(ParseError("Exponent has no digits"))
1368     );
1369     assert_eq!(
1370         "-1.e".parse::<Double>(),
1371         Err(ParseError("Exponent has no digits"))
1372     );
1373
1374     assert_eq!(
1375         ".1e".parse::<Double>(),
1376         Err(ParseError("Exponent has no digits"))
1377     );
1378     assert_eq!(
1379         "+.1e".parse::<Double>(),
1380         Err(ParseError("Exponent has no digits"))
1381     );
1382     assert_eq!(
1383         "-.1e".parse::<Double>(),
1384         Err(ParseError("Exponent has no digits"))
1385     );
1386
1387     assert_eq!(
1388         "1.1e".parse::<Double>(),
1389         Err(ParseError("Exponent has no digits"))
1390     );
1391     assert_eq!(
1392         "+1.1e".parse::<Double>(),
1393         Err(ParseError("Exponent has no digits"))
1394     );
1395     assert_eq!(
1396         "-1.1e".parse::<Double>(),
1397         Err(ParseError("Exponent has no digits"))
1398     );
1399
1400
1401     assert_eq!(
1402         "1e+".parse::<Double>(),
1403         Err(ParseError("Exponent has no digits"))
1404     );
1405     assert_eq!(
1406         "1e-".parse::<Double>(),
1407         Err(ParseError("Exponent has no digits"))
1408     );
1409
1410     assert_eq!(
1411         ".1e".parse::<Double>(),
1412         Err(ParseError("Exponent has no digits"))
1413     );
1414     assert_eq!(
1415         ".1e+".parse::<Double>(),
1416         Err(ParseError("Exponent has no digits"))
1417     );
1418     assert_eq!(
1419         ".1e-".parse::<Double>(),
1420         Err(ParseError("Exponent has no digits"))
1421     );
1422
1423     assert_eq!(
1424         "1.0e".parse::<Double>(),
1425         Err(ParseError("Exponent has no digits"))
1426     );
1427     assert_eq!(
1428         "1.0e+".parse::<Double>(),
1429         Err(ParseError("Exponent has no digits"))
1430     );
1431     assert_eq!(
1432         "1.0e-".parse::<Double>(),
1433         Err(ParseError("Exponent has no digits"))
1434     );
1435 }
1436
1437 #[test]
1438 fn string_hexadecimal_death() {
1439     assert_eq!("0x".parse::<Double>(), Err(ParseError("Invalid string")));
1440     assert_eq!("+0x".parse::<Double>(), Err(ParseError("Invalid string")));
1441     assert_eq!("-0x".parse::<Double>(), Err(ParseError("Invalid string")));
1442
1443     assert_eq!(
1444         "0x0".parse::<Double>(),
1445         Err(ParseError("Hex strings require an exponent"))
1446     );
1447     assert_eq!(
1448         "+0x0".parse::<Double>(),
1449         Err(ParseError("Hex strings require an exponent"))
1450     );
1451     assert_eq!(
1452         "-0x0".parse::<Double>(),
1453         Err(ParseError("Hex strings require an exponent"))
1454     );
1455
1456     assert_eq!(
1457         "0x0.".parse::<Double>(),
1458         Err(ParseError("Hex strings require an exponent"))
1459     );
1460     assert_eq!(
1461         "+0x0.".parse::<Double>(),
1462         Err(ParseError("Hex strings require an exponent"))
1463     );
1464     assert_eq!(
1465         "-0x0.".parse::<Double>(),
1466         Err(ParseError("Hex strings require an exponent"))
1467     );
1468
1469     assert_eq!(
1470         "0x.0".parse::<Double>(),
1471         Err(ParseError("Hex strings require an exponent"))
1472     );
1473     assert_eq!(
1474         "+0x.0".parse::<Double>(),
1475         Err(ParseError("Hex strings require an exponent"))
1476     );
1477     assert_eq!(
1478         "-0x.0".parse::<Double>(),
1479         Err(ParseError("Hex strings require an exponent"))
1480     );
1481
1482     assert_eq!(
1483         "0x0.0".parse::<Double>(),
1484         Err(ParseError("Hex strings require an exponent"))
1485     );
1486     assert_eq!(
1487         "+0x0.0".parse::<Double>(),
1488         Err(ParseError("Hex strings require an exponent"))
1489     );
1490     assert_eq!(
1491         "-0x0.0".parse::<Double>(),
1492         Err(ParseError("Hex strings require an exponent"))
1493     );
1494
1495     assert_eq!(
1496         "0x\0".parse::<Double>(),
1497         Err(ParseError("Invalid character in significand"))
1498     );
1499     assert_eq!(
1500         "0x1\0".parse::<Double>(),
1501         Err(ParseError("Invalid character in significand"))
1502     );
1503     assert_eq!(
1504         "0x1\02".parse::<Double>(),
1505         Err(ParseError("Invalid character in significand"))
1506     );
1507     assert_eq!(
1508         "0x1\02p1".parse::<Double>(),
1509         Err(ParseError("Invalid character in significand"))
1510     );
1511     assert_eq!(
1512         "0x1p\0".parse::<Double>(),
1513         Err(ParseError("Invalid character in exponent"))
1514     );
1515     assert_eq!(
1516         "0x1p1\0".parse::<Double>(),
1517         Err(ParseError("Invalid character in exponent"))
1518     );
1519     assert_eq!(
1520         "0x1p1\02".parse::<Double>(),
1521         Err(ParseError("Invalid character in exponent"))
1522     );
1523
1524     assert_eq!(
1525         "0x1p0f".parse::<Double>(),
1526         Err(ParseError("Invalid character in exponent"))
1527     );
1528
1529     assert_eq!(
1530         "0x..p1".parse::<Double>(),
1531         Err(ParseError("String contains multiple dots"))
1532     );
1533     assert_eq!(
1534         "0x..0p1".parse::<Double>(),
1535         Err(ParseError("String contains multiple dots"))
1536     );
1537     assert_eq!(
1538         "0x1.0.0p1".parse::<Double>(),
1539         Err(ParseError("String contains multiple dots"))
1540     );
1541 }
1542
1543 #[test]
1544 fn string_hexadecimal_significand_death() {
1545     assert_eq!(
1546         "0x.".parse::<Double>(),
1547         Err(ParseError("Significand has no digits"))
1548     );
1549     assert_eq!(
1550         "+0x.".parse::<Double>(),
1551         Err(ParseError("Significand has no digits"))
1552     );
1553     assert_eq!(
1554         "-0x.".parse::<Double>(),
1555         Err(ParseError("Significand has no digits"))
1556     );
1557
1558     assert_eq!(
1559         "0xp".parse::<Double>(),
1560         Err(ParseError("Significand has no digits"))
1561     );
1562     assert_eq!(
1563         "+0xp".parse::<Double>(),
1564         Err(ParseError("Significand has no digits"))
1565     );
1566     assert_eq!(
1567         "-0xp".parse::<Double>(),
1568         Err(ParseError("Significand has no digits"))
1569     );
1570
1571     assert_eq!(
1572         "0xp+".parse::<Double>(),
1573         Err(ParseError("Significand has no digits"))
1574     );
1575     assert_eq!(
1576         "+0xp+".parse::<Double>(),
1577         Err(ParseError("Significand has no digits"))
1578     );
1579     assert_eq!(
1580         "-0xp+".parse::<Double>(),
1581         Err(ParseError("Significand has no digits"))
1582     );
1583
1584     assert_eq!(
1585         "0xp-".parse::<Double>(),
1586         Err(ParseError("Significand has no digits"))
1587     );
1588     assert_eq!(
1589         "+0xp-".parse::<Double>(),
1590         Err(ParseError("Significand has no digits"))
1591     );
1592     assert_eq!(
1593         "-0xp-".parse::<Double>(),
1594         Err(ParseError("Significand has no digits"))
1595     );
1596
1597
1598     assert_eq!(
1599         "0x.p".parse::<Double>(),
1600         Err(ParseError("Significand has no digits"))
1601     );
1602     assert_eq!(
1603         "+0x.p".parse::<Double>(),
1604         Err(ParseError("Significand has no digits"))
1605     );
1606     assert_eq!(
1607         "-0x.p".parse::<Double>(),
1608         Err(ParseError("Significand has no digits"))
1609     );
1610
1611     assert_eq!(
1612         "0x.p+".parse::<Double>(),
1613         Err(ParseError("Significand has no digits"))
1614     );
1615     assert_eq!(
1616         "+0x.p+".parse::<Double>(),
1617         Err(ParseError("Significand has no digits"))
1618     );
1619     assert_eq!(
1620         "-0x.p+".parse::<Double>(),
1621         Err(ParseError("Significand has no digits"))
1622     );
1623
1624     assert_eq!(
1625         "0x.p-".parse::<Double>(),
1626         Err(ParseError("Significand has no digits"))
1627     );
1628     assert_eq!(
1629         "+0x.p-".parse::<Double>(),
1630         Err(ParseError("Significand has no digits"))
1631     );
1632     assert_eq!(
1633         "-0x.p-".parse::<Double>(),
1634         Err(ParseError("Significand has no digits"))
1635     );
1636 }
1637
1638 #[test]
1639 fn string_hexadecimal_exponent_death() {
1640     assert_eq!(
1641         "0x1p".parse::<Double>(),
1642         Err(ParseError("Exponent has no digits"))
1643     );
1644     assert_eq!(
1645         "+0x1p".parse::<Double>(),
1646         Err(ParseError("Exponent has no digits"))
1647     );
1648     assert_eq!(
1649         "-0x1p".parse::<Double>(),
1650         Err(ParseError("Exponent has no digits"))
1651     );
1652
1653     assert_eq!(
1654         "0x1p+".parse::<Double>(),
1655         Err(ParseError("Exponent has no digits"))
1656     );
1657     assert_eq!(
1658         "+0x1p+".parse::<Double>(),
1659         Err(ParseError("Exponent has no digits"))
1660     );
1661     assert_eq!(
1662         "-0x1p+".parse::<Double>(),
1663         Err(ParseError("Exponent has no digits"))
1664     );
1665
1666     assert_eq!(
1667         "0x1p-".parse::<Double>(),
1668         Err(ParseError("Exponent has no digits"))
1669     );
1670     assert_eq!(
1671         "+0x1p-".parse::<Double>(),
1672         Err(ParseError("Exponent has no digits"))
1673     );
1674     assert_eq!(
1675         "-0x1p-".parse::<Double>(),
1676         Err(ParseError("Exponent has no digits"))
1677     );
1678
1679
1680     assert_eq!(
1681         "0x1.p".parse::<Double>(),
1682         Err(ParseError("Exponent has no digits"))
1683     );
1684     assert_eq!(
1685         "+0x1.p".parse::<Double>(),
1686         Err(ParseError("Exponent has no digits"))
1687     );
1688     assert_eq!(
1689         "-0x1.p".parse::<Double>(),
1690         Err(ParseError("Exponent has no digits"))
1691     );
1692
1693     assert_eq!(
1694         "0x1.p+".parse::<Double>(),
1695         Err(ParseError("Exponent has no digits"))
1696     );
1697     assert_eq!(
1698         "+0x1.p+".parse::<Double>(),
1699         Err(ParseError("Exponent has no digits"))
1700     );
1701     assert_eq!(
1702         "-0x1.p+".parse::<Double>(),
1703         Err(ParseError("Exponent has no digits"))
1704     );
1705
1706     assert_eq!(
1707         "0x1.p-".parse::<Double>(),
1708         Err(ParseError("Exponent has no digits"))
1709     );
1710     assert_eq!(
1711         "+0x1.p-".parse::<Double>(),
1712         Err(ParseError("Exponent has no digits"))
1713     );
1714     assert_eq!(
1715         "-0x1.p-".parse::<Double>(),
1716         Err(ParseError("Exponent has no digits"))
1717     );
1718
1719
1720     assert_eq!(
1721         "0x.1p".parse::<Double>(),
1722         Err(ParseError("Exponent has no digits"))
1723     );
1724     assert_eq!(
1725         "+0x.1p".parse::<Double>(),
1726         Err(ParseError("Exponent has no digits"))
1727     );
1728     assert_eq!(
1729         "-0x.1p".parse::<Double>(),
1730         Err(ParseError("Exponent has no digits"))
1731     );
1732
1733     assert_eq!(
1734         "0x.1p+".parse::<Double>(),
1735         Err(ParseError("Exponent has no digits"))
1736     );
1737     assert_eq!(
1738         "+0x.1p+".parse::<Double>(),
1739         Err(ParseError("Exponent has no digits"))
1740     );
1741     assert_eq!(
1742         "-0x.1p+".parse::<Double>(),
1743         Err(ParseError("Exponent has no digits"))
1744     );
1745
1746     assert_eq!(
1747         "0x.1p-".parse::<Double>(),
1748         Err(ParseError("Exponent has no digits"))
1749     );
1750     assert_eq!(
1751         "+0x.1p-".parse::<Double>(),
1752         Err(ParseError("Exponent has no digits"))
1753     );
1754     assert_eq!(
1755         "-0x.1p-".parse::<Double>(),
1756         Err(ParseError("Exponent has no digits"))
1757     );
1758
1759
1760     assert_eq!(
1761         "0x1.1p".parse::<Double>(),
1762         Err(ParseError("Exponent has no digits"))
1763     );
1764     assert_eq!(
1765         "+0x1.1p".parse::<Double>(),
1766         Err(ParseError("Exponent has no digits"))
1767     );
1768     assert_eq!(
1769         "-0x1.1p".parse::<Double>(),
1770         Err(ParseError("Exponent has no digits"))
1771     );
1772
1773     assert_eq!(
1774         "0x1.1p+".parse::<Double>(),
1775         Err(ParseError("Exponent has no digits"))
1776     );
1777     assert_eq!(
1778         "+0x1.1p+".parse::<Double>(),
1779         Err(ParseError("Exponent has no digits"))
1780     );
1781     assert_eq!(
1782         "-0x1.1p+".parse::<Double>(),
1783         Err(ParseError("Exponent has no digits"))
1784     );
1785
1786     assert_eq!(
1787         "0x1.1p-".parse::<Double>(),
1788         Err(ParseError("Exponent has no digits"))
1789     );
1790     assert_eq!(
1791         "+0x1.1p-".parse::<Double>(),
1792         Err(ParseError("Exponent has no digits"))
1793     );
1794     assert_eq!(
1795         "-0x1.1p-".parse::<Double>(),
1796         Err(ParseError("Exponent has no digits"))
1797     );
1798 }
1799
1800 #[test]
1801 fn exact_inverse() {
1802     // Trivial operation.
1803     assert!(
1804         Double::from_f64(2.0)
1805             .get_exact_inverse()
1806             .unwrap()
1807             .bitwise_eq(Double::from_f64(0.5))
1808     );
1809     assert!(
1810         Single::from_f32(2.0)
1811             .get_exact_inverse()
1812             .unwrap()
1813             .bitwise_eq(Single::from_f32(0.5))
1814     );
1815     assert!(
1816         "2.0"
1817             .parse::<Quad>()
1818             .unwrap()
1819             .get_exact_inverse()
1820             .unwrap()
1821             .bitwise_eq("0.5".parse::<Quad>().unwrap())
1822     );
1823     assert!(
1824         "2.0"
1825             .parse::<X87DoubleExtended>()
1826             .unwrap()
1827             .get_exact_inverse()
1828             .unwrap()
1829             .bitwise_eq("0.5".parse::<X87DoubleExtended>().unwrap())
1830     );
1831
1832     // FLT_MIN
1833     assert!(
1834         Single::from_f32(1.17549435e-38)
1835             .get_exact_inverse()
1836             .unwrap()
1837             .bitwise_eq(Single::from_f32(8.5070592e+37))
1838     );
1839
1840     // Large float, inverse is a denormal.
1841     assert!(Single::from_f32(1.7014118e38).get_exact_inverse().is_none());
1842     // Zero
1843     assert!(Double::from_f64(0.0).get_exact_inverse().is_none());
1844     // Denormalized float
1845     assert!(
1846         Single::from_f32(1.40129846e-45)
1847             .get_exact_inverse()
1848             .is_none()
1849     );
1850 }
1851
1852 #[test]
1853 fn round_to_integral() {
1854     let t = Double::from_f64(-0.5);
1855     assert_eq!(-0.0, t.round_to_integral(Round::TowardZero).value.to_f64());
1856     assert_eq!(
1857         -1.0,
1858         t.round_to_integral(Round::TowardNegative).value.to_f64()
1859     );
1860     assert_eq!(
1861         -0.0,
1862         t.round_to_integral(Round::TowardPositive).value.to_f64()
1863     );
1864     assert_eq!(
1865         -0.0,
1866         t.round_to_integral(Round::NearestTiesToEven).value.to_f64()
1867     );
1868
1869     let s = Double::from_f64(3.14);
1870     assert_eq!(3.0, s.round_to_integral(Round::TowardZero).value.to_f64());
1871     assert_eq!(
1872         3.0,
1873         s.round_to_integral(Round::TowardNegative).value.to_f64()
1874     );
1875     assert_eq!(
1876         4.0,
1877         s.round_to_integral(Round::TowardPositive).value.to_f64()
1878     );
1879     assert_eq!(
1880         3.0,
1881         s.round_to_integral(Round::NearestTiesToEven).value.to_f64()
1882     );
1883
1884     let r = Double::largest();
1885     assert_eq!(
1886         r.to_f64(),
1887         r.round_to_integral(Round::TowardZero).value.to_f64()
1888     );
1889     assert_eq!(
1890         r.to_f64(),
1891         r.round_to_integral(Round::TowardNegative).value.to_f64()
1892     );
1893     assert_eq!(
1894         r.to_f64(),
1895         r.round_to_integral(Round::TowardPositive).value.to_f64()
1896     );
1897     assert_eq!(
1898         r.to_f64(),
1899         r.round_to_integral(Round::NearestTiesToEven).value.to_f64()
1900     );
1901
1902     let p = Double::ZERO.round_to_integral(Round::TowardZero).value;
1903     assert_eq!(0.0, p.to_f64());
1904     let p = (-Double::ZERO).round_to_integral(Round::TowardZero).value;
1905     assert_eq!(-0.0, p.to_f64());
1906     let p = Double::NAN.round_to_integral(Round::TowardZero).value;
1907     assert!(p.to_f64().is_nan());
1908     let p = Double::INFINITY.round_to_integral(Round::TowardZero).value;
1909     assert!(p.to_f64().is_infinite() && p.to_f64() > 0.0);
1910     let p = (-Double::INFINITY)
1911         .round_to_integral(Round::TowardZero)
1912         .value;
1913     assert!(p.to_f64().is_infinite() && p.to_f64() < 0.0);
1914 }
1915
1916 #[test]
1917 fn is_integer() {
1918     let t = Double::from_f64(-0.0);
1919     assert!(t.is_integer());
1920     let t = Double::from_f64(3.14159);
1921     assert!(!t.is_integer());
1922     let t = Double::NAN;
1923     assert!(!t.is_integer());
1924     let t = Double::INFINITY;
1925     assert!(!t.is_integer());
1926     let t = -Double::INFINITY;
1927     assert!(!t.is_integer());
1928     let t = Double::largest();
1929     assert!(t.is_integer());
1930 }
1931
1932 #[test]
1933 fn largest() {
1934     assert_eq!(3.402823466e+38, Single::largest().to_f32());
1935     assert_eq!(1.7976931348623158e+308, Double::largest().to_f64());
1936 }
1937
1938 #[test]
1939 fn smallest() {
1940     let test = Single::SMALLEST;
1941     let expected = "0x0.000002p-126".parse::<Single>().unwrap();
1942     assert!(!test.is_negative());
1943     assert!(test.is_finite_non_zero());
1944     assert!(test.is_denormal());
1945     assert!(test.bitwise_eq(expected));
1946
1947     let test = -Single::SMALLEST;
1948     let expected = "-0x0.000002p-126".parse::<Single>().unwrap();
1949     assert!(test.is_negative());
1950     assert!(test.is_finite_non_zero());
1951     assert!(test.is_denormal());
1952     assert!(test.bitwise_eq(expected));
1953
1954     let test = Quad::SMALLEST;
1955     let expected = "0x0.0000000000000000000000000001p-16382"
1956         .parse::<Quad>()
1957         .unwrap();
1958     assert!(!test.is_negative());
1959     assert!(test.is_finite_non_zero());
1960     assert!(test.is_denormal());
1961     assert!(test.bitwise_eq(expected));
1962
1963     let test = -Quad::SMALLEST;
1964     let expected = "-0x0.0000000000000000000000000001p-16382"
1965         .parse::<Quad>()
1966         .unwrap();
1967     assert!(test.is_negative());
1968     assert!(test.is_finite_non_zero());
1969     assert!(test.is_denormal());
1970     assert!(test.bitwise_eq(expected));
1971 }
1972
1973 #[test]
1974 fn smallest_normalized() {
1975     let test = Single::smallest_normalized();
1976     let expected = "0x1p-126".parse::<Single>().unwrap();
1977     assert!(!test.is_negative());
1978     assert!(test.is_finite_non_zero());
1979     assert!(!test.is_denormal());
1980     assert!(test.bitwise_eq(expected));
1981
1982     let test = -Single::smallest_normalized();
1983     let expected = "-0x1p-126".parse::<Single>().unwrap();
1984     assert!(test.is_negative());
1985     assert!(test.is_finite_non_zero());
1986     assert!(!test.is_denormal());
1987     assert!(test.bitwise_eq(expected));
1988
1989     let test = Quad::smallest_normalized();
1990     let expected = "0x1p-16382".parse::<Quad>().unwrap();
1991     assert!(!test.is_negative());
1992     assert!(test.is_finite_non_zero());
1993     assert!(!test.is_denormal());
1994     assert!(test.bitwise_eq(expected));
1995
1996     let test = -Quad::smallest_normalized();
1997     let expected = "-0x1p-16382".parse::<Quad>().unwrap();
1998     assert!(test.is_negative());
1999     assert!(test.is_finite_non_zero());
2000     assert!(!test.is_denormal());
2001     assert!(test.bitwise_eq(expected));
2002 }
2003
2004 #[test]
2005 fn zero() {
2006     assert_eq!(0.0, Single::from_f32(0.0).to_f32());
2007     assert_eq!(-0.0, Single::from_f32(-0.0).to_f32());
2008     assert!(Single::from_f32(-0.0).is_negative());
2009
2010     assert_eq!(0.0, Double::from_f64(0.0).to_f64());
2011     assert_eq!(-0.0, Double::from_f64(-0.0).to_f64());
2012     assert!(Double::from_f64(-0.0).is_negative());
2013
2014     fn test<T: Float>(sign: bool, bits: u128) {
2015         let test = if sign { -T::ZERO } else { T::ZERO };
2016         let pattern = if sign { "-0x0p+0" } else { "0x0p+0" };
2017         let expected = pattern.parse::<T>().unwrap();
2018         assert!(test.is_zero());
2019         assert_eq!(sign, test.is_negative());
2020         assert!(test.bitwise_eq(expected));
2021         assert_eq!(bits, test.to_bits());
2022     }
2023     test::<Half>(false, 0);
2024     test::<Half>(true, 0x8000);
2025     test::<Single>(false, 0);
2026     test::<Single>(true, 0x80000000);
2027     test::<Double>(false, 0);
2028     test::<Double>(true, 0x8000000000000000);
2029     test::<Quad>(false, 0);
2030     test::<Quad>(true, 0x8000000000000000_0000000000000000);
2031     test::<X87DoubleExtended>(false, 0);
2032     test::<X87DoubleExtended>(true, 0x8000_0000000000000000);
2033 }
2034
2035 #[test]
2036 fn copy_sign() {
2037     assert!(Double::from_f64(-42.0).bitwise_eq(
2038         Double::from_f64(42.0).copy_sign(
2039             Double::from_f64(-1.0),
2040         ),
2041     ));
2042     assert!(Double::from_f64(42.0).bitwise_eq(
2043         Double::from_f64(-42.0).copy_sign(
2044             Double::from_f64(1.0),
2045         ),
2046     ));
2047     assert!(Double::from_f64(-42.0).bitwise_eq(
2048         Double::from_f64(-42.0).copy_sign(
2049             Double::from_f64(-1.0),
2050         ),
2051     ));
2052     assert!(Double::from_f64(42.0).bitwise_eq(
2053         Double::from_f64(42.0).copy_sign(
2054             Double::from_f64(1.0),
2055         ),
2056     ));
2057 }
2058
2059 #[test]
2060 fn convert() {
2061     let mut loses_info = false;
2062     let test = "1.0".parse::<Double>().unwrap();
2063     let test: Single = test.convert(&mut loses_info).value;
2064     assert_eq!(1.0, test.to_f32());
2065     assert!(!loses_info);
2066
2067     let mut test = "0x1p-53".parse::<X87DoubleExtended>().unwrap();
2068     let one = "1.0".parse::<X87DoubleExtended>().unwrap();
2069     test += one;
2070     let test: Double = test.convert(&mut loses_info).value;
2071     assert_eq!(1.0, test.to_f64());
2072     assert!(loses_info);
2073
2074     let mut test = "0x1p-53".parse::<Quad>().unwrap();
2075     let one = "1.0".parse::<Quad>().unwrap();
2076     test += one;
2077     let test: Double = test.convert(&mut loses_info).value;
2078     assert_eq!(1.0, test.to_f64());
2079     assert!(loses_info);
2080
2081     let test = "0xf.fffffffp+28".parse::<X87DoubleExtended>().unwrap();
2082     let test: Double = test.convert(&mut loses_info).value;
2083     assert_eq!(4294967295.0, test.to_f64());
2084     assert!(!loses_info);
2085
2086     let test = Single::snan(None);
2087     let x87_snan = X87DoubleExtended::snan(None);
2088     let test: X87DoubleExtended = test.convert(&mut loses_info).value;
2089     assert!(test.bitwise_eq(x87_snan));
2090     assert!(!loses_info);
2091
2092     let test = Single::qnan(None);
2093     let x87_qnan = X87DoubleExtended::qnan(None);
2094     let test: X87DoubleExtended = test.convert(&mut loses_info).value;
2095     assert!(test.bitwise_eq(x87_qnan));
2096     assert!(!loses_info);
2097
2098     let test = X87DoubleExtended::snan(None);
2099     let test: X87DoubleExtended = test.convert(&mut loses_info).value;
2100     assert!(test.bitwise_eq(x87_snan));
2101     assert!(!loses_info);
2102
2103     let test = X87DoubleExtended::qnan(None);
2104     let test: X87DoubleExtended = test.convert(&mut loses_info).value;
2105     assert!(test.bitwise_eq(x87_qnan));
2106     assert!(!loses_info);
2107 }
2108
2109 #[test]
2110 fn is_negative() {
2111     let t = "0x1p+0".parse::<Single>().unwrap();
2112     assert!(!t.is_negative());
2113     let t = "-0x1p+0".parse::<Single>().unwrap();
2114     assert!(t.is_negative());
2115
2116     assert!(!Single::INFINITY.is_negative());
2117     assert!((-Single::INFINITY).is_negative());
2118
2119     assert!(!Single::ZERO.is_negative());
2120     assert!((-Single::ZERO).is_negative());
2121
2122     assert!(!Single::NAN.is_negative());
2123     assert!((-Single::NAN).is_negative());
2124
2125     assert!(!Single::snan(None).is_negative());
2126     assert!((-Single::snan(None)).is_negative());
2127 }
2128
2129 #[test]
2130 fn is_normal() {
2131     let t = "0x1p+0".parse::<Single>().unwrap();
2132     assert!(t.is_normal());
2133
2134     assert!(!Single::INFINITY.is_normal());
2135     assert!(!Single::ZERO.is_normal());
2136     assert!(!Single::NAN.is_normal());
2137     assert!(!Single::snan(None).is_normal());
2138     assert!(!"0x1p-149".parse::<Single>().unwrap().is_normal());
2139 }
2140
2141 #[test]
2142 fn is_finite() {
2143     let t = "0x1p+0".parse::<Single>().unwrap();
2144     assert!(t.is_finite());
2145     assert!(!Single::INFINITY.is_finite());
2146     assert!(Single::ZERO.is_finite());
2147     assert!(!Single::NAN.is_finite());
2148     assert!(!Single::snan(None).is_finite());
2149     assert!("0x1p-149".parse::<Single>().unwrap().is_finite());
2150 }
2151
2152 #[test]
2153 fn is_infinite() {
2154     let t = "0x1p+0".parse::<Single>().unwrap();
2155     assert!(!t.is_infinite());
2156     assert!(Single::INFINITY.is_infinite());
2157     assert!(!Single::ZERO.is_infinite());
2158     assert!(!Single::NAN.is_infinite());
2159     assert!(!Single::snan(None).is_infinite());
2160     assert!(!"0x1p-149".parse::<Single>().unwrap().is_infinite());
2161 }
2162
2163 #[test]
2164 fn is_nan() {
2165     let t = "0x1p+0".parse::<Single>().unwrap();
2166     assert!(!t.is_nan());
2167     assert!(!Single::INFINITY.is_nan());
2168     assert!(!Single::ZERO.is_nan());
2169     assert!(Single::NAN.is_nan());
2170     assert!(Single::snan(None).is_nan());
2171     assert!(!"0x1p-149".parse::<Single>().unwrap().is_nan());
2172 }
2173
2174 #[test]
2175 fn is_finite_non_zero() {
2176     // Test positive/negative normal value.
2177     assert!("0x1p+0".parse::<Single>().unwrap().is_finite_non_zero());
2178     assert!("-0x1p+0".parse::<Single>().unwrap().is_finite_non_zero());
2179
2180     // Test positive/negative denormal value.
2181     assert!("0x1p-149".parse::<Single>().unwrap().is_finite_non_zero());
2182     assert!("-0x1p-149".parse::<Single>().unwrap().is_finite_non_zero());
2183
2184     // Test +/- Infinity.
2185     assert!(!Single::INFINITY.is_finite_non_zero());
2186     assert!(!(-Single::INFINITY).is_finite_non_zero());
2187
2188     // Test +/- Zero.
2189     assert!(!Single::ZERO.is_finite_non_zero());
2190     assert!(!(-Single::ZERO).is_finite_non_zero());
2191
2192     // Test +/- qNaN. +/- don't mean anything with qNaN but paranoia can't hurt in
2193     // this instance.
2194     assert!(!Single::NAN.is_finite_non_zero());
2195     assert!(!(-Single::NAN).is_finite_non_zero());
2196
2197     // Test +/- sNaN. +/- don't mean anything with sNaN but paranoia can't hurt in
2198     // this instance.
2199     assert!(!Single::snan(None).is_finite_non_zero());
2200     assert!(!(-Single::snan(None)).is_finite_non_zero());
2201 }
2202
2203 #[test]
2204 fn add() {
2205     // Test Special Cases against each other and normal values.
2206
2207     // FIXMES/NOTES:
2208     // 1. Since we perform only default exception handling all operations with
2209     // signaling NaNs should have a result that is a quiet NaN. Currently they
2210     // return sNaN.
2211
2212     let p_inf = Single::INFINITY;
2213     let m_inf = -Single::INFINITY;
2214     let p_zero = Single::ZERO;
2215     let m_zero = -Single::ZERO;
2216     let qnan = Single::NAN;
2217     let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
2218     let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
2219     let p_largest_value = Single::largest();
2220     let m_largest_value = -Single::largest();
2221     let p_smallest_value = Single::SMALLEST;
2222     let m_smallest_value = -Single::SMALLEST;
2223     let p_smallest_normalized = Single::smallest_normalized();
2224     let m_smallest_normalized = -Single::smallest_normalized();
2225
2226     let overflow_status = Status::OVERFLOW | Status::INEXACT;
2227
2228     let special_cases = [
2229         (p_inf, p_inf, "inf", Status::OK, Category::Infinity),
2230         (p_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2231         (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
2232         (p_inf, m_zero, "inf", Status::OK, Category::Infinity),
2233         (p_inf, qnan, "nan", Status::OK, Category::NaN),
2234         /*
2235 // See Note 1.
2236 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2237         */
2238         (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
2239         (p_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
2240         (
2241             p_inf,
2242             p_largest_value,
2243             "inf",
2244             Status::OK,
2245             Category::Infinity,
2246         ),
2247         (
2248             p_inf,
2249             m_largest_value,
2250             "inf",
2251             Status::OK,
2252             Category::Infinity,
2253         ),
2254         (
2255             p_inf,
2256             p_smallest_value,
2257             "inf",
2258             Status::OK,
2259             Category::Infinity,
2260         ),
2261         (
2262             p_inf,
2263             m_smallest_value,
2264             "inf",
2265             Status::OK,
2266             Category::Infinity,
2267         ),
2268         (
2269             p_inf,
2270             p_smallest_normalized,
2271             "inf",
2272             Status::OK,
2273             Category::Infinity,
2274         ),
2275         (
2276             p_inf,
2277             m_smallest_normalized,
2278             "inf",
2279             Status::OK,
2280             Category::Infinity,
2281         ),
2282         (m_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2283         (m_inf, m_inf, "-inf", Status::OK, Category::Infinity),
2284         (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
2285         (m_inf, m_zero, "-inf", Status::OK, Category::Infinity),
2286         (m_inf, qnan, "nan", Status::OK, Category::NaN),
2287         /*
2288 // See Note 1.
2289 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2290         */
2291         (
2292             m_inf,
2293             p_normal_value,
2294             "-inf",
2295             Status::OK,
2296             Category::Infinity,
2297         ),
2298         (
2299             m_inf,
2300             m_normal_value,
2301             "-inf",
2302             Status::OK,
2303             Category::Infinity,
2304         ),
2305         (
2306             m_inf,
2307             p_largest_value,
2308             "-inf",
2309             Status::OK,
2310             Category::Infinity,
2311         ),
2312         (
2313             m_inf,
2314             m_largest_value,
2315             "-inf",
2316             Status::OK,
2317             Category::Infinity,
2318         ),
2319         (
2320             m_inf,
2321             p_smallest_value,
2322             "-inf",
2323             Status::OK,
2324             Category::Infinity,
2325         ),
2326         (
2327             m_inf,
2328             m_smallest_value,
2329             "-inf",
2330             Status::OK,
2331             Category::Infinity,
2332         ),
2333         (
2334             m_inf,
2335             p_smallest_normalized,
2336             "-inf",
2337             Status::OK,
2338             Category::Infinity,
2339         ),
2340         (
2341             m_inf,
2342             m_smallest_normalized,
2343             "-inf",
2344             Status::OK,
2345             Category::Infinity,
2346         ),
2347         (p_zero, p_inf, "inf", Status::OK, Category::Infinity),
2348         (p_zero, m_inf, "-inf", Status::OK, Category::Infinity),
2349         (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
2350         (p_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
2351         (p_zero, qnan, "nan", Status::OK, Category::NaN),
2352         /*
2353 // See Note 1.
2354 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2355         */
2356         (
2357             p_zero,
2358             p_normal_value,
2359             "0x1p+0",
2360             Status::OK,
2361             Category::Normal,
2362         ),
2363         (
2364             p_zero,
2365             m_normal_value,
2366             "-0x1p+0",
2367             Status::OK,
2368             Category::Normal,
2369         ),
2370         (
2371             p_zero,
2372             p_largest_value,
2373             "0x1.fffffep+127",
2374             Status::OK,
2375             Category::Normal,
2376         ),
2377         (
2378             p_zero,
2379             m_largest_value,
2380             "-0x1.fffffep+127",
2381             Status::OK,
2382             Category::Normal,
2383         ),
2384         (
2385             p_zero,
2386             p_smallest_value,
2387             "0x1p-149",
2388             Status::OK,
2389             Category::Normal,
2390         ),
2391         (
2392             p_zero,
2393             m_smallest_value,
2394             "-0x1p-149",
2395             Status::OK,
2396             Category::Normal,
2397         ),
2398         (
2399             p_zero,
2400             p_smallest_normalized,
2401             "0x1p-126",
2402             Status::OK,
2403             Category::Normal,
2404         ),
2405         (
2406             p_zero,
2407             m_smallest_normalized,
2408             "-0x1p-126",
2409             Status::OK,
2410             Category::Normal,
2411         ),
2412         (m_zero, p_inf, "inf", Status::OK, Category::Infinity),
2413         (m_zero, m_inf, "-inf", Status::OK, Category::Infinity),
2414         (m_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
2415         (m_zero, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2416         (m_zero, qnan, "nan", Status::OK, Category::NaN),
2417         /*
2418 // See Note 1.
2419 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2420         */
2421         (
2422             m_zero,
2423             p_normal_value,
2424             "0x1p+0",
2425             Status::OK,
2426             Category::Normal,
2427         ),
2428         (
2429             m_zero,
2430             m_normal_value,
2431             "-0x1p+0",
2432             Status::OK,
2433             Category::Normal,
2434         ),
2435         (
2436             m_zero,
2437             p_largest_value,
2438             "0x1.fffffep+127",
2439             Status::OK,
2440             Category::Normal,
2441         ),
2442         (
2443             m_zero,
2444             m_largest_value,
2445             "-0x1.fffffep+127",
2446             Status::OK,
2447             Category::Normal,
2448         ),
2449         (
2450             m_zero,
2451             p_smallest_value,
2452             "0x1p-149",
2453             Status::OK,
2454             Category::Normal,
2455         ),
2456         (
2457             m_zero,
2458             m_smallest_value,
2459             "-0x1p-149",
2460             Status::OK,
2461             Category::Normal,
2462         ),
2463         (
2464             m_zero,
2465             p_smallest_normalized,
2466             "0x1p-126",
2467             Status::OK,
2468             Category::Normal,
2469         ),
2470         (
2471             m_zero,
2472             m_smallest_normalized,
2473             "-0x1p-126",
2474             Status::OK,
2475             Category::Normal,
2476         ),
2477         (qnan, p_inf, "nan", Status::OK, Category::NaN),
2478         (qnan, m_inf, "nan", Status::OK, Category::NaN),
2479         (qnan, p_zero, "nan", Status::OK, Category::NaN),
2480         (qnan, m_zero, "nan", Status::OK, Category::NaN),
2481         (qnan, qnan, "nan", Status::OK, Category::NaN),
2482         /*
2483 // See Note 1.
2484 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
2485         */
2486         (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
2487         (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
2488         (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
2489         (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
2490         (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
2491         (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
2492         (
2493             qnan,
2494             p_smallest_normalized,
2495             "nan",
2496             Status::OK,
2497             Category::NaN,
2498         ),
2499         (
2500             qnan,
2501             m_smallest_normalized,
2502             "nan",
2503             Status::OK,
2504             Category::NaN,
2505         ),
2506         /*
2507 // See Note 1.
2508 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2509 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2510 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2511 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2512 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
2513 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
2514 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2515 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2516 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2517 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2518 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2519 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2520 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2521 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2522         */
2523         (p_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
2524         (
2525             p_normal_value,
2526             m_inf,
2527             "-inf",
2528             Status::OK,
2529             Category::Infinity,
2530         ),
2531         (
2532             p_normal_value,
2533             p_zero,
2534             "0x1p+0",
2535             Status::OK,
2536             Category::Normal,
2537         ),
2538         (
2539             p_normal_value,
2540             m_zero,
2541             "0x1p+0",
2542             Status::OK,
2543             Category::Normal,
2544         ),
2545         (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
2546         /*
2547 // See Note 1.
2548 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2549         */
2550         (
2551             p_normal_value,
2552             p_normal_value,
2553             "0x1p+1",
2554             Status::OK,
2555             Category::Normal,
2556         ),
2557         (
2558             p_normal_value,
2559             m_normal_value,
2560             "0x0p+0",
2561             Status::OK,
2562             Category::Zero,
2563         ),
2564         (
2565             p_normal_value,
2566             p_largest_value,
2567             "0x1.fffffep+127",
2568             Status::INEXACT,
2569             Category::Normal,
2570         ),
2571         (
2572             p_normal_value,
2573             m_largest_value,
2574             "-0x1.fffffep+127",
2575             Status::INEXACT,
2576             Category::Normal,
2577         ),
2578         (
2579             p_normal_value,
2580             p_smallest_value,
2581             "0x1p+0",
2582             Status::INEXACT,
2583             Category::Normal,
2584         ),
2585         (
2586             p_normal_value,
2587             m_smallest_value,
2588             "0x1p+0",
2589             Status::INEXACT,
2590             Category::Normal,
2591         ),
2592         (
2593             p_normal_value,
2594             p_smallest_normalized,
2595             "0x1p+0",
2596             Status::INEXACT,
2597             Category::Normal,
2598         ),
2599         (
2600             p_normal_value,
2601             m_smallest_normalized,
2602             "0x1p+0",
2603             Status::INEXACT,
2604             Category::Normal,
2605         ),
2606         (m_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
2607         (
2608             m_normal_value,
2609             m_inf,
2610             "-inf",
2611             Status::OK,
2612             Category::Infinity,
2613         ),
2614         (
2615             m_normal_value,
2616             p_zero,
2617             "-0x1p+0",
2618             Status::OK,
2619             Category::Normal,
2620         ),
2621         (
2622             m_normal_value,
2623             m_zero,
2624             "-0x1p+0",
2625             Status::OK,
2626             Category::Normal,
2627         ),
2628         (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
2629         /*
2630 // See Note 1.
2631 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2632         */
2633         (
2634             m_normal_value,
2635             p_normal_value,
2636             "0x0p+0",
2637             Status::OK,
2638             Category::Zero,
2639         ),
2640         (
2641             m_normal_value,
2642             m_normal_value,
2643             "-0x1p+1",
2644             Status::OK,
2645             Category::Normal,
2646         ),
2647         (
2648             m_normal_value,
2649             p_largest_value,
2650             "0x1.fffffep+127",
2651             Status::INEXACT,
2652             Category::Normal,
2653         ),
2654         (
2655             m_normal_value,
2656             m_largest_value,
2657             "-0x1.fffffep+127",
2658             Status::INEXACT,
2659             Category::Normal,
2660         ),
2661         (
2662             m_normal_value,
2663             p_smallest_value,
2664             "-0x1p+0",
2665             Status::INEXACT,
2666             Category::Normal,
2667         ),
2668         (
2669             m_normal_value,
2670             m_smallest_value,
2671             "-0x1p+0",
2672             Status::INEXACT,
2673             Category::Normal,
2674         ),
2675         (
2676             m_normal_value,
2677             p_smallest_normalized,
2678             "-0x1p+0",
2679             Status::INEXACT,
2680             Category::Normal,
2681         ),
2682         (
2683             m_normal_value,
2684             m_smallest_normalized,
2685             "-0x1p+0",
2686             Status::INEXACT,
2687             Category::Normal,
2688         ),
2689         (
2690             p_largest_value,
2691             p_inf,
2692             "inf",
2693             Status::OK,
2694             Category::Infinity,
2695         ),
2696         (
2697             p_largest_value,
2698             m_inf,
2699             "-inf",
2700             Status::OK,
2701             Category::Infinity,
2702         ),
2703         (
2704             p_largest_value,
2705             p_zero,
2706             "0x1.fffffep+127",
2707             Status::OK,
2708             Category::Normal,
2709         ),
2710         (
2711             p_largest_value,
2712             m_zero,
2713             "0x1.fffffep+127",
2714             Status::OK,
2715             Category::Normal,
2716         ),
2717         (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
2718         /*
2719 // See Note 1.
2720 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2721         */
2722         (
2723             p_largest_value,
2724             p_normal_value,
2725             "0x1.fffffep+127",
2726             Status::INEXACT,
2727             Category::Normal,
2728         ),
2729         (
2730             p_largest_value,
2731             m_normal_value,
2732             "0x1.fffffep+127",
2733             Status::INEXACT,
2734             Category::Normal,
2735         ),
2736         (
2737             p_largest_value,
2738             p_largest_value,
2739             "inf",
2740             overflow_status,
2741             Category::Infinity,
2742         ),
2743         (
2744             p_largest_value,
2745             m_largest_value,
2746             "0x0p+0",
2747             Status::OK,
2748             Category::Zero,
2749         ),
2750         (
2751             p_largest_value,
2752             p_smallest_value,
2753             "0x1.fffffep+127",
2754             Status::INEXACT,
2755             Category::Normal,
2756         ),
2757         (
2758             p_largest_value,
2759             m_smallest_value,
2760             "0x1.fffffep+127",
2761             Status::INEXACT,
2762             Category::Normal,
2763         ),
2764         (
2765             p_largest_value,
2766             p_smallest_normalized,
2767             "0x1.fffffep+127",
2768             Status::INEXACT,
2769             Category::Normal,
2770         ),
2771         (
2772             p_largest_value,
2773             m_smallest_normalized,
2774             "0x1.fffffep+127",
2775             Status::INEXACT,
2776             Category::Normal,
2777         ),
2778         (
2779             m_largest_value,
2780             p_inf,
2781             "inf",
2782             Status::OK,
2783             Category::Infinity,
2784         ),
2785         (
2786             m_largest_value,
2787             m_inf,
2788             "-inf",
2789             Status::OK,
2790             Category::Infinity,
2791         ),
2792         (
2793             m_largest_value,
2794             p_zero,
2795             "-0x1.fffffep+127",
2796             Status::OK,
2797             Category::Normal,
2798         ),
2799         (
2800             m_largest_value,
2801             m_zero,
2802             "-0x1.fffffep+127",
2803             Status::OK,
2804             Category::Normal,
2805         ),
2806         (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
2807         /*
2808 // See Note 1.
2809 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2810         */
2811         (
2812             m_largest_value,
2813             p_normal_value,
2814             "-0x1.fffffep+127",
2815             Status::INEXACT,
2816             Category::Normal,
2817         ),
2818         (
2819             m_largest_value,
2820             m_normal_value,
2821             "-0x1.fffffep+127",
2822             Status::INEXACT,
2823             Category::Normal,
2824         ),
2825         (
2826             m_largest_value,
2827             p_largest_value,
2828             "0x0p+0",
2829             Status::OK,
2830             Category::Zero,
2831         ),
2832         (
2833             m_largest_value,
2834             m_largest_value,
2835             "-inf",
2836             overflow_status,
2837             Category::Infinity,
2838         ),
2839         (
2840             m_largest_value,
2841             p_smallest_value,
2842             "-0x1.fffffep+127",
2843             Status::INEXACT,
2844             Category::Normal,
2845         ),
2846         (
2847             m_largest_value,
2848             m_smallest_value,
2849             "-0x1.fffffep+127",
2850             Status::INEXACT,
2851             Category::Normal,
2852         ),
2853         (
2854             m_largest_value,
2855             p_smallest_normalized,
2856             "-0x1.fffffep+127",
2857             Status::INEXACT,
2858             Category::Normal,
2859         ),
2860         (
2861             m_largest_value,
2862             m_smallest_normalized,
2863             "-0x1.fffffep+127",
2864             Status::INEXACT,
2865             Category::Normal,
2866         ),
2867         (
2868             p_smallest_value,
2869             p_inf,
2870             "inf",
2871             Status::OK,
2872             Category::Infinity,
2873         ),
2874         (
2875             p_smallest_value,
2876             m_inf,
2877             "-inf",
2878             Status::OK,
2879             Category::Infinity,
2880         ),
2881         (
2882             p_smallest_value,
2883             p_zero,
2884             "0x1p-149",
2885             Status::OK,
2886             Category::Normal,
2887         ),
2888         (
2889             p_smallest_value,
2890             m_zero,
2891             "0x1p-149",
2892             Status::OK,
2893             Category::Normal,
2894         ),
2895         (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2896         /*
2897 // See Note 1.
2898 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2899         */
2900         (
2901             p_smallest_value,
2902             p_normal_value,
2903             "0x1p+0",
2904             Status::INEXACT,
2905             Category::Normal,
2906         ),
2907         (
2908             p_smallest_value,
2909             m_normal_value,
2910             "-0x1p+0",
2911             Status::INEXACT,
2912             Category::Normal,
2913         ),
2914         (
2915             p_smallest_value,
2916             p_largest_value,
2917             "0x1.fffffep+127",
2918             Status::INEXACT,
2919             Category::Normal,
2920         ),
2921         (
2922             p_smallest_value,
2923             m_largest_value,
2924             "-0x1.fffffep+127",
2925             Status::INEXACT,
2926             Category::Normal,
2927         ),
2928         (
2929             p_smallest_value,
2930             p_smallest_value,
2931             "0x1p-148",
2932             Status::OK,
2933             Category::Normal,
2934         ),
2935         (
2936             p_smallest_value,
2937             m_smallest_value,
2938             "0x0p+0",
2939             Status::OK,
2940             Category::Zero,
2941         ),
2942         (
2943             p_smallest_value,
2944             p_smallest_normalized,
2945             "0x1.000002p-126",
2946             Status::OK,
2947             Category::Normal,
2948         ),
2949         (
2950             p_smallest_value,
2951             m_smallest_normalized,
2952             "-0x1.fffffcp-127",
2953             Status::OK,
2954             Category::Normal,
2955         ),
2956         (
2957             m_smallest_value,
2958             p_inf,
2959             "inf",
2960             Status::OK,
2961             Category::Infinity,
2962         ),
2963         (
2964             m_smallest_value,
2965             m_inf,
2966             "-inf",
2967             Status::OK,
2968             Category::Infinity,
2969         ),
2970         (
2971             m_smallest_value,
2972             p_zero,
2973             "-0x1p-149",
2974             Status::OK,
2975             Category::Normal,
2976         ),
2977         (
2978             m_smallest_value,
2979             m_zero,
2980             "-0x1p-149",
2981             Status::OK,
2982             Category::Normal,
2983         ),
2984         (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2985         /*
2986 // See Note 1.
2987 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2988         */
2989         (
2990             m_smallest_value,
2991             p_normal_value,
2992             "0x1p+0",
2993             Status::INEXACT,
2994             Category::Normal,
2995         ),
2996         (
2997             m_smallest_value,
2998             m_normal_value,
2999             "-0x1p+0",
3000             Status::INEXACT,
3001             Category::Normal,
3002         ),
3003         (
3004             m_smallest_value,
3005             p_largest_value,
3006             "0x1.fffffep+127",
3007             Status::INEXACT,
3008             Category::Normal,
3009         ),
3010         (
3011             m_smallest_value,
3012             m_largest_value,
3013             "-0x1.fffffep+127",
3014             Status::INEXACT,
3015             Category::Normal,
3016         ),
3017         (
3018             m_smallest_value,
3019             p_smallest_value,
3020             "0x0p+0",
3021             Status::OK,
3022             Category::Zero,
3023         ),
3024         (
3025             m_smallest_value,
3026             m_smallest_value,
3027             "-0x1p-148",
3028             Status::OK,
3029             Category::Normal,
3030         ),
3031         (
3032             m_smallest_value,
3033             p_smallest_normalized,
3034             "0x1.fffffcp-127",
3035             Status::OK,
3036             Category::Normal,
3037         ),
3038         (
3039             m_smallest_value,
3040             m_smallest_normalized,
3041             "-0x1.000002p-126",
3042             Status::OK,
3043             Category::Normal,
3044         ),
3045         (
3046             p_smallest_normalized,
3047             p_inf,
3048             "inf",
3049             Status::OK,
3050             Category::Infinity,
3051         ),
3052         (
3053             p_smallest_normalized,
3054             m_inf,
3055             "-inf",
3056             Status::OK,
3057             Category::Infinity,
3058         ),
3059         (
3060             p_smallest_normalized,
3061             p_zero,
3062             "0x1p-126",
3063             Status::OK,
3064             Category::Normal,
3065         ),
3066         (
3067             p_smallest_normalized,
3068             m_zero,
3069             "0x1p-126",
3070             Status::OK,
3071             Category::Normal,
3072         ),
3073         (
3074             p_smallest_normalized,
3075             qnan,
3076             "nan",
3077             Status::OK,
3078             Category::NaN,
3079         ),
3080         /*
3081 // See Note 1.
3082 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
3083         */
3084         (
3085             p_smallest_normalized,
3086             p_normal_value,
3087             "0x1p+0",
3088             Status::INEXACT,
3089             Category::Normal,
3090         ),
3091         (
3092             p_smallest_normalized,
3093             m_normal_value,
3094             "-0x1p+0",
3095             Status::INEXACT,
3096             Category::Normal,
3097         ),
3098         (
3099             p_smallest_normalized,
3100             p_largest_value,
3101             "0x1.fffffep+127",
3102             Status::INEXACT,
3103             Category::Normal,
3104         ),
3105         (
3106             p_smallest_normalized,
3107             m_largest_value,
3108             "-0x1.fffffep+127",
3109             Status::INEXACT,
3110             Category::Normal,
3111         ),
3112         (
3113             p_smallest_normalized,
3114             p_smallest_value,
3115             "0x1.000002p-126",
3116             Status::OK,
3117             Category::Normal,
3118         ),
3119         (
3120             p_smallest_normalized,
3121             m_smallest_value,
3122             "0x1.fffffcp-127",
3123             Status::OK,
3124             Category::Normal,
3125         ),
3126         (
3127             p_smallest_normalized,
3128             p_smallest_normalized,
3129             "0x1p-125",
3130             Status::OK,
3131             Category::Normal,
3132         ),
3133         (
3134             p_smallest_normalized,
3135             m_smallest_normalized,
3136             "0x0p+0",
3137             Status::OK,
3138             Category::Zero,
3139         ),
3140         (
3141             m_smallest_normalized,
3142             p_inf,
3143             "inf",
3144             Status::OK,
3145             Category::Infinity,
3146         ),
3147         (
3148             m_smallest_normalized,
3149             m_inf,
3150             "-inf",
3151             Status::OK,
3152             Category::Infinity,
3153         ),
3154         (
3155             m_smallest_normalized,
3156             p_zero,
3157             "-0x1p-126",
3158             Status::OK,
3159             Category::Normal,
3160         ),
3161         (
3162             m_smallest_normalized,
3163             m_zero,
3164             "-0x1p-126",
3165             Status::OK,
3166             Category::Normal,
3167         ),
3168         (
3169             m_smallest_normalized,
3170             qnan,
3171             "nan",
3172             Status::OK,
3173             Category::NaN,
3174         ),
3175         /*
3176 // See Note 1.
3177 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
3178         */
3179         (
3180             m_smallest_normalized,
3181             p_normal_value,
3182             "0x1p+0",
3183             Status::INEXACT,
3184             Category::Normal,
3185         ),
3186         (
3187             m_smallest_normalized,
3188             m_normal_value,
3189             "-0x1p+0",
3190             Status::INEXACT,
3191             Category::Normal,
3192         ),
3193         (
3194             m_smallest_normalized,
3195             p_largest_value,
3196             "0x1.fffffep+127",
3197             Status::INEXACT,
3198             Category::Normal,
3199         ),
3200         (
3201             m_smallest_normalized,
3202             m_largest_value,
3203             "-0x1.fffffep+127",
3204             Status::INEXACT,
3205             Category::Normal,
3206         ),
3207         (
3208             m_smallest_normalized,
3209             p_smallest_value,
3210             "-0x1.fffffcp-127",
3211             Status::OK,
3212             Category::Normal,
3213         ),
3214         (
3215             m_smallest_normalized,
3216             m_smallest_value,
3217             "-0x1.000002p-126",
3218             Status::OK,
3219             Category::Normal,
3220         ),
3221         (
3222             m_smallest_normalized,
3223             p_smallest_normalized,
3224             "0x0p+0",
3225             Status::OK,
3226             Category::Zero,
3227         ),
3228         (
3229             m_smallest_normalized,
3230             m_smallest_normalized,
3231             "-0x1p-125",
3232             Status::OK,
3233             Category::Normal,
3234         ),
3235     ];
3236
3237     for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
3238         let status;
3239         let result = unpack!(status=, x + y);
3240         assert_eq!(status, e_status);
3241         assert_eq!(result.category(), e_category);
3242         assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
3243     }
3244 }
3245
3246 #[test]
3247 fn subtract() {
3248     // Test Special Cases against each other and normal values.
3249
3250     // FIXMES/NOTES:
3251     // 1. Since we perform only default exception handling all operations with
3252     // signaling NaNs should have a result that is a quiet NaN. Currently they
3253     // return sNaN.
3254
3255     let p_inf = Single::INFINITY;
3256     let m_inf = -Single::INFINITY;
3257     let p_zero = Single::ZERO;
3258     let m_zero = -Single::ZERO;
3259     let qnan = Single::NAN;
3260     let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
3261     let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
3262     let p_largest_value = Single::largest();
3263     let m_largest_value = -Single::largest();
3264     let p_smallest_value = Single::SMALLEST;
3265     let m_smallest_value = -Single::SMALLEST;
3266     let p_smallest_normalized = Single::smallest_normalized();
3267     let m_smallest_normalized = -Single::smallest_normalized();
3268
3269     let overflow_status = Status::OVERFLOW | Status::INEXACT;
3270
3271     let special_cases = [
3272         (p_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
3273         (p_inf, m_inf, "inf", Status::OK, Category::Infinity),
3274         (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
3275         (p_inf, m_zero, "inf", Status::OK, Category::Infinity),
3276         (p_inf, qnan, "-nan", Status::OK, Category::NaN),
3277         /*
3278 // See Note 1.
3279 (p_inf, snan, "-nan", Status::INVALID_OP, Category::NaN),
3280         */
3281         (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
3282         (p_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
3283         (
3284             p_inf,
3285             p_largest_value,
3286             "inf",
3287             Status::OK,
3288             Category::Infinity,
3289         ),
3290         (
3291             p_inf,
3292             m_largest_value,
3293             "inf",
3294             Status::OK,
3295             Category::Infinity,
3296         ),
3297         (
3298             p_inf,
3299             p_smallest_value,
3300             "inf",
3301             Status::OK,
3302             Category::Infinity,
3303         ),
3304         (
3305             p_inf,
3306             m_smallest_value,
3307             "inf",
3308             Status::OK,
3309             Category::Infinity,
3310         ),
3311         (
3312             p_inf,
3313             p_smallest_normalized,
3314             "inf",
3315             Status::OK,
3316             Category::Infinity,
3317         ),
3318         (
3319             p_inf,
3320             m_smallest_normalized,
3321             "inf",
3322             Status::OK,
3323             Category::Infinity,
3324         ),
3325         (m_inf, p_inf, "-inf", Status::OK, Category::Infinity),
3326         (m_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
3327         (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
3328         (m_inf, m_zero, "-inf", Status::OK, Category::Infinity),
3329         (m_inf, qnan, "-nan", Status::OK, Category::NaN),
3330         /*
3331 // See Note 1.
3332 (m_inf, snan, "-nan", Status::INVALID_OP, Category::NaN),
3333         */
3334         (
3335             m_inf,
3336             p_normal_value,
3337             "-inf",
3338             Status::OK,
3339             Category::Infinity,
3340         ),
3341         (
3342             m_inf,
3343             m_normal_value,
3344             "-inf",
3345             Status::OK,
3346             Category::Infinity,
3347         ),
3348         (
3349             m_inf,
3350             p_largest_value,
3351             "-inf",
3352             Status::OK,
3353             Category::Infinity,
3354         ),
3355         (
3356             m_inf,
3357             m_largest_value,
3358             "-inf",
3359             Status::OK,
3360             Category::Infinity,
3361         ),
3362         (
3363             m_inf,
3364             p_smallest_value,
3365             "-inf",
3366             Status::OK,
3367             Category::Infinity,
3368         ),
3369         (
3370             m_inf,
3371             m_smallest_value,
3372             "-inf",
3373             Status::OK,
3374             Category::Infinity,
3375         ),
3376         (
3377             m_inf,
3378             p_smallest_normalized,
3379             "-inf",
3380             Status::OK,
3381             Category::Infinity,
3382         ),
3383         (
3384             m_inf,
3385             m_smallest_normalized,
3386             "-inf",
3387             Status::OK,
3388             Category::Infinity,
3389         ),
3390         (p_zero, p_inf, "-inf", Status::OK, Category::Infinity),
3391         (p_zero, m_inf, "inf", Status::OK, Category::Infinity),
3392         (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
3393         (p_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
3394         (p_zero, qnan, "-nan", Status::OK, Category::NaN),
3395         /*
3396 // See Note 1.
3397 (p_zero, snan, "-nan", Status::INVALID_OP, Category::NaN),
3398         */
3399         (
3400             p_zero,
3401             p_normal_value,
3402             "-0x1p+0",
3403             Status::OK,
3404             Category::Normal,
3405         ),
3406         (
3407             p_zero,
3408             m_normal_value,
3409             "0x1p+0",
3410             Status::OK,
3411             Category::Normal,
3412         ),
3413         (
3414             p_zero,
3415             p_largest_value,
3416             "-0x1.fffffep+127",
3417             Status::OK,
3418             Category::Normal,
3419         ),
3420         (
3421             p_zero,
3422             m_largest_value,
3423             "0x1.fffffep+127",
3424             Status::OK,
3425             Category::Normal,
3426         ),
3427         (
3428             p_zero,
3429             p_smallest_value,
3430             "-0x1p-149",
3431             Status::OK,
3432             Category::Normal,
3433         ),
3434         (
3435             p_zero,
3436             m_smallest_value,
3437             "0x1p-149",
3438             Status::OK,
3439             Category::Normal,
3440         ),
3441         (
3442             p_zero,
3443             p_smallest_normalized,
3444             "-0x1p-126",
3445             Status::OK,
3446             Category::Normal,
3447         ),
3448         (
3449             p_zero,
3450             m_smallest_normalized,
3451             "0x1p-126",
3452             Status::OK,
3453             Category::Normal,
3454         ),
3455         (m_zero, p_inf, "-inf", Status::OK, Category::Infinity),
3456         (m_zero, m_inf, "inf", Status::OK, Category::Infinity),
3457         (m_zero, p_zero, "-0x0p+0", Status::OK, Category::Zero),
3458         (m_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
3459         (m_zero, qnan, "-nan", Status::OK, Category::NaN),
3460         /*
3461 // See Note 1.
3462 (m_zero, snan, "-nan", Status::INVALID_OP, Category::NaN),
3463         */
3464         (
3465             m_zero,
3466             p_normal_value,
3467             "-0x1p+0",
3468             Status::OK,
3469             Category::Normal,
3470         ),
3471         (
3472             m_zero,
3473             m_normal_value,
3474             "0x1p+0",
3475             Status::OK,
3476             Category::Normal,
3477         ),
3478         (
3479             m_zero,
3480             p_largest_value,
3481             "-0x1.fffffep+127",
3482             Status::OK,
3483             Category::Normal,
3484         ),
3485         (
3486             m_zero,
3487             m_largest_value,
3488             "0x1.fffffep+127",
3489             Status::OK,
3490             Category::Normal,
3491         ),
3492         (
3493             m_zero,
3494             p_smallest_value,
3495             "-0x1p-149",
3496             Status::OK,
3497             Category::Normal,
3498         ),
3499         (
3500             m_zero,
3501             m_smallest_value,
3502             "0x1p-149",
3503             Status::OK,
3504             Category::Normal,
3505         ),
3506         (
3507             m_zero,
3508             p_smallest_normalized,
3509             "-0x1p-126",
3510             Status::OK,
3511             Category::Normal,
3512         ),
3513         (
3514             m_zero,
3515             m_smallest_normalized,
3516             "0x1p-126",
3517             Status::OK,
3518             Category::Normal,
3519         ),
3520         (qnan, p_inf, "nan", Status::OK, Category::NaN),
3521         (qnan, m_inf, "nan", Status::OK, Category::NaN),
3522         (qnan, p_zero, "nan", Status::OK, Category::NaN),
3523         (qnan, m_zero, "nan", Status::OK, Category::NaN),
3524         (qnan, qnan, "nan", Status::OK, Category::NaN),
3525         /*
3526 // See Note 1.
3527 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
3528         */
3529         (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
3530         (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
3531         (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
3532         (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
3533         (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
3534         (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
3535         (
3536             qnan,
3537             p_smallest_normalized,
3538             "nan",
3539             Status::OK,
3540             Category::NaN,
3541         ),
3542         (
3543             qnan,
3544             m_smallest_normalized,
3545             "nan",
3546             Status::OK,
3547             Category::NaN,
3548         ),
3549         /*
3550 // See Note 1.
3551 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
3552 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
3553 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
3554 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
3555 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
3556 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
3557 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
3558 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
3559 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
3560 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
3561 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
3562 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
3563 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
3564 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
3565         */
3566         (
3567             p_normal_value,
3568             p_inf,
3569             "-inf",
3570             Status::OK,
3571             Category::Infinity,
3572         ),
3573         (p_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
3574         (
3575             p_normal_value,
3576             p_zero,
3577             "0x1p+0",
3578             Status::OK,
3579             Category::Normal,
3580         ),
3581         (
3582             p_normal_value,
3583             m_zero,
3584             "0x1p+0",
3585             Status::OK,
3586             Category::Normal,
3587         ),
3588         (p_normal_value, qnan, "-nan", Status::OK, Category::NaN),
3589         /*
3590 // See Note 1.
3591 (p_normal_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
3592         */
3593         (
3594             p_normal_value,
3595             p_normal_value,
3596             "0x0p+0",
3597             Status::OK,
3598             Category::Zero,
3599         ),
3600         (
3601             p_normal_value,
3602             m_normal_value,
3603             "0x1p+1",
3604             Status::OK,
3605             Category::Normal,
3606         ),
3607         (
3608             p_normal_value,
3609             p_largest_value,
3610             "-0x1.fffffep+127",
3611             Status::INEXACT,
3612             Category::Normal,
3613         ),
3614         (
3615             p_normal_value,
3616             m_largest_value,
3617             "0x1.fffffep+127",
3618             Status::INEXACT,
3619             Category::Normal,
3620         ),
3621         (
3622             p_normal_value,
3623             p_smallest_value,
3624             "0x1p+0",
3625             Status::INEXACT,
3626             Category::Normal,
3627         ),
3628         (
3629             p_normal_value,
3630             m_smallest_value,
3631             "0x1p+0",
3632             Status::INEXACT,
3633             Category::Normal,
3634         ),
3635         (
3636             p_normal_value,
3637             p_smallest_normalized,
3638             "0x1p+0",
3639             Status::INEXACT,
3640             Category::Normal,
3641         ),
3642         (
3643             p_normal_value,
3644             m_smallest_normalized,
3645             "0x1p+0",
3646             Status::INEXACT,
3647             Category::Normal,
3648         ),
3649         (
3650             m_normal_value,
3651             p_inf,
3652             "-inf",
3653             Status::OK,
3654             Category::Infinity,
3655         ),
3656         (m_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
3657         (
3658             m_normal_value,
3659             p_zero,
3660             "-0x1p+0",
3661             Status::OK,
3662             Category::Normal,
3663         ),
3664         (
3665             m_normal_value,
3666             m_zero,
3667             "-0x1p+0",
3668             Status::OK,
3669             Category::Normal,
3670         ),
3671         (m_normal_value, qnan, "-nan", Status::OK, Category::NaN),
3672         /*
3673 // See Note 1.
3674 (m_normal_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
3675         */
3676         (
3677             m_normal_value,
3678             p_normal_value,
3679             "-0x1p+1",
3680             Status::OK,
3681             Category::Normal,
3682         ),
3683         (
3684             m_normal_value,
3685             m_normal_value,
3686             "0x0p+0",
3687             Status::OK,
3688             Category::Zero,
3689         ),
3690         (
3691             m_normal_value,
3692             p_largest_value,
3693             "-0x1.fffffep+127",
3694             Status::INEXACT,
3695             Category::Normal,
3696         ),
3697         (
3698             m_normal_value,
3699             m_largest_value,
3700             "0x1.fffffep+127",
3701             Status::INEXACT,
3702             Category::Normal,
3703         ),
3704         (
3705             m_normal_value,
3706             p_smallest_value,
3707             "-0x1p+0",
3708             Status::INEXACT,
3709             Category::Normal,
3710         ),
3711         (
3712             m_normal_value,
3713             m_smallest_value,
3714             "-0x1p+0",
3715             Status::INEXACT,
3716             Category::Normal,
3717         ),
3718         (
3719             m_normal_value,
3720             p_smallest_normalized,
3721             "-0x1p+0",
3722             Status::INEXACT,
3723             Category::Normal,
3724         ),
3725         (
3726             m_normal_value,
3727             m_smallest_normalized,
3728             "-0x1p+0",
3729             Status::INEXACT,
3730             Category::Normal,
3731         ),
3732         (
3733             p_largest_value,
3734             p_inf,
3735             "-inf",
3736             Status::OK,
3737             Category::Infinity,
3738         ),
3739         (
3740             p_largest_value,
3741             m_inf,
3742             "inf",
3743             Status::OK,
3744             Category::Infinity,
3745         ),
3746         (
3747             p_largest_value,
3748             p_zero,
3749             "0x1.fffffep+127",
3750             Status::OK,
3751             Category::Normal,
3752         ),
3753         (
3754             p_largest_value,
3755             m_zero,
3756             "0x1.fffffep+127",
3757             Status::OK,
3758             Category::Normal,
3759         ),
3760         (p_largest_value, qnan, "-nan", Status::OK, Category::NaN),
3761         /*
3762 // See Note 1.
3763 (p_largest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
3764         */
3765         (
3766             p_largest_value,
3767             p_normal_value,
3768             "0x1.fffffep+127",
3769             Status::INEXACT,
3770             Category::Normal,
3771         ),
3772         (
3773             p_largest_value,
3774             m_normal_value,
3775             "0x1.fffffep+127",
3776             Status::INEXACT,
3777             Category::Normal,
3778         ),
3779         (
3780             p_largest_value,
3781             p_largest_value,
3782             "0x0p+0",
3783             Status::OK,
3784             Category::Zero,
3785         ),
3786         (
3787             p_largest_value,
3788             m_largest_value,
3789             "inf",
3790             overflow_status,
3791             Category::Infinity,
3792         ),
3793         (
3794             p_largest_value,
3795             p_smallest_value,
3796             "0x1.fffffep+127",
3797             Status::INEXACT,
3798             Category::Normal,
3799         ),
3800         (
3801             p_largest_value,
3802             m_smallest_value,
3803             "0x1.fffffep+127",
3804             Status::INEXACT,
3805             Category::Normal,
3806         ),
3807         (
3808             p_largest_value,
3809             p_smallest_normalized,
3810             "0x1.fffffep+127",
3811             Status::INEXACT,
3812             Category::Normal,
3813         ),
3814         (
3815             p_largest_value,
3816             m_smallest_normalized,
3817             "0x1.fffffep+127",
3818             Status::INEXACT,
3819             Category::Normal,
3820         ),
3821         (
3822             m_largest_value,
3823             p_inf,
3824             "-inf",
3825             Status::OK,
3826             Category::Infinity,
3827         ),
3828         (
3829             m_largest_value,
3830             m_inf,
3831             "inf",
3832             Status::OK,
3833             Category::Infinity,
3834         ),
3835         (
3836             m_largest_value,
3837             p_zero,
3838             "-0x1.fffffep+127",
3839             Status::OK,
3840             Category::Normal,
3841         ),
3842         (
3843             m_largest_value,
3844             m_zero,
3845             "-0x1.fffffep+127",
3846             Status::OK,
3847             Category::Normal,
3848         ),
3849         (m_largest_value, qnan, "-nan", Status::OK, Category::NaN),
3850         /*
3851 // See Note 1.
3852 (m_largest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
3853         */
3854         (
3855             m_largest_value,
3856             p_normal_value,
3857             "-0x1.fffffep+127",
3858             Status::INEXACT,
3859             Category::Normal,
3860         ),
3861         (
3862             m_largest_value,
3863             m_normal_value,
3864             "-0x1.fffffep+127",
3865             Status::INEXACT,
3866             Category::Normal,
3867         ),
3868         (
3869             m_largest_value,
3870             p_largest_value,
3871             "-inf",
3872             overflow_status,
3873             Category::Infinity,
3874         ),
3875         (
3876             m_largest_value,
3877             m_largest_value,
3878             "0x0p+0",
3879             Status::OK,
3880             Category::Zero,
3881         ),
3882         (
3883             m_largest_value,
3884             p_smallest_value,
3885             "-0x1.fffffep+127",
3886             Status::INEXACT,
3887             Category::Normal,
3888         ),
3889         (
3890             m_largest_value,
3891             m_smallest_value,
3892             "-0x1.fffffep+127",
3893             Status::INEXACT,
3894             Category::Normal,
3895         ),
3896         (
3897             m_largest_value,
3898             p_smallest_normalized,
3899             "-0x1.fffffep+127",
3900             Status::INEXACT,
3901             Category::Normal,
3902         ),
3903         (
3904             m_largest_value,
3905             m_smallest_normalized,
3906             "-0x1.fffffep+127",
3907             Status::INEXACT,
3908             Category::Normal,
3909         ),
3910         (
3911             p_smallest_value,
3912             p_inf,
3913             "-inf",
3914             Status::OK,
3915             Category::Infinity,
3916         ),
3917         (
3918             p_smallest_value,
3919             m_inf,
3920             "inf",
3921             Status::OK,
3922             Category::Infinity,
3923         ),
3924         (
3925             p_smallest_value,
3926             p_zero,
3927             "0x1p-149",
3928             Status::OK,
3929             Category::Normal,
3930         ),
3931         (
3932             p_smallest_value,
3933             m_zero,
3934             "0x1p-149",
3935             Status::OK,
3936             Category::Normal,
3937         ),
3938         (p_smallest_value, qnan, "-nan", Status::OK, Category::NaN),
3939         /*
3940 // See Note 1.
3941 (p_smallest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
3942         */
3943         (
3944             p_smallest_value,
3945             p_normal_value,
3946             "-0x1p+0",
3947             Status::INEXACT,
3948             Category::Normal,
3949         ),
3950         (
3951             p_smallest_value,
3952             m_normal_value,
3953             "0x1p+0",
3954             Status::INEXACT,
3955             Category::Normal,
3956         ),
3957         (
3958             p_smallest_value,
3959             p_largest_value,
3960             "-0x1.fffffep+127",
3961             Status::INEXACT,
3962             Category::Normal,
3963         ),
3964         (
3965             p_smallest_value,
3966             m_largest_value,
3967             "0x1.fffffep+127",
3968             Status::INEXACT,
3969             Category::Normal,
3970         ),
3971         (
3972             p_smallest_value,
3973             p_smallest_value,
3974             "0x0p+0",
3975             Status::OK,
3976             Category::Zero,
3977         ),
3978         (
3979             p_smallest_value,
3980             m_smallest_value,
3981             "0x1p-148",
3982             Status::OK,
3983             Category::Normal,
3984         ),
3985         (
3986             p_smallest_value,
3987             p_smallest_normalized,
3988             "-0x1.fffffcp-127",
3989             Status::OK,
3990             Category::Normal,
3991         ),
3992         (
3993             p_smallest_value,
3994             m_smallest_normalized,
3995             "0x1.000002p-126",
3996             Status::OK,
3997             Category::Normal,
3998         ),
3999         (
4000             m_smallest_value,
4001             p_inf,
4002             "-inf",
4003             Status::OK,
4004             Category::Infinity,
4005         ),
4006         (
4007             m_smallest_value,
4008             m_inf,
4009             "inf",
4010             Status::OK,
4011             Category::Infinity,
4012         ),
4013         (
4014             m_smallest_value,
4015             p_zero,
4016             "-0x1p-149",
4017             Status::OK,
4018             Category::Normal,
4019         ),
4020         (
4021             m_smallest_value,
4022             m_zero,
4023             "-0x1p-149",
4024             Status::OK,
4025             Category::Normal,
4026         ),
4027         (m_smallest_value, qnan, "-nan", Status::OK, Category::NaN),
4028         /*
4029 // See Note 1.
4030 (m_smallest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
4031         */
4032         (
4033             m_smallest_value,
4034             p_normal_value,
4035             "-0x1p+0",
4036             Status::INEXACT,
4037             Category::Normal,
4038         ),
4039         (
4040             m_smallest_value,
4041             m_normal_value,
4042             "0x1p+0",
4043             Status::INEXACT,
4044             Category::Normal,
4045         ),
4046         (
4047             m_smallest_value,
4048             p_largest_value,
4049             "-0x1.fffffep+127",
4050             Status::INEXACT,
4051             Category::Normal,
4052         ),
4053         (
4054             m_smallest_value,
4055             m_largest_value,
4056             "0x1.fffffep+127",
4057             Status::INEXACT,
4058             Category::Normal,
4059         ),
4060         (
4061             m_smallest_value,
4062             p_smallest_value,
4063             "-0x1p-148",
4064             Status::OK,
4065             Category::Normal,
4066         ),
4067         (
4068             m_smallest_value,
4069             m_smallest_value,
4070             "0x0p+0",
4071             Status::OK,
4072             Category::Zero,
4073         ),
4074         (
4075             m_smallest_value,
4076             p_smallest_normalized,
4077             "-0x1.000002p-126",
4078             Status::OK,
4079             Category::Normal,
4080         ),
4081         (
4082             m_smallest_value,
4083             m_smallest_normalized,
4084             "0x1.fffffcp-127",
4085             Status::OK,
4086             Category::Normal,
4087         ),
4088         (
4089             p_smallest_normalized,
4090             p_inf,
4091             "-inf",
4092             Status::OK,
4093             Category::Infinity,
4094         ),
4095         (
4096             p_smallest_normalized,
4097             m_inf,
4098             "inf",
4099             Status::OK,
4100             Category::Infinity,
4101         ),
4102         (
4103             p_smallest_normalized,
4104             p_zero,
4105             "0x1p-126",
4106             Status::OK,
4107             Category::Normal,
4108         ),
4109         (
4110             p_smallest_normalized,
4111             m_zero,
4112             "0x1p-126",
4113             Status::OK,
4114             Category::Normal,
4115         ),
4116         (
4117             p_smallest_normalized,
4118             qnan,
4119             "-nan",
4120             Status::OK,
4121             Category::NaN,
4122         ),
4123         /*
4124 // See Note 1.
4125 (p_smallest_normalized, snan, "-nan", Status::INVALID_OP, Category::NaN),
4126         */
4127         (
4128             p_smallest_normalized,
4129             p_normal_value,
4130             "-0x1p+0",
4131             Status::INEXACT,
4132             Category::Normal,
4133         ),
4134         (
4135             p_smallest_normalized,
4136             m_normal_value,
4137             "0x1p+0",
4138             Status::INEXACT,
4139             Category::Normal,
4140         ),
4141         (
4142             p_smallest_normalized,
4143             p_largest_value,
4144             "-0x1.fffffep+127",
4145             Status::INEXACT,
4146             Category::Normal,
4147         ),
4148         (
4149             p_smallest_normalized,
4150             m_largest_value,
4151             "0x1.fffffep+127",
4152             Status::INEXACT,
4153             Category::Normal,
4154         ),
4155         (
4156             p_smallest_normalized,
4157             p_smallest_value,
4158             "0x1.fffffcp-127",
4159             Status::OK,
4160             Category::Normal,
4161         ),
4162         (
4163             p_smallest_normalized,
4164             m_smallest_value,
4165             "0x1.000002p-126",
4166             Status::OK,
4167             Category::Normal,
4168         ),
4169         (
4170             p_smallest_normalized,
4171             p_smallest_normalized,
4172             "0x0p+0",
4173             Status::OK,
4174             Category::Zero,
4175         ),
4176         (
4177             p_smallest_normalized,
4178             m_smallest_normalized,
4179             "0x1p-125",
4180             Status::OK,
4181             Category::Normal,
4182         ),
4183         (
4184             m_smallest_normalized,
4185             p_inf,
4186             "-inf",
4187             Status::OK,
4188             Category::Infinity,
4189         ),
4190         (
4191             m_smallest_normalized,
4192             m_inf,
4193             "inf",
4194             Status::OK,
4195             Category::Infinity,
4196         ),
4197         (
4198             m_smallest_normalized,
4199             p_zero,
4200             "-0x1p-126",
4201             Status::OK,
4202             Category::Normal,
4203         ),
4204         (
4205             m_smallest_normalized,
4206             m_zero,
4207             "-0x1p-126",
4208             Status::OK,
4209             Category::Normal,
4210         ),
4211         (
4212             m_smallest_normalized,
4213             qnan,
4214             "-nan",
4215             Status::OK,
4216             Category::NaN,
4217         ),
4218         /*
4219 // See Note 1.
4220 (m_smallest_normalized, snan, "-nan", Status::INVALID_OP, Category::NaN),
4221         */
4222         (
4223             m_smallest_normalized,
4224             p_normal_value,
4225             "-0x1p+0",
4226             Status::INEXACT,
4227             Category::Normal,
4228         ),
4229         (
4230             m_smallest_normalized,
4231             m_normal_value,
4232             "0x1p+0",
4233             Status::INEXACT,
4234             Category::Normal,
4235         ),
4236         (
4237             m_smallest_normalized,
4238             p_largest_value,
4239             "-0x1.fffffep+127",
4240             Status::INEXACT,
4241             Category::Normal,
4242         ),
4243         (
4244             m_smallest_normalized,
4245             m_largest_value,
4246             "0x1.fffffep+127",
4247             Status::INEXACT,
4248             Category::Normal,
4249         ),
4250         (
4251             m_smallest_normalized,
4252             p_smallest_value,
4253             "-0x1.000002p-126",
4254             Status::OK,
4255             Category::Normal,
4256         ),
4257         (
4258             m_smallest_normalized,
4259             m_smallest_value,
4260             "-0x1.fffffcp-127",
4261             Status::OK,
4262             Category::Normal,
4263         ),
4264         (
4265             m_smallest_normalized,
4266             p_smallest_normalized,
4267             "-0x1p-125",
4268             Status::OK,
4269             Category::Normal,
4270         ),
4271         (
4272             m_smallest_normalized,
4273             m_smallest_normalized,
4274             "0x0p+0",
4275             Status::OK,
4276             Category::Zero,
4277         ),
4278     ];
4279
4280     for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
4281         let status;
4282         let result = unpack!(status=, x - y);
4283         assert_eq!(status, e_status);
4284         assert_eq!(result.category(), e_category);
4285         assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
4286     }
4287 }
4288
4289 #[test]
4290 fn multiply() {
4291     // Test Special Cases against each other and normal values.
4292
4293     // FIXMES/NOTES:
4294     // 1. Since we perform only default exception handling all operations with
4295     // signaling NaNs should have a result that is a quiet NaN. Currently they
4296     // return sNaN.
4297
4298     let p_inf = Single::INFINITY;
4299     let m_inf = -Single::INFINITY;
4300     let p_zero = Single::ZERO;
4301     let m_zero = -Single::ZERO;
4302     let qnan = Single::NAN;
4303     let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
4304     let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
4305     let p_largest_value = Single::largest();
4306     let m_largest_value = -Single::largest();
4307     let p_smallest_value = Single::SMALLEST;
4308     let m_smallest_value = -Single::SMALLEST;
4309     let p_smallest_normalized = Single::smallest_normalized();
4310     let m_smallest_normalized = -Single::smallest_normalized();
4311
4312     let overflow_status = Status::OVERFLOW | Status::INEXACT;
4313     let underflow_status = Status::UNDERFLOW | Status::INEXACT;
4314
4315     let special_cases = [
4316         (p_inf, p_inf, "inf", Status::OK, Category::Infinity),
4317         (p_inf, m_inf, "-inf", Status::OK, Category::Infinity),
4318         (p_inf, p_zero, "nan", Status::INVALID_OP, Category::NaN),
4319         (p_inf, m_zero, "nan", Status::INVALID_OP, Category::NaN),
4320         (p_inf, qnan, "nan", Status::OK, Category::NaN),
4321         /*
4322 // See Note 1.
4323 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
4324         */
4325         (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
4326         (
4327             p_inf,
4328             m_normal_value,
4329             "-inf",
4330             Status::OK,
4331             Category::Infinity,
4332         ),
4333         (
4334             p_inf,
4335             p_largest_value,
4336             "inf",
4337             Status::OK,
4338             Category::Infinity,
4339         ),
4340         (
4341             p_inf,
4342             m_largest_value,
4343             "-inf",
4344             Status::OK,
4345             Category::Infinity,
4346         ),
4347         (
4348             p_inf,
4349             p_smallest_value,
4350             "inf",
4351             Status::OK,
4352             Category::Infinity,
4353         ),
4354         (
4355             p_inf,
4356             m_smallest_value,
4357             "-inf",
4358             Status::OK,
4359             Category::Infinity,
4360         ),
4361         (
4362             p_inf,
4363             p_smallest_normalized,
4364             "inf",
4365             Status::OK,
4366             Category::Infinity,
4367         ),
4368         (
4369             p_inf,
4370             m_smallest_normalized,
4371             "-inf",
4372             Status::OK,
4373             Category::Infinity,
4374         ),
4375         (m_inf, p_inf, "-inf", Status::OK, Category::Infinity),
4376         (m_inf, m_inf, "inf", Status::OK, Category::Infinity),
4377         (m_inf, p_zero, "nan", Status::INVALID_OP, Category::NaN),
4378         (m_inf, m_zero, "nan", Status::INVALID_OP, Category::NaN),
4379         (m_inf, qnan, "nan", Status::OK, Category::NaN),
4380         /*
4381 // See Note 1.
4382 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
4383         */
4384         (
4385             m_inf,
4386             p_normal_value,
4387             "-inf",
4388             Status::OK,
4389             Category::Infinity,
4390         ),
4391         (m_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
4392         (
4393             m_inf,
4394             p_largest_value,
4395             "-inf",
4396             Status::OK,
4397             Category::Infinity,
4398         ),
4399         (
4400             m_inf,
4401             m_largest_value,
4402             "inf",
4403             Status::OK,
4404             Category::Infinity,
4405         ),
4406         (
4407             m_inf,
4408             p_smallest_value,
4409             "-inf",
4410             Status::OK,
4411             Category::Infinity,
4412         ),
4413         (
4414             m_inf,
4415             m_smallest_value,
4416             "inf",
4417             Status::OK,
4418             Category::Infinity,
4419         ),
4420         (
4421             m_inf,
4422             p_smallest_normalized,
4423             "-inf",
4424             Status::OK,
4425             Category::Infinity,
4426         ),
4427         (
4428             m_inf,
4429             m_smallest_normalized,
4430             "inf",
4431             Status::OK,
4432             Category::Infinity,
4433         ),
4434         (p_zero, p_inf, "nan", Status::INVALID_OP, Category::NaN),
4435         (p_zero, m_inf, "nan", Status::INVALID_OP, Category::NaN),
4436         (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
4437         (p_zero, m_zero, "-0x0p+0", Status::OK, Category::Zero),
4438         (p_zero, qnan, "nan", Status::OK, Category::NaN),
4439         /*
4440 // See Note 1.
4441 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
4442         */
4443         (p_zero, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
4444         (
4445             p_zero,
4446             m_normal_value,
4447             "-0x0p+0",
4448             Status::OK,
4449             Category::Zero,
4450         ),
4451         (
4452             p_zero,
4453             p_largest_value,
4454             "0x0p+0",
4455             Status::OK,
4456             Category::Zero,
4457         ),
4458         (
4459             p_zero,
4460             m_largest_value,
4461             "-0x0p+0",
4462             Status::OK,
4463             Category::Zero,
4464         ),
4465         (
4466             p_zero,
4467             p_smallest_value,
4468             "0x0p+0",
4469             Status::OK,
4470             Category::Zero,
4471         ),
4472         (
4473             p_zero,
4474             m_smallest_value,
4475             "-0x0p+0",
4476             Status::OK,
4477             Category::Zero,
4478         ),
4479         (
4480             p_zero,
4481             p_smallest_normalized,
4482             "0x0p+0",
4483             Status::OK,
4484             Category::Zero,
4485         ),
4486         (
4487             p_zero,
4488             m_smallest_normalized,
4489             "-0x0p+0",
4490             Status::OK,
4491             Category::Zero,
4492         ),
4493         (m_zero, p_inf, "nan", Status::INVALID_OP, Category::NaN),
4494         (m_zero, m_inf, "nan", Status::INVALID_OP, Category::NaN),
4495         (m_zero, p_zero, "-0x0p+0", Status::OK, Category::Zero),
4496         (m_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
4497         (m_zero, qnan, "nan", Status::OK, Category::NaN),
4498         /*
4499 // See Note 1.
4500 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
4501         */
4502         (
4503             m_zero,
4504             p_normal_value,
4505             "-0x0p+0",
4506             Status::OK,
4507             Category::Zero,
4508         ),
4509         (m_zero, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
4510         (
4511             m_zero,
4512             p_largest_value,
4513             "-0x0p+0",
4514             Status::OK,
4515             Category::Zero,
4516         ),
4517         (
4518             m_zero,
4519             m_largest_value,
4520             "0x0p+0",
4521             Status::OK,
4522             Category::Zero,
4523         ),
4524         (
4525             m_zero,
4526             p_smallest_value,
4527             "-0x0p+0",
4528             Status::OK,
4529             Category::Zero,
4530         ),
4531         (
4532             m_zero,
4533             m_smallest_value,
4534             "0x0p+0",
4535             Status::OK,
4536             Category::Zero,
4537         ),
4538         (
4539             m_zero,
4540             p_smallest_normalized,
4541             "-0x0p+0",
4542             Status::OK,
4543             Category::Zero,
4544         ),
4545         (
4546             m_zero,
4547             m_smallest_normalized,
4548             "0x0p+0",
4549             Status::OK,
4550             Category::Zero,
4551         ),
4552         (qnan, p_inf, "nan", Status::OK, Category::NaN),
4553         (qnan, m_inf, "nan", Status::OK, Category::NaN),
4554         (qnan, p_zero, "nan", Status::OK, Category::NaN),
4555         (qnan, m_zero, "nan", Status::OK, Category::NaN),
4556         (qnan, qnan, "nan", Status::OK, Category::NaN),
4557         /*
4558 // See Note 1.
4559 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
4560         */
4561         (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
4562         (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
4563         (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
4564         (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
4565         (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
4566         (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
4567         (
4568             qnan,
4569             p_smallest_normalized,
4570             "nan",
4571             Status::OK,
4572             Category::NaN,
4573         ),
4574         (
4575             qnan,
4576             m_smallest_normalized,
4577             "nan",
4578             Status::OK,
4579             Category::NaN,
4580         ),
4581         /*
4582 // See Note 1.
4583 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
4584 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
4585 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
4586 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
4587 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
4588 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
4589 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
4590 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
4591 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
4592 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
4593 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
4594 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
4595 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
4596 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
4597         */
4598         (p_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
4599         (
4600             p_normal_value,
4601             m_inf,
4602             "-inf",
4603             Status::OK,
4604             Category::Infinity,
4605         ),
4606         (p_normal_value, p_zero, "0x0p+0", Status::OK, Category::Zero),
4607         (
4608             p_normal_value,
4609             m_zero,
4610             "-0x0p+0",
4611             Status::OK,
4612             Category::Zero,
4613         ),
4614         (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
4615         /*
4616 // See Note 1.
4617 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
4618         */
4619         (
4620             p_normal_value,
4621             p_normal_value,
4622             "0x1p+0",
4623             Status::OK,
4624             Category::Normal,
4625         ),
4626         (
4627             p_normal_value,
4628             m_normal_value,
4629             "-0x1p+0",
4630             Status::OK,
4631             Category::Normal,
4632         ),
4633         (
4634             p_normal_value,
4635             p_largest_value,
4636             "0x1.fffffep+127",
4637             Status::OK,
4638             Category::Normal,
4639         ),
4640         (
4641             p_normal_value,
4642             m_largest_value,
4643             "-0x1.fffffep+127",
4644             Status::OK,
4645             Category::Normal,
4646         ),
4647         (
4648             p_normal_value,
4649             p_smallest_value,
4650             "0x1p-149",
4651             Status::OK,
4652             Category::Normal,
4653         ),
4654         (
4655             p_normal_value,
4656             m_smallest_value,
4657             "-0x1p-149",
4658             Status::OK,
4659             Category::Normal,
4660         ),
4661         (
4662             p_normal_value,
4663             p_smallest_normalized,
4664             "0x1p-126",
4665             Status::OK,
4666             Category::Normal,
4667         ),
4668         (
4669             p_normal_value,
4670             m_smallest_normalized,
4671             "-0x1p-126",
4672             Status::OK,
4673             Category::Normal,
4674         ),
4675         (
4676             m_normal_value,
4677             p_inf,
4678             "-inf",
4679             Status::OK,
4680             Category::Infinity,
4681         ),
4682         (m_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
4683         (
4684             m_normal_value,
4685             p_zero,
4686             "-0x0p+0",
4687             Status::OK,
4688             Category::Zero,
4689         ),
4690         (m_normal_value, m_zero, "0x0p+0", Status::OK, Category::Zero),
4691         (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
4692         /*
4693 // See Note 1.
4694 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
4695         */
4696         (
4697             m_normal_value,
4698             p_normal_value,
4699             "-0x1p+0",
4700             Status::OK,
4701             Category::Normal,
4702         ),
4703         (
4704             m_normal_value,
4705             m_normal_value,
4706             "0x1p+0",
4707             Status::OK,
4708             Category::Normal,
4709         ),
4710         (
4711             m_normal_value,
4712             p_largest_value,
4713             "-0x1.fffffep+127",
4714             Status::OK,
4715             Category::Normal,
4716         ),
4717         (
4718             m_normal_value,
4719             m_largest_value,
4720             "0x1.fffffep+127",
4721             Status::OK,
4722             Category::Normal,
4723         ),
4724         (
4725             m_normal_value,
4726             p_smallest_value,
4727             "-0x1p-149",
4728             Status::OK,
4729             Category::Normal,
4730         ),
4731         (
4732             m_normal_value,
4733             m_smallest_value,
4734             "0x1p-149",
4735             Status::OK,
4736             Category::Normal,
4737         ),
4738         (
4739             m_normal_value,
4740             p_smallest_normalized,
4741             "-0x1p-126",
4742             Status::OK,
4743             Category::Normal,
4744         ),
4745         (
4746             m_normal_value,
4747             m_smallest_normalized,
4748             "0x1p-126",
4749             Status::OK,
4750             Category::Normal,
4751         ),
4752         (
4753             p_largest_value,
4754             p_inf,
4755             "inf",
4756             Status::OK,
4757             Category::Infinity,
4758         ),
4759         (
4760             p_largest_value,
4761             m_inf,
4762             "-inf",
4763             Status::OK,
4764             Category::Infinity,
4765         ),
4766         (
4767             p_largest_value,
4768             p_zero,
4769             "0x0p+0",
4770             Status::OK,
4771             Category::Zero,
4772         ),
4773         (
4774             p_largest_value,
4775             m_zero,
4776             "-0x0p+0",
4777             Status::OK,
4778             Category::Zero,
4779         ),
4780         (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
4781         /*
4782 // See Note 1.
4783 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
4784         */
4785         (
4786             p_largest_value,
4787             p_normal_value,
4788             "0x1.fffffep+127",
4789             Status::OK,
4790             Category::Normal,
4791         ),
4792         (
4793             p_largest_value,
4794             m_normal_value,
4795             "-0x1.fffffep+127",
4796             Status::OK,
4797             Category::Normal,
4798         ),
4799         (
4800             p_largest_value,
4801             p_largest_value,
4802             "inf",
4803             overflow_status,
4804             Category::Infinity,
4805         ),
4806         (
4807             p_largest_value,
4808             m_largest_value,
4809             "-inf",
4810             overflow_status,
4811             Category::Infinity,
4812         ),
4813         (
4814             p_largest_value,
4815             p_smallest_value,
4816             "0x1.fffffep-22",
4817             Status::OK,
4818             Category::Normal,
4819         ),
4820         (
4821             p_largest_value,
4822             m_smallest_value,
4823             "-0x1.fffffep-22",
4824             Status::OK,
4825             Category::Normal,
4826         ),
4827         (
4828             p_largest_value,
4829             p_smallest_normalized,
4830             "0x1.fffffep+1",
4831             Status::OK,
4832             Category::Normal,
4833         ),
4834         (
4835             p_largest_value,
4836             m_smallest_normalized,
4837             "-0x1.fffffep+1",
4838             Status::OK,
4839             Category::Normal,
4840         ),
4841         (
4842             m_largest_value,
4843             p_inf,
4844             "-inf",
4845             Status::OK,
4846             Category::Infinity,
4847         ),
4848         (
4849             m_largest_value,
4850             m_inf,
4851             "inf",
4852             Status::OK,
4853             Category::Infinity,
4854         ),
4855         (
4856             m_largest_value,
4857             p_zero,
4858             "-0x0p+0",
4859             Status::OK,
4860             Category::Zero,
4861         ),
4862         (
4863             m_largest_value,
4864             m_zero,
4865             "0x0p+0",
4866             Status::OK,
4867             Category::Zero,
4868         ),
4869         (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
4870         /*
4871 // See Note 1.
4872 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
4873         */
4874         (
4875             m_largest_value,
4876             p_normal_value,
4877             "-0x1.fffffep+127",
4878             Status::OK,
4879             Category::Normal,
4880         ),
4881         (
4882             m_largest_value,
4883             m_normal_value,
4884             "0x1.fffffep+127",
4885             Status::OK,
4886             Category::Normal,
4887         ),
4888         (
4889             m_largest_value,
4890             p_largest_value,
4891             "-inf",
4892             overflow_status,
4893             Category::Infinity,
4894         ),
4895         (
4896             m_largest_value,
4897             m_largest_value,
4898             "inf",
4899             overflow_status,
4900             Category::Infinity,
4901         ),
4902         (
4903             m_largest_value,
4904             p_smallest_value,
4905             "-0x1.fffffep-22",
4906             Status::OK,
4907             Category::Normal,
4908         ),
4909         (
4910             m_largest_value,
4911             m_smallest_value,
4912             "0x1.fffffep-22",
4913             Status::OK,
4914             Category::Normal,
4915         ),
4916         (
4917             m_largest_value,
4918             p_smallest_normalized,
4919             "-0x1.fffffep+1",
4920             Status::OK,
4921             Category::Normal,
4922         ),
4923         (
4924             m_largest_value,
4925             m_smallest_normalized,
4926             "0x1.fffffep+1",
4927             Status::OK,
4928             Category::Normal,
4929         ),
4930         (
4931             p_smallest_value,
4932             p_inf,
4933             "inf",
4934             Status::OK,
4935             Category::Infinity,
4936         ),
4937         (
4938             p_smallest_value,
4939             m_inf,
4940             "-inf",
4941             Status::OK,
4942             Category::Infinity,
4943         ),
4944         (
4945             p_smallest_value,
4946             p_zero,
4947             "0x0p+0",
4948             Status::OK,
4949             Category::Zero,
4950         ),
4951         (
4952             p_smallest_value,
4953             m_zero,
4954             "-0x0p+0",
4955             Status::OK,
4956             Category::Zero,
4957         ),
4958         (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
4959         /*
4960 // See Note 1.
4961 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
4962         */
4963         (
4964             p_smallest_value,
4965             p_normal_value,
4966             "0x1p-149",
4967             Status::OK,
4968             Category::Normal,
4969         ),
4970         (
4971             p_smallest_value,
4972             m_normal_value,
4973             "-0x1p-149",
4974             Status::OK,
4975             Category::Normal,
4976         ),
4977         (
4978             p_smallest_value,
4979             p_largest_value,
4980             "0x1.fffffep-22",
4981             Status::OK,
4982             Category::Normal,
4983         ),
4984         (
4985             p_smallest_value,
4986             m_largest_value,
4987             "-0x1.fffffep-22",
4988             Status::OK,
4989             Category::Normal,
4990         ),
4991         (
4992             p_smallest_value,
4993             p_smallest_value,
4994             "0x0p+0",
4995             underflow_status,
4996             Category::Zero,
4997         ),
4998         (
4999             p_smallest_value,
5000             m_smallest_value,
5001             "-0x0p+0",
5002             underflow_status,
5003             Category::Zero,
5004         ),
5005         (
5006             p_smallest_value,
5007             p_smallest_normalized,
5008             "0x0p+0",
5009             underflow_status,
5010             Category::Zero,
5011         ),
5012         (
5013             p_smallest_value,
5014             m_smallest_normalized,
5015             "-0x0p+0",
5016             underflow_status,
5017             Category::Zero,
5018         ),
5019         (
5020             m_smallest_value,
5021             p_inf,
5022             "-inf",
5023             Status::OK,
5024             Category::Infinity,
5025         ),
5026         (
5027             m_smallest_value,
5028             m_inf,
5029             "inf",
5030             Status::OK,
5031             Category::Infinity,
5032         ),
5033         (
5034             m_smallest_value,
5035             p_zero,
5036             "-0x0p+0",
5037             Status::OK,
5038             Category::Zero,
5039         ),
5040         (
5041             m_smallest_value,
5042             m_zero,
5043             "0x0p+0",
5044             Status::OK,
5045             Category::Zero,
5046         ),
5047         (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
5048         /*
5049 // See Note 1.
5050 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5051         */
5052         (
5053             m_smallest_value,
5054             p_normal_value,
5055             "-0x1p-149",
5056             Status::OK,
5057             Category::Normal,
5058         ),
5059         (
5060             m_smallest_value,
5061             m_normal_value,
5062             "0x1p-149",
5063             Status::OK,
5064             Category::Normal,
5065         ),
5066         (
5067             m_smallest_value,
5068             p_largest_value,
5069             "-0x1.fffffep-22",
5070             Status::OK,
5071             Category::Normal,
5072         ),
5073         (
5074             m_smallest_value,
5075             m_largest_value,
5076             "0x1.fffffep-22",
5077             Status::OK,
5078             Category::Normal,
5079         ),
5080         (
5081             m_smallest_value,
5082             p_smallest_value,
5083             "-0x0p+0",
5084             underflow_status,
5085             Category::Zero,
5086         ),
5087         (
5088             m_smallest_value,
5089             m_smallest_value,
5090             "0x0p+0",
5091             underflow_status,
5092             Category::Zero,
5093         ),
5094         (
5095             m_smallest_value,
5096             p_smallest_normalized,
5097             "-0x0p+0",
5098             underflow_status,
5099             Category::Zero,
5100         ),
5101         (
5102             m_smallest_value,
5103             m_smallest_normalized,
5104             "0x0p+0",
5105             underflow_status,
5106             Category::Zero,
5107         ),
5108         (
5109             p_smallest_normalized,
5110             p_inf,
5111             "inf",
5112             Status::OK,
5113             Category::Infinity,
5114         ),
5115         (
5116             p_smallest_normalized,
5117             m_inf,
5118             "-inf",
5119             Status::OK,
5120             Category::Infinity,
5121         ),
5122         (
5123             p_smallest_normalized,
5124             p_zero,
5125             "0x0p+0",
5126             Status::OK,
5127             Category::Zero,
5128         ),
5129         (
5130             p_smallest_normalized,
5131             m_zero,
5132             "-0x0p+0",
5133             Status::OK,
5134             Category::Zero,
5135         ),
5136         (
5137             p_smallest_normalized,
5138             qnan,
5139             "nan",
5140             Status::OK,
5141             Category::NaN,
5142         ),
5143         /*
5144 // See Note 1.
5145 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
5146         */
5147         (
5148             p_smallest_normalized,
5149             p_normal_value,
5150             "0x1p-126",
5151             Status::OK,
5152             Category::Normal,
5153         ),
5154         (
5155             p_smallest_normalized,
5156             m_normal_value,
5157             "-0x1p-126",
5158             Status::OK,
5159             Category::Normal,
5160         ),
5161         (
5162             p_smallest_normalized,
5163             p_largest_value,
5164             "0x1.fffffep+1",
5165             Status::OK,
5166             Category::Normal,
5167         ),
5168         (
5169             p_smallest_normalized,
5170             m_largest_value,
5171             "-0x1.fffffep+1",
5172             Status::OK,
5173             Category::Normal,
5174         ),
5175         (
5176             p_smallest_normalized,
5177             p_smallest_value,
5178             "0x0p+0",
5179             underflow_status,
5180             Category::Zero,
5181         ),
5182         (
5183             p_smallest_normalized,
5184             m_smallest_value,
5185             "-0x0p+0",
5186             underflow_status,
5187             Category::Zero,
5188         ),
5189         (
5190             p_smallest_normalized,
5191             p_smallest_normalized,
5192             "0x0p+0",
5193             underflow_status,
5194             Category::Zero,
5195         ),
5196         (
5197             p_smallest_normalized,
5198             m_smallest_normalized,
5199             "-0x0p+0",
5200             underflow_status,
5201             Category::Zero,
5202         ),
5203         (
5204             m_smallest_normalized,
5205             p_inf,
5206             "-inf",
5207             Status::OK,
5208             Category::Infinity,
5209         ),
5210         (
5211             m_smallest_normalized,
5212             m_inf,
5213             "inf",
5214             Status::OK,
5215             Category::Infinity,
5216         ),
5217         (
5218             m_smallest_normalized,
5219             p_zero,
5220             "-0x0p+0",
5221             Status::OK,
5222             Category::Zero,
5223         ),
5224         (
5225             m_smallest_normalized,
5226             m_zero,
5227             "0x0p+0",
5228             Status::OK,
5229             Category::Zero,
5230         ),
5231         (
5232             m_smallest_normalized,
5233             qnan,
5234             "nan",
5235             Status::OK,
5236             Category::NaN,
5237         ),
5238         /*
5239 // See Note 1.
5240 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
5241         */
5242         (
5243             m_smallest_normalized,
5244             p_normal_value,
5245             "-0x1p-126",
5246             Status::OK,
5247             Category::Normal,
5248         ),
5249         (
5250             m_smallest_normalized,
5251             m_normal_value,
5252             "0x1p-126",
5253             Status::OK,
5254             Category::Normal,
5255         ),
5256         (
5257             m_smallest_normalized,
5258             p_largest_value,
5259             "-0x1.fffffep+1",
5260             Status::OK,
5261             Category::Normal,
5262         ),
5263         (
5264             m_smallest_normalized,
5265             m_largest_value,
5266             "0x1.fffffep+1",
5267             Status::OK,
5268             Category::Normal,
5269         ),
5270         (
5271             m_smallest_normalized,
5272             p_smallest_value,
5273             "-0x0p+0",
5274             underflow_status,
5275             Category::Zero,
5276         ),
5277         (
5278             m_smallest_normalized,
5279             m_smallest_value,
5280             "0x0p+0",
5281             underflow_status,
5282             Category::Zero,
5283         ),
5284         (
5285             m_smallest_normalized,
5286             p_smallest_normalized,
5287             "-0x0p+0",
5288             underflow_status,
5289             Category::Zero,
5290         ),
5291         (
5292             m_smallest_normalized,
5293             m_smallest_normalized,
5294             "0x0p+0",
5295             underflow_status,
5296             Category::Zero,
5297         ),
5298     ];
5299
5300     for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
5301         let status;
5302         let result = unpack!(status=, x * y);
5303         assert_eq!(status, e_status);
5304         assert_eq!(result.category(), e_category);
5305         assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
5306     }
5307 }
5308
5309 #[test]
5310 fn divide() {
5311     // Test Special Cases against each other and normal values.
5312
5313     // FIXMES/NOTES:
5314     // 1. Since we perform only default exception handling all operations with
5315     // signaling NaNs should have a result that is a quiet NaN. Currently they
5316     // return sNaN.
5317
5318     let p_inf = Single::INFINITY;
5319     let m_inf = -Single::INFINITY;
5320     let p_zero = Single::ZERO;
5321     let m_zero = -Single::ZERO;
5322     let qnan = Single::NAN;
5323     let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
5324     let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
5325     let p_largest_value = Single::largest();
5326     let m_largest_value = -Single::largest();
5327     let p_smallest_value = Single::SMALLEST;
5328     let m_smallest_value = -Single::SMALLEST;
5329     let p_smallest_normalized = Single::smallest_normalized();
5330     let m_smallest_normalized = -Single::smallest_normalized();
5331
5332     let overflow_status = Status::OVERFLOW | Status::INEXACT;
5333     let underflow_status = Status::UNDERFLOW | Status::INEXACT;
5334
5335     let special_cases = [
5336         (p_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
5337         (p_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
5338         (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
5339         (p_inf, m_zero, "-inf", Status::OK, Category::Infinity),
5340         (p_inf, qnan, "nan", Status::OK, Category::NaN),
5341         /*
5342 // See Note 1.
5343 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
5344         */
5345         (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
5346         (
5347             p_inf,
5348             m_normal_value,
5349             "-inf",
5350             Status::OK,
5351             Category::Infinity,
5352         ),
5353         (
5354             p_inf,
5355             p_largest_value,
5356             "inf",
5357             Status::OK,
5358             Category::Infinity,
5359         ),
5360         (
5361             p_inf,
5362             m_largest_value,
5363             "-inf",
5364             Status::OK,
5365             Category::Infinity,
5366         ),
5367         (
5368             p_inf,
5369             p_smallest_value,
5370             "inf",
5371             Status::OK,
5372             Category::Infinity,
5373         ),
5374         (
5375             p_inf,
5376             m_smallest_value,
5377             "-inf",
5378             Status::OK,
5379             Category::Infinity,
5380         ),
5381         (
5382             p_inf,
5383             p_smallest_normalized,
5384             "inf",
5385             Status::OK,
5386             Category::Infinity,
5387         ),
5388         (
5389             p_inf,
5390             m_smallest_normalized,
5391             "-inf",
5392             Status::OK,
5393             Category::Infinity,
5394         ),
5395         (m_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
5396         (m_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
5397         (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
5398         (m_inf, m_zero, "inf", Status::OK, Category::Infinity),
5399         (m_inf, qnan, "nan", Status::OK, Category::NaN),
5400         /*
5401 // See Note 1.
5402 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
5403         */
5404         (
5405             m_inf,
5406             p_normal_value,
5407             "-inf",
5408             Status::OK,
5409             Category::Infinity,
5410         ),
5411         (m_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
5412         (
5413             m_inf,
5414             p_largest_value,
5415             "-inf",
5416             Status::OK,
5417             Category::Infinity,
5418         ),
5419         (
5420             m_inf,
5421             m_largest_value,
5422             "inf",
5423             Status::OK,
5424             Category::Infinity,
5425         ),
5426         (
5427             m_inf,
5428             p_smallest_value,
5429             "-inf",
5430             Status::OK,
5431             Category::Infinity,
5432         ),
5433         (
5434             m_inf,
5435             m_smallest_value,
5436             "inf",
5437             Status::OK,
5438             Category::Infinity,
5439         ),
5440         (
5441             m_inf,
5442             p_smallest_normalized,
5443             "-inf",
5444             Status::OK,
5445             Category::Infinity,
5446         ),
5447         (
5448             m_inf,
5449             m_smallest_normalized,
5450             "inf",
5451             Status::OK,
5452             Category::Infinity,
5453         ),
5454         (p_zero, p_inf, "0x0p+0", Status::OK, Category::Zero),
5455         (p_zero, m_inf, "-0x0p+0", Status::OK, Category::Zero),
5456         (p_zero, p_zero, "nan", Status::INVALID_OP, Category::NaN),
5457         (p_zero, m_zero, "nan", Status::INVALID_OP, Category::NaN),
5458         (p_zero, qnan, "nan", Status::OK, Category::NaN),
5459         /*
5460 // See Note 1.
5461 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
5462         */
5463         (p_zero, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
5464         (
5465             p_zero,
5466             m_normal_value,
5467             "-0x0p+0",
5468             Status::OK,
5469             Category::Zero,
5470         ),
5471         (
5472             p_zero,
5473             p_largest_value,
5474             "0x0p+0",
5475             Status::OK,
5476             Category::Zero,
5477         ),
5478         (
5479             p_zero,
5480             m_largest_value,
5481             "-0x0p+0",
5482             Status::OK,
5483             Category::Zero,
5484         ),
5485         (
5486             p_zero,
5487             p_smallest_value,
5488             "0x0p+0",
5489             Status::OK,
5490             Category::Zero,
5491         ),
5492         (
5493             p_zero,
5494             m_smallest_value,
5495             "-0x0p+0",
5496             Status::OK,
5497             Category::Zero,
5498         ),
5499         (
5500             p_zero,
5501             p_smallest_normalized,
5502             "0x0p+0",
5503             Status::OK,
5504             Category::Zero,
5505         ),
5506         (
5507             p_zero,
5508             m_smallest_normalized,
5509             "-0x0p+0",
5510             Status::OK,
5511             Category::Zero,
5512         ),
5513         (m_zero, p_inf, "-0x0p+0", Status::OK, Category::Zero),
5514         (m_zero, m_inf, "0x0p+0", Status::OK, Category::Zero),
5515         (m_zero, p_zero, "nan", Status::INVALID_OP, Category::NaN),
5516         (m_zero, m_zero, "nan", Status::INVALID_OP, Category::NaN),
5517         (m_zero, qnan, "nan", Status::OK, Category::NaN),
5518         /*
5519 // See Note 1.
5520 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
5521         */
5522         (
5523             m_zero,
5524             p_normal_value,
5525             "-0x0p+0",
5526             Status::OK,
5527             Category::Zero,
5528         ),
5529         (m_zero, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
5530         (
5531             m_zero,
5532             p_largest_value,
5533             "-0x0p+0",
5534             Status::OK,
5535             Category::Zero,
5536         ),
5537         (
5538             m_zero,
5539             m_largest_value,
5540             "0x0p+0",
5541             Status::OK,
5542             Category::Zero,
5543         ),
5544         (
5545             m_zero,
5546             p_smallest_value,
5547             "-0x0p+0",
5548             Status::OK,
5549             Category::Zero,
5550         ),
5551         (
5552             m_zero,
5553             m_smallest_value,
5554             "0x0p+0",
5555             Status::OK,
5556             Category::Zero,
5557         ),
5558         (
5559             m_zero,
5560             p_smallest_normalized,
5561             "-0x0p+0",
5562             Status::OK,
5563             Category::Zero,
5564         ),
5565         (
5566             m_zero,
5567             m_smallest_normalized,
5568             "0x0p+0",
5569             Status::OK,
5570             Category::Zero,
5571         ),
5572         (qnan, p_inf, "nan", Status::OK, Category::NaN),
5573         (qnan, m_inf, "nan", Status::OK, Category::NaN),
5574         (qnan, p_zero, "nan", Status::OK, Category::NaN),
5575         (qnan, m_zero, "nan", Status::OK, Category::NaN),
5576         (qnan, qnan, "nan", Status::OK, Category::NaN),
5577         /*
5578 // See Note 1.
5579 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
5580         */
5581         (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
5582         (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
5583         (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
5584         (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
5585         (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
5586         (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
5587         (
5588             qnan,
5589             p_smallest_normalized,
5590             "nan",
5591             Status::OK,
5592             Category::NaN,
5593         ),
5594         (
5595             qnan,
5596             m_smallest_normalized,
5597             "nan",
5598             Status::OK,
5599             Category::NaN,
5600         ),
5601         /*
5602 // See Note 1.
5603 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
5604 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
5605 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
5606 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
5607 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
5608 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
5609 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
5610 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
5611 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
5612 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
5613 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
5614 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
5615 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
5616 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
5617         */
5618         (p_normal_value, p_inf, "0x0p+0", Status::OK, Category::Zero),
5619         (p_normal_value, m_inf, "-0x0p+0", Status::OK, Category::Zero),
5620         (
5621             p_normal_value,
5622             p_zero,
5623             "inf",
5624             Status::DIV_BY_ZERO,
5625             Category::Infinity,
5626         ),
5627         (
5628             p_normal_value,
5629             m_zero,
5630             "-inf",
5631             Status::DIV_BY_ZERO,
5632             Category::Infinity,
5633         ),
5634         (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
5635         /*
5636 // See Note 1.
5637 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5638         */
5639         (
5640             p_normal_value,
5641             p_normal_value,
5642             "0x1p+0",
5643             Status::OK,
5644             Category::Normal,
5645         ),
5646         (
5647             p_normal_value,
5648             m_normal_value,
5649             "-0x1p+0",
5650             Status::OK,
5651             Category::Normal,
5652         ),
5653         (
5654             p_normal_value,
5655             p_largest_value,
5656             "0x1p-128",
5657             underflow_status,
5658             Category::Normal,
5659         ),
5660         (
5661             p_normal_value,
5662             m_largest_value,
5663             "-0x1p-128",
5664             underflow_status,
5665             Category::Normal,
5666         ),
5667         (
5668             p_normal_value,
5669             p_smallest_value,
5670             "inf",
5671             overflow_status,
5672             Category::Infinity,
5673         ),
5674         (
5675             p_normal_value,
5676             m_smallest_value,
5677             "-inf",
5678             overflow_status,
5679             Category::Infinity,
5680         ),
5681         (
5682             p_normal_value,
5683             p_smallest_normalized,
5684             "0x1p+126",
5685             Status::OK,
5686             Category::Normal,
5687         ),
5688         (
5689             p_normal_value,
5690             m_smallest_normalized,
5691             "-0x1p+126",
5692             Status::OK,
5693             Category::Normal,
5694         ),
5695         (m_normal_value, p_inf, "-0x0p+0", Status::OK, Category::Zero),
5696         (m_normal_value, m_inf, "0x0p+0", Status::OK, Category::Zero),
5697         (
5698             m_normal_value,
5699             p_zero,
5700             "-inf",
5701             Status::DIV_BY_ZERO,
5702             Category::Infinity,
5703         ),
5704         (
5705             m_normal_value,
5706             m_zero,
5707             "inf",
5708             Status::DIV_BY_ZERO,
5709             Category::Infinity,
5710         ),
5711         (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
5712         /*
5713 // See Note 1.
5714 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5715         */
5716         (
5717             m_normal_value,
5718             p_normal_value,
5719             "-0x1p+0",
5720             Status::OK,
5721             Category::Normal,
5722         ),
5723         (
5724             m_normal_value,
5725             m_normal_value,
5726             "0x1p+0",
5727             Status::OK,
5728             Category::Normal,
5729         ),
5730         (
5731             m_normal_value,
5732             p_largest_value,
5733             "-0x1p-128",
5734             underflow_status,
5735             Category::Normal,
5736         ),
5737         (
5738             m_normal_value,
5739             m_largest_value,
5740             "0x1p-128",
5741             underflow_status,
5742             Category::Normal,
5743         ),
5744         (
5745             m_normal_value,
5746             p_smallest_value,
5747             "-inf",
5748             overflow_status,
5749             Category::Infinity,
5750         ),
5751         (
5752             m_normal_value,
5753             m_smallest_value,
5754             "inf",
5755             overflow_status,
5756             Category::Infinity,
5757         ),
5758         (
5759             m_normal_value,
5760             p_smallest_normalized,
5761             "-0x1p+126",
5762             Status::OK,
5763             Category::Normal,
5764         ),
5765         (
5766             m_normal_value,
5767             m_smallest_normalized,
5768             "0x1p+126",
5769             Status::OK,
5770             Category::Normal,
5771         ),
5772         (p_largest_value, p_inf, "0x0p+0", Status::OK, Category::Zero),
5773         (
5774             p_largest_value,
5775             m_inf,
5776             "-0x0p+0",
5777             Status::OK,
5778             Category::Zero,
5779         ),
5780         (
5781             p_largest_value,
5782             p_zero,
5783             "inf",
5784             Status::DIV_BY_ZERO,
5785             Category::Infinity,
5786         ),
5787         (
5788             p_largest_value,
5789             m_zero,
5790             "-inf",
5791             Status::DIV_BY_ZERO,
5792             Category::Infinity,
5793         ),
5794         (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
5795         /*
5796 // See Note 1.
5797 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5798         */
5799         (
5800             p_largest_value,
5801             p_normal_value,
5802             "0x1.fffffep+127",
5803             Status::OK,
5804             Category::Normal,
5805         ),
5806         (
5807             p_largest_value,
5808             m_normal_value,
5809             "-0x1.fffffep+127",
5810             Status::OK,
5811             Category::Normal,
5812         ),
5813         (
5814             p_largest_value,
5815             p_largest_value,
5816             "0x1p+0",
5817             Status::OK,
5818             Category::Normal,
5819         ),
5820         (
5821             p_largest_value,
5822             m_largest_value,
5823             "-0x1p+0",
5824             Status::OK,
5825             Category::Normal,
5826         ),
5827         (
5828             p_largest_value,
5829             p_smallest_value,
5830             "inf",
5831             overflow_status,
5832             Category::Infinity,
5833         ),
5834         (
5835             p_largest_value,
5836             m_smallest_value,
5837             "-inf",
5838             overflow_status,
5839             Category::Infinity,
5840         ),
5841         (
5842             p_largest_value,
5843             p_smallest_normalized,
5844             "inf",
5845             overflow_status,
5846             Category::Infinity,
5847         ),
5848         (
5849             p_largest_value,
5850             m_smallest_normalized,
5851             "-inf",
5852             overflow_status,
5853             Category::Infinity,
5854         ),
5855         (
5856             m_largest_value,
5857             p_inf,
5858             "-0x0p+0",
5859             Status::OK,
5860             Category::Zero,
5861         ),
5862         (m_largest_value, m_inf, "0x0p+0", Status::OK, Category::Zero),
5863         (
5864             m_largest_value,
5865             p_zero,
5866             "-inf",
5867             Status::DIV_BY_ZERO,
5868             Category::Infinity,
5869         ),
5870         (
5871             m_largest_value,
5872             m_zero,
5873             "inf",
5874             Status::DIV_BY_ZERO,
5875             Category::Infinity,
5876         ),
5877         (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
5878         /*
5879 // See Note 1.
5880 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5881         */
5882         (
5883             m_largest_value,
5884             p_normal_value,
5885             "-0x1.fffffep+127",
5886             Status::OK,
5887             Category::Normal,
5888         ),
5889         (
5890             m_largest_value,
5891             m_normal_value,
5892             "0x1.fffffep+127",
5893             Status::OK,
5894             Category::Normal,
5895         ),
5896         (
5897             m_largest_value,
5898             p_largest_value,
5899             "-0x1p+0",
5900             Status::OK,
5901             Category::Normal,
5902         ),
5903         (
5904             m_largest_value,
5905             m_largest_value,
5906             "0x1p+0",
5907             Status::OK,
5908             Category::Normal,
5909         ),
5910         (
5911             m_largest_value,
5912             p_smallest_value,
5913             "-inf",
5914             overflow_status,
5915             Category::Infinity,
5916         ),
5917         (
5918             m_largest_value,
5919             m_smallest_value,
5920             "inf",
5921             overflow_status,
5922             Category::Infinity,
5923         ),
5924         (
5925             m_largest_value,
5926             p_smallest_normalized,
5927             "-inf",
5928             overflow_status,
5929             Category::Infinity,
5930         ),
5931         (
5932             m_largest_value,
5933             m_smallest_normalized,
5934             "inf",
5935             overflow_status,
5936             Category::Infinity,
5937         ),
5938         (
5939             p_smallest_value,
5940             p_inf,
5941             "0x0p+0",
5942             Status::OK,
5943             Category::Zero,
5944         ),
5945         (
5946             p_smallest_value,
5947             m_inf,
5948             "-0x0p+0",
5949             Status::OK,
5950             Category::Zero,
5951         ),
5952         (
5953             p_smallest_value,
5954             p_zero,
5955             "inf",
5956             Status::DIV_BY_ZERO,
5957             Category::Infinity,
5958         ),
5959         (
5960             p_smallest_value,
5961             m_zero,
5962             "-inf",
5963             Status::DIV_BY_ZERO,
5964             Category::Infinity,
5965         ),
5966         (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
5967         /*
5968 // See Note 1.
5969 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
5970         */
5971         (
5972             p_smallest_value,
5973             p_normal_value,
5974             "0x1p-149",
5975             Status::OK,
5976             Category::Normal,
5977         ),
5978         (
5979             p_smallest_value,
5980             m_normal_value,
5981             "-0x1p-149",
5982             Status::OK,
5983             Category::Normal,
5984         ),
5985         (
5986             p_smallest_value,
5987             p_largest_value,
5988             "0x0p+0",
5989             underflow_status,
5990             Category::Zero,
5991         ),
5992         (
5993             p_smallest_value,
5994             m_largest_value,
5995             "-0x0p+0",
5996             underflow_status,
5997             Category::Zero,
5998         ),
5999         (
6000             p_smallest_value,
6001             p_smallest_value,
6002             "0x1p+0",
6003             Status::OK,
6004             Category::Normal,
6005         ),
6006         (
6007             p_smallest_value,
6008             m_smallest_value,
6009             "-0x1p+0",
6010             Status::OK,
6011             Category::Normal,
6012         ),
6013         (
6014             p_smallest_value,
6015             p_smallest_normalized,
6016             "0x1p-23",
6017             Status::OK,
6018             Category::Normal,
6019         ),
6020         (
6021             p_smallest_value,
6022             m_smallest_normalized,
6023             "-0x1p-23",
6024             Status::OK,
6025             Category::Normal,
6026         ),
6027         (
6028             m_smallest_value,
6029             p_inf,
6030             "-0x0p+0",
6031             Status::OK,
6032             Category::Zero,
6033         ),
6034         (
6035             m_smallest_value,
6036             m_inf,
6037             "0x0p+0",
6038             Status::OK,
6039             Category::Zero,
6040         ),
6041         (
6042             m_smallest_value,
6043             p_zero,
6044             "-inf",
6045             Status::DIV_BY_ZERO,
6046             Category::Infinity,
6047         ),
6048         (
6049             m_smallest_value,
6050             m_zero,
6051             "inf",
6052             Status::DIV_BY_ZERO,
6053             Category::Infinity,
6054         ),
6055         (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
6056         /*
6057 // See Note 1.
6058 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
6059         */
6060         (
6061             m_smallest_value,
6062             p_normal_value,
6063             "-0x1p-149",
6064             Status::OK,
6065             Category::Normal,
6066         ),
6067         (
6068             m_smallest_value,
6069             m_normal_value,
6070             "0x1p-149",
6071             Status::OK,
6072             Category::Normal,
6073         ),
6074         (
6075             m_smallest_value,
6076             p_largest_value,
6077             "-0x0p+0",
6078             underflow_status,
6079             Category::Zero,
6080         ),
6081         (
6082             m_smallest_value,
6083             m_largest_value,
6084             "0x0p+0",
6085             underflow_status,
6086             Category::Zero,
6087         ),
6088         (
6089             m_smallest_value,
6090             p_smallest_value,
6091             "-0x1p+0",
6092             Status::OK,
6093             Category::Normal,
6094         ),
6095         (
6096             m_smallest_value,
6097             m_smallest_value,
6098             "0x1p+0",
6099             Status::OK,
6100             Category::Normal,
6101         ),
6102         (
6103             m_smallest_value,
6104             p_smallest_normalized,
6105             "-0x1p-23",
6106             Status::OK,
6107             Category::Normal,
6108         ),
6109         (
6110             m_smallest_value,
6111             m_smallest_normalized,
6112             "0x1p-23",
6113             Status::OK,
6114             Category::Normal,
6115         ),
6116         (
6117             p_smallest_normalized,
6118             p_inf,
6119             "0x0p+0",
6120             Status::OK,
6121             Category::Zero,
6122         ),
6123         (
6124             p_smallest_normalized,
6125             m_inf,
6126             "-0x0p+0",
6127             Status::OK,
6128             Category::Zero,
6129         ),
6130         (
6131             p_smallest_normalized,
6132             p_zero,
6133             "inf",
6134             Status::DIV_BY_ZERO,
6135             Category::Infinity,
6136         ),
6137         (
6138             p_smallest_normalized,
6139             m_zero,
6140             "-inf",
6141             Status::DIV_BY_ZERO,
6142             Category::Infinity,
6143         ),
6144         (
6145             p_smallest_normalized,
6146             qnan,
6147             "nan",
6148             Status::OK,
6149             Category::NaN,
6150         ),
6151         /*
6152 // See Note 1.
6153 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
6154         */
6155         (
6156             p_smallest_normalized,
6157             p_normal_value,
6158             "0x1p-126",
6159             Status::OK,
6160             Category::Normal,
6161         ),
6162         (
6163             p_smallest_normalized,
6164             m_normal_value,
6165             "-0x1p-126",
6166             Status::OK,
6167             Category::Normal,
6168         ),
6169         (
6170             p_smallest_normalized,
6171             p_largest_value,
6172             "0x0p+0",
6173             underflow_status,
6174             Category::Zero,
6175         ),
6176         (
6177             p_smallest_normalized,
6178             m_largest_value,
6179             "-0x0p+0",
6180             underflow_status,
6181             Category::Zero,
6182         ),
6183         (
6184             p_smallest_normalized,
6185             p_smallest_value,
6186             "0x1p+23",
6187             Status::OK,
6188             Category::Normal,
6189         ),
6190         (
6191             p_smallest_normalized,
6192             m_smallest_value,
6193             "-0x1p+23",
6194             Status::OK,
6195             Category::Normal,
6196         ),
6197         (
6198             p_smallest_normalized,
6199             p_smallest_normalized,
6200             "0x1p+0",
6201             Status::OK,
6202             Category::Normal,
6203         ),
6204         (
6205             p_smallest_normalized,
6206             m_smallest_normalized,
6207             "-0x1p+0",
6208             Status::OK,
6209             Category::Normal,
6210         ),
6211         (
6212             m_smallest_normalized,
6213             p_inf,
6214             "-0x0p+0",
6215             Status::OK,
6216             Category::Zero,
6217         ),
6218         (
6219             m_smallest_normalized,
6220             m_inf,
6221             "0x0p+0",
6222             Status::OK,
6223             Category::Zero,
6224         ),
6225         (
6226             m_smallest_normalized,
6227             p_zero,
6228             "-inf",
6229             Status::DIV_BY_ZERO,
6230             Category::Infinity,
6231         ),
6232         (
6233             m_smallest_normalized,
6234             m_zero,
6235             "inf",
6236             Status::DIV_BY_ZERO,
6237             Category::Infinity,
6238         ),
6239         (
6240             m_smallest_normalized,
6241             qnan,
6242             "nan",
6243             Status::OK,
6244             Category::NaN,
6245         ),
6246         /*
6247 // See Note 1.
6248 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
6249         */
6250         (
6251             m_smallest_normalized,
6252             p_normal_value,
6253             "-0x1p-126",
6254             Status::OK,
6255             Category::Normal,
6256         ),
6257         (
6258             m_smallest_normalized,
6259             m_normal_value,
6260             "0x1p-126",
6261             Status::OK,
6262             Category::Normal,
6263         ),
6264         (
6265             m_smallest_normalized,
6266             p_largest_value,
6267             "-0x0p+0",
6268             underflow_status,
6269             Category::Zero,
6270         ),
6271         (
6272             m_smallest_normalized,
6273             m_largest_value,
6274             "0x0p+0",
6275             underflow_status,
6276             Category::Zero,
6277         ),
6278         (
6279             m_smallest_normalized,
6280             p_smallest_value,
6281             "-0x1p+23",
6282             Status::OK,
6283             Category::Normal,
6284         ),
6285         (
6286             m_smallest_normalized,
6287             m_smallest_value,
6288             "0x1p+23",
6289             Status::OK,
6290             Category::Normal,
6291         ),
6292         (
6293             m_smallest_normalized,
6294             p_smallest_normalized,
6295             "-0x1p+0",
6296             Status::OK,
6297             Category::Normal,
6298         ),
6299         (
6300             m_smallest_normalized,
6301             m_smallest_normalized,
6302             "0x1p+0",
6303             Status::OK,
6304             Category::Normal,
6305         ),
6306     ];
6307
6308     for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
6309         let status;
6310         let result = unpack!(status=, x / y);
6311         assert_eq!(status, e_status);
6312         assert_eq!(result.category(), e_category);
6313         assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
6314     }
6315 }
6316
6317 #[test]
6318 fn operator_overloads() {
6319     // This is mostly testing that these operator overloads compile.
6320     let one = "0x1p+0".parse::<Single>().unwrap();
6321     let two = "0x2p+0".parse::<Single>().unwrap();
6322     assert!(two.bitwise_eq((one + one).value));
6323     assert!(one.bitwise_eq((two - one).value));
6324     assert!(two.bitwise_eq((one * two).value));
6325     assert!(one.bitwise_eq((two / two).value));
6326 }
6327
6328 #[test]
6329 fn abs() {
6330     let p_inf = Single::INFINITY;
6331     let m_inf = -Single::INFINITY;
6332     let p_zero = Single::ZERO;
6333     let m_zero = -Single::ZERO;
6334     let p_qnan = Single::NAN;
6335     let m_qnan = -Single::NAN;
6336     let p_snan = Single::snan(None);
6337     let m_snan = -Single::snan(None);
6338     let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
6339     let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
6340     let p_largest_value = Single::largest();
6341     let m_largest_value = -Single::largest();
6342     let p_smallest_value = Single::SMALLEST;
6343     let m_smallest_value = -Single::SMALLEST;
6344     let p_smallest_normalized = Single::smallest_normalized();
6345     let m_smallest_normalized = -Single::smallest_normalized();
6346
6347     assert!(p_inf.bitwise_eq(p_inf.abs()));
6348     assert!(p_inf.bitwise_eq(m_inf.abs()));
6349     assert!(p_zero.bitwise_eq(p_zero.abs()));
6350     assert!(p_zero.bitwise_eq(m_zero.abs()));
6351     assert!(p_qnan.bitwise_eq(p_qnan.abs()));
6352     assert!(p_qnan.bitwise_eq(m_qnan.abs()));
6353     assert!(p_snan.bitwise_eq(p_snan.abs()));
6354     assert!(p_snan.bitwise_eq(m_snan.abs()));
6355     assert!(p_normal_value.bitwise_eq(p_normal_value.abs()));
6356     assert!(p_normal_value.bitwise_eq(m_normal_value.abs()));
6357     assert!(p_largest_value.bitwise_eq(p_largest_value.abs()));
6358     assert!(p_largest_value.bitwise_eq(m_largest_value.abs()));
6359     assert!(p_smallest_value.bitwise_eq(p_smallest_value.abs()));
6360     assert!(p_smallest_value.bitwise_eq(m_smallest_value.abs()));
6361     assert!(p_smallest_normalized.bitwise_eq(
6362         p_smallest_normalized.abs(),
6363     ));
6364     assert!(p_smallest_normalized.bitwise_eq(
6365         m_smallest_normalized.abs(),
6366     ));
6367 }
6368
6369 #[test]
6370 fn neg() {
6371     let one = "1.0".parse::<Single>().unwrap();
6372     let neg_one = "-1.0".parse::<Single>().unwrap();
6373     let zero = Single::ZERO;
6374     let neg_zero = -Single::ZERO;
6375     let inf = Single::INFINITY;
6376     let neg_inf = -Single::INFINITY;
6377     let qnan = Single::NAN;
6378     let neg_qnan = -Single::NAN;
6379
6380     assert!(neg_one.bitwise_eq(-one));
6381     assert!(one.bitwise_eq(-neg_one));
6382     assert!(neg_zero.bitwise_eq(-zero));
6383     assert!(zero.bitwise_eq(-neg_zero));
6384     assert!(neg_inf.bitwise_eq(-inf));
6385     assert!(inf.bitwise_eq(-neg_inf));
6386     assert!(neg_inf.bitwise_eq(-inf));
6387     assert!(inf.bitwise_eq(-neg_inf));
6388     assert!(neg_qnan.bitwise_eq(-qnan));
6389     assert!(qnan.bitwise_eq(-neg_qnan));
6390 }
6391
6392 #[test]
6393 fn ilogb() {
6394     assert_eq!(-1074, Double::SMALLEST.ilogb());
6395     assert_eq!(-1074, (-Double::SMALLEST).ilogb());
6396     assert_eq!(
6397         -1023,
6398         "0x1.ffffffffffffep-1024".parse::<Double>().unwrap().ilogb()
6399     );
6400     assert_eq!(
6401         -1023,
6402         "0x1.ffffffffffffep-1023".parse::<Double>().unwrap().ilogb()
6403     );
6404     assert_eq!(
6405         -1023,
6406         "-0x1.ffffffffffffep-1023"
6407             .parse::<Double>()
6408             .unwrap()
6409             .ilogb()
6410     );
6411     assert_eq!(-51, "0x1p-51".parse::<Double>().unwrap().ilogb());
6412     assert_eq!(
6413         -1023,
6414         "0x1.c60f120d9f87cp-1023".parse::<Double>().unwrap().ilogb()
6415     );
6416     assert_eq!(-2, "0x0.ffffp-1".parse::<Double>().unwrap().ilogb());
6417     assert_eq!(-1023, "0x1.fffep-1023".parse::<Double>().unwrap().ilogb());
6418     assert_eq!(1023, Double::largest().ilogb());
6419     assert_eq!(1023, (-Double::largest()).ilogb());
6420
6421
6422     assert_eq!(0, "0x1p+0".parse::<Single>().unwrap().ilogb());
6423     assert_eq!(0, "-0x1p+0".parse::<Single>().unwrap().ilogb());
6424     assert_eq!(42, "0x1p+42".parse::<Single>().unwrap().ilogb());
6425     assert_eq!(-42, "0x1p-42".parse::<Single>().unwrap().ilogb());
6426
6427     assert_eq!(IEK_INF, Single::INFINITY.ilogb());
6428     assert_eq!(IEK_INF, (-Single::INFINITY).ilogb());
6429     assert_eq!(IEK_ZERO, Single::ZERO.ilogb());
6430     assert_eq!(IEK_ZERO, (-Single::ZERO).ilogb());
6431     assert_eq!(IEK_NAN, Single::NAN.ilogb());
6432     assert_eq!(IEK_NAN, Single::snan(None).ilogb());
6433
6434     assert_eq!(127, Single::largest().ilogb());
6435     assert_eq!(127, (-Single::largest()).ilogb());
6436
6437     assert_eq!(-149, Single::SMALLEST.ilogb());
6438     assert_eq!(-149, (-Single::SMALLEST).ilogb());
6439     assert_eq!(-126, Single::smallest_normalized().ilogb());
6440     assert_eq!(-126, (-Single::smallest_normalized()).ilogb());
6441 }
6442
6443 #[test]
6444 fn scalbn() {
6445     assert!("0x1p+0".parse::<Single>().unwrap().bitwise_eq(
6446         "0x1p+0".parse::<Single>().unwrap().scalbn(0),
6447     ));
6448     assert!("0x1p+42".parse::<Single>().unwrap().bitwise_eq(
6449         "0x1p+0".parse::<Single>().unwrap().scalbn(42),
6450     ));
6451     assert!("0x1p-42".parse::<Single>().unwrap().bitwise_eq(
6452         "0x1p+0".parse::<Single>().unwrap().scalbn(-42),
6453     ));
6454
6455     let p_inf = Single::INFINITY;
6456     let m_inf = -Single::INFINITY;
6457     let p_zero = Single::ZERO;
6458     let m_zero = -Single::ZERO;
6459     let p_qnan = Single::NAN;
6460     let m_qnan = -Single::NAN;
6461     let snan = Single::snan(None);
6462
6463     assert!(p_inf.bitwise_eq(p_inf.scalbn(0)));
6464     assert!(m_inf.bitwise_eq(m_inf.scalbn(0)));
6465     assert!(p_zero.bitwise_eq(p_zero.scalbn(0)));
6466     assert!(m_zero.bitwise_eq(m_zero.scalbn(0)));
6467     assert!(p_qnan.bitwise_eq(p_qnan.scalbn(0)));
6468     assert!(m_qnan.bitwise_eq(m_qnan.scalbn(0)));
6469     assert!(!snan.scalbn(0).is_signaling());
6470
6471     let scalbn_snan = snan.scalbn(1);
6472     assert!(scalbn_snan.is_nan() && !scalbn_snan.is_signaling());
6473
6474     // Make sure highest bit of payload is preserved.
6475     let payload = (1 << 50) | (1 << 49) | (1234 << 32) | 1;
6476
6477     let snan_with_payload = Double::snan(Some(payload));
6478     let quiet_payload = snan_with_payload.scalbn(1);
6479     assert!(quiet_payload.is_nan() && !quiet_payload.is_signaling());
6480     assert_eq!(payload, quiet_payload.to_bits() & ((1 << 51) - 1));
6481
6482     assert!(p_inf.bitwise_eq(
6483         "0x1p+0".parse::<Single>().unwrap().scalbn(128),
6484     ));
6485     assert!(m_inf.bitwise_eq(
6486         "-0x1p+0".parse::<Single>().unwrap().scalbn(128),
6487     ));
6488     assert!(p_inf.bitwise_eq(
6489         "0x1p+127".parse::<Single>().unwrap().scalbn(1),
6490     ));
6491     assert!(p_zero.bitwise_eq(
6492         "0x1p-127".parse::<Single>().unwrap().scalbn(-127),
6493     ));
6494     assert!(m_zero.bitwise_eq(
6495         "-0x1p-127".parse::<Single>().unwrap().scalbn(-127),
6496     ));
6497     assert!("-0x1p-149".parse::<Single>().unwrap().bitwise_eq(
6498         "-0x1p-127".parse::<Single>().unwrap().scalbn(-22),
6499     ));
6500     assert!(p_zero.bitwise_eq(
6501         "0x1p-126".parse::<Single>().unwrap().scalbn(-24),
6502     ));
6503
6504
6505     let smallest_f64 = Double::SMALLEST;
6506     let neg_smallest_f64 = -Double::SMALLEST;
6507
6508     let largest_f64 = Double::largest();
6509     let neg_largest_f64 = -Double::largest();
6510
6511     let largest_denormal_f64 = "0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
6512     let neg_largest_denormal_f64 = "-0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
6513
6514
6515     assert!(smallest_f64.bitwise_eq(
6516         "0x1p-1074".parse::<Double>().unwrap().scalbn(0),
6517     ));
6518     assert!(neg_smallest_f64.bitwise_eq(
6519         "-0x1p-1074".parse::<Double>().unwrap().scalbn(0),
6520     ));
6521
6522     assert!("0x1p+1023".parse::<Double>().unwrap().bitwise_eq(
6523         smallest_f64.scalbn(
6524             2097,
6525         ),
6526     ));
6527
6528     assert!(smallest_f64.scalbn(-2097).is_pos_zero());
6529     assert!(smallest_f64.scalbn(-2098).is_pos_zero());
6530     assert!(smallest_f64.scalbn(-2099).is_pos_zero());
6531     assert!("0x1p+1022".parse::<Double>().unwrap().bitwise_eq(
6532         smallest_f64.scalbn(
6533             2096,
6534         ),
6535     ));
6536     assert!("0x1p+1023".parse::<Double>().unwrap().bitwise_eq(
6537         smallest_f64.scalbn(
6538             2097,
6539         ),
6540     ));
6541     assert!(smallest_f64.scalbn(2098).is_infinite());
6542     assert!(smallest_f64.scalbn(2099).is_infinite());
6543
6544     // Test for integer overflows when adding to exponent.
6545     assert!(smallest_f64.scalbn(-ExpInt::max_value()).is_pos_zero());
6546     assert!(largest_f64.scalbn(ExpInt::max_value()).is_infinite());
6547
6548     assert!(largest_denormal_f64.bitwise_eq(
6549         largest_denormal_f64.scalbn(0),
6550     ));
6551     assert!(neg_largest_denormal_f64.bitwise_eq(
6552         neg_largest_denormal_f64.scalbn(0),
6553     ));
6554
6555     assert!(
6556         "0x1.ffffffffffffep-1022"
6557             .parse::<Double>()
6558             .unwrap()
6559             .bitwise_eq(largest_denormal_f64.scalbn(1))
6560     );
6561     assert!(
6562         "-0x1.ffffffffffffep-1021"
6563             .parse::<Double>()
6564             .unwrap()
6565             .bitwise_eq(neg_largest_denormal_f64.scalbn(2))
6566     );
6567
6568     assert!(
6569         "0x1.ffffffffffffep+1"
6570             .parse::<Double>()
6571             .unwrap()
6572             .bitwise_eq(largest_denormal_f64.scalbn(1024))
6573     );
6574     assert!(largest_denormal_f64.scalbn(-1023).is_pos_zero());
6575     assert!(largest_denormal_f64.scalbn(-1024).is_pos_zero());
6576     assert!(largest_denormal_f64.scalbn(-2048).is_pos_zero());
6577     assert!(largest_denormal_f64.scalbn(2047).is_infinite());
6578     assert!(largest_denormal_f64.scalbn(2098).is_infinite());
6579     assert!(largest_denormal_f64.scalbn(2099).is_infinite());
6580
6581     assert!(
6582         "0x1.ffffffffffffep-2"
6583             .parse::<Double>()
6584             .unwrap()
6585             .bitwise_eq(largest_denormal_f64.scalbn(1021))
6586     );
6587     assert!(
6588         "0x1.ffffffffffffep-1"
6589             .parse::<Double>()
6590             .unwrap()
6591             .bitwise_eq(largest_denormal_f64.scalbn(1022))
6592     );
6593     assert!(
6594         "0x1.ffffffffffffep+0"
6595             .parse::<Double>()
6596             .unwrap()
6597             .bitwise_eq(largest_denormal_f64.scalbn(1023))
6598     );
6599     assert!(
6600         "0x1.ffffffffffffep+1023"
6601             .parse::<Double>()
6602             .unwrap()
6603             .bitwise_eq(largest_denormal_f64.scalbn(2046))
6604     );
6605     assert!("0x1p+974".parse::<Double>().unwrap().bitwise_eq(
6606         smallest_f64.scalbn(
6607             2048,
6608         ),
6609     ));
6610
6611     let random_denormal_f64 = "0x1.c60f120d9f87cp+51".parse::<Double>().unwrap();
6612     assert!(
6613         "0x1.c60f120d9f87cp-972"
6614             .parse::<Double>()
6615             .unwrap()
6616             .bitwise_eq(random_denormal_f64.scalbn(-1023))
6617     );
6618     assert!(
6619         "0x1.c60f120d9f87cp-1"
6620             .parse::<Double>()
6621             .unwrap()
6622             .bitwise_eq(random_denormal_f64.scalbn(-52))
6623     );
6624     assert!(
6625         "0x1.c60f120d9f87cp-2"
6626             .parse::<Double>()
6627             .unwrap()
6628             .bitwise_eq(random_denormal_f64.scalbn(-53))
6629     );
6630     assert!(
6631         "0x1.c60f120d9f87cp+0"
6632             .parse::<Double>()
6633             .unwrap()
6634             .bitwise_eq(random_denormal_f64.scalbn(-51))
6635     );
6636
6637     assert!(random_denormal_f64.scalbn(-2097).is_pos_zero());
6638     assert!(random_denormal_f64.scalbn(-2090).is_pos_zero());
6639
6640
6641     assert!("-0x1p-1073".parse::<Double>().unwrap().bitwise_eq(
6642         neg_largest_f64.scalbn(-2097),
6643     ));
6644
6645     assert!("-0x1p-1024".parse::<Double>().unwrap().bitwise_eq(
6646         neg_largest_f64.scalbn(-2048),
6647     ));
6648
6649     assert!("0x1p-1073".parse::<Double>().unwrap().bitwise_eq(
6650         largest_f64.scalbn(
6651             -2097,
6652         ),
6653     ));
6654
6655     assert!("0x1p-1074".parse::<Double>().unwrap().bitwise_eq(
6656         largest_f64.scalbn(
6657             -2098,
6658         ),
6659     ));
6660     assert!("-0x1p-1074".parse::<Double>().unwrap().bitwise_eq(
6661         neg_largest_f64.scalbn(-2098),
6662     ));
6663     assert!(neg_largest_f64.scalbn(-2099).is_neg_zero());
6664     assert!(largest_f64.scalbn(1).is_infinite());
6665
6666
6667     assert!("0x1p+0".parse::<Double>().unwrap().bitwise_eq(
6668         "0x1p+52".parse::<Double>().unwrap().scalbn(-52),
6669     ));
6670
6671     assert!("0x1p-103".parse::<Double>().unwrap().bitwise_eq(
6672         "0x1p-51".parse::<Double>().unwrap().scalbn(-52),
6673     ));
6674 }
6675
6676 #[test]
6677 fn frexp() {
6678     let p_zero = Double::ZERO;
6679     let m_zero = -Double::ZERO;
6680     let one = Double::from_f64(1.0);
6681     let m_one = Double::from_f64(-1.0);
6682
6683     let largest_denormal = "0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
6684     let neg_largest_denormal = "-0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
6685
6686     let smallest = Double::SMALLEST;
6687     let neg_smallest = -Double::SMALLEST;
6688
6689     let largest = Double::largest();
6690     let neg_largest = -Double::largest();
6691
6692     let p_inf = Double::INFINITY;
6693     let m_inf = -Double::INFINITY;
6694
6695     let p_qnan = Double::NAN;
6696     let m_qnan = -Double::NAN;
6697     let snan = Double::snan(None);
6698
6699     // Make sure highest bit of payload is preserved.
6700     let payload = (1 << 50) | (1 << 49) | (1234 << 32) | 1;
6701
6702     let snan_with_payload = Double::snan(Some(payload));
6703
6704     let mut exp = 0;
6705
6706     let frac = p_zero.frexp(&mut exp);
6707     assert_eq!(0, exp);
6708     assert!(frac.is_pos_zero());
6709
6710     let frac = m_zero.frexp(&mut exp);
6711     assert_eq!(0, exp);
6712     assert!(frac.is_neg_zero());
6713
6714
6715     let frac = one.frexp(&mut exp);
6716     assert_eq!(1, exp);
6717     assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
6718
6719     let frac = m_one.frexp(&mut exp);
6720     assert_eq!(1, exp);
6721     assert!("-0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
6722
6723     let frac = largest_denormal.frexp(&mut exp);
6724     assert_eq!(-1022, exp);
6725     assert!(
6726         "0x1.ffffffffffffep-1"
6727             .parse::<Double>()
6728             .unwrap()
6729             .bitwise_eq(frac)
6730     );
6731
6732     let frac = neg_largest_denormal.frexp(&mut exp);
6733     assert_eq!(-1022, exp);
6734     assert!(
6735         "-0x1.ffffffffffffep-1"
6736             .parse::<Double>()
6737             .unwrap()
6738             .bitwise_eq(frac)
6739     );
6740
6741
6742     let frac = smallest.frexp(&mut exp);
6743     assert_eq!(-1073, exp);
6744     assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
6745
6746     let frac = neg_smallest.frexp(&mut exp);
6747     assert_eq!(-1073, exp);
6748     assert!("-0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
6749
6750
6751     let frac = largest.frexp(&mut exp);
6752     assert_eq!(1024, exp);
6753     assert!(
6754         "0x1.fffffffffffffp-1"
6755             .parse::<Double>()
6756             .unwrap()
6757             .bitwise_eq(frac)
6758     );
6759
6760     let frac = neg_largest.frexp(&mut exp);
6761     assert_eq!(1024, exp);
6762     assert!(
6763         "-0x1.fffffffffffffp-1"
6764             .parse::<Double>()
6765             .unwrap()
6766             .bitwise_eq(frac)
6767     );
6768
6769
6770     let frac = p_inf.frexp(&mut exp);
6771     assert_eq!(IEK_INF, exp);
6772     assert!(frac.is_infinite() && !frac.is_negative());
6773
6774     let frac = m_inf.frexp(&mut exp);
6775     assert_eq!(IEK_INF, exp);
6776     assert!(frac.is_infinite() && frac.is_negative());
6777
6778     let frac = p_qnan.frexp(&mut exp);
6779     assert_eq!(IEK_NAN, exp);
6780     assert!(frac.is_nan());
6781
6782     let frac = m_qnan.frexp(&mut exp);
6783     assert_eq!(IEK_NAN, exp);
6784     assert!(frac.is_nan());
6785
6786     let frac = snan.frexp(&mut exp);
6787     assert_eq!(IEK_NAN, exp);
6788     assert!(frac.is_nan() && !frac.is_signaling());
6789
6790     let frac = snan_with_payload.frexp(&mut exp);
6791     assert_eq!(IEK_NAN, exp);
6792     assert!(frac.is_nan() && !frac.is_signaling());
6793     assert_eq!(payload, frac.to_bits() & ((1 << 51) - 1));
6794
6795     let frac = "0x0.ffffp-1".parse::<Double>().unwrap().frexp(&mut exp);
6796     assert_eq!(-1, exp);
6797     assert!("0x1.fffep-1".parse::<Double>().unwrap().bitwise_eq(frac));
6798
6799     let frac = "0x1p-51".parse::<Double>().unwrap().frexp(&mut exp);
6800     assert_eq!(-50, exp);
6801     assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
6802
6803     let frac = "0x1.c60f120d9f87cp+51".parse::<Double>().unwrap().frexp(
6804         &mut exp,
6805     );
6806     assert_eq!(52, exp);
6807     assert!(
6808         "0x1.c60f120d9f87cp-1"
6809             .parse::<Double>()
6810             .unwrap()
6811             .bitwise_eq(frac)
6812     );
6813 }
6814
6815 #[test]
6816 fn modulo() {
6817     let mut status;
6818     {
6819         let f1 = "1.5".parse::<Double>().unwrap();
6820         let f2 = "1.0".parse::<Double>().unwrap();
6821         let expected = "0.5".parse::<Double>().unwrap();
6822         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6823         assert_eq!(status, Status::OK);
6824     }
6825     {
6826         let f1 = "0.5".parse::<Double>().unwrap();
6827         let f2 = "1.0".parse::<Double>().unwrap();
6828         let expected = "0.5".parse::<Double>().unwrap();
6829         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6830         assert_eq!(status, Status::OK);
6831     }
6832     {
6833         let f1 = "0x1.3333333333333p-2".parse::<Double>().unwrap(); // 0.3
6834         let f2 = "0x1.47ae147ae147bp-7".parse::<Double>().unwrap(); // 0.01
6835         // 0.009999999999999983
6836         let expected = "0x1.47ae147ae1471p-7".parse::<Double>().unwrap();
6837         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6838         assert_eq!(status, Status::OK);
6839     }
6840     {
6841         let f1 = "0x1p64".parse::<Double>().unwrap(); // 1.8446744073709552e19
6842         let f2 = "1.5".parse::<Double>().unwrap();
6843         let expected = "1.0".parse::<Double>().unwrap();
6844         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6845         assert_eq!(status, Status::OK);
6846     }
6847     {
6848         let f1 = "0x1p1000".parse::<Double>().unwrap();
6849         let f2 = "0x1p-1000".parse::<Double>().unwrap();
6850         let expected = "0.0".parse::<Double>().unwrap();
6851         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6852         assert_eq!(status, Status::OK);
6853     }
6854     {
6855         let f1 = "0.0".parse::<Double>().unwrap();
6856         let f2 = "1.0".parse::<Double>().unwrap();
6857         let expected = "0.0".parse::<Double>().unwrap();
6858         assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
6859         assert_eq!(status, Status::OK);
6860     }
6861     {
6862         let f1 = "1.0".parse::<Double>().unwrap();
6863         let f2 = "0.0".parse::<Double>().unwrap();
6864         assert!(unpack!(status=, f1 % f2).is_nan());
6865         assert_eq!(status, Status::INVALID_OP);
6866     }
6867     {
6868         let f1 = "0.0".parse::<Double>().unwrap();
6869         let f2 = "0.0".parse::<Double>().unwrap();
6870         assert!(unpack!(status=, f1 % f2).is_nan());
6871         assert_eq!(status, Status::INVALID_OP);
6872     }
6873     {
6874         let f1 = Double::INFINITY;
6875         let f2 = "1.0".parse::<Double>().unwrap();
6876         assert!(unpack!(status=, f1 % f2).is_nan());
6877         assert_eq!(status, Status::INVALID_OP);
6878     }
6879 }