1 // ignore-tidy-filelength
3 use rustc_apfloat::ieee::{Double, Half, Quad, Single, X87DoubleExtended};
4 use rustc_apfloat::unpack;
5 use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
6 use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status};
9 fn from_f32(input: f32) -> Self;
10 fn to_f32(self) -> f32;
13 impl SingleExt for Single {
14 fn from_f32(input: f32) -> Self {
15 Self::from_bits(input.to_bits() as u128)
18 fn to_f32(self) -> f32 {
19 f32::from_bits(self.to_bits() as u32)
24 fn from_f64(input: f64) -> Self;
25 fn to_f64(self) -> f64;
28 impl DoubleExt for Double {
29 fn from_f64(input: f64) -> Self {
30 Self::from_bits(input.to_bits() as u128)
33 fn to_f64(self) -> f64 {
34 f64::from_bits(self.to_bits() as u64)
40 // We test qNaN, -qNaN, +sNaN, -sNaN with and without payloads.
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());
54 // 1. Test Special Cases Values.
56 // Test all special values for nextUp and nextDown perscribed by IEEE-754R
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));
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));
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));
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));
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));
107 // nextDown(largest) = -nextUp(-largest)
108 // = -(-largest + inc)
110 let test = unpack!(status=, Quad::largest().next_down());
111 let expected = "0x1.fffffffffffffffffffffffffffep+16383".parse::<Quad>().unwrap();
112 assert_eq!(status, Status::OK);
113 assert!(!test.is_infinite() && !test.is_negative());
114 assert!(test.bitwise_eq(expected));
116 // nextUp(-largest) = -largest + inc.
117 let test = unpack!(status=, (-Quad::largest()).next_up());
118 let expected = "-0x1.fffffffffffffffffffffffffffep+16383".parse::<Quad>().unwrap();
119 assert_eq!(status, Status::OK);
120 assert!(test.bitwise_eq(expected));
122 // nextDown(-largest) = -nextUp(largest) = -(inf) = -inf.
123 let test = unpack!(status=, (-Quad::largest()).next_down());
124 let expected = -Quad::INFINITY;
125 assert_eq!(status, Status::OK);
126 assert!(test.is_infinite() && test.is_negative());
127 assert!(test.bitwise_eq(expected));
129 // nextUp(smallest) = smallest + inc.
130 let test = unpack!(status=, "0x0.0000000000000000000000000001p-16382"
134 let expected = "0x0.0000000000000000000000000002p-16382".parse::<Quad>().unwrap();
135 assert_eq!(status, Status::OK);
136 assert!(test.bitwise_eq(expected));
138 // nextDown(smallest) = -nextUp(-smallest) = -(-0) = +0.
139 let test = unpack!(status=, "0x0.0000000000000000000000000001p-16382"
143 let expected = Quad::ZERO;
144 assert_eq!(status, Status::OK);
145 assert!(test.is_pos_zero());
146 assert!(test.bitwise_eq(expected));
148 // nextUp(-smallest) = -0.
149 let test = unpack!(status=, "-0x0.0000000000000000000000000001p-16382"
153 let expected = -Quad::ZERO;
154 assert_eq!(status, Status::OK);
155 assert!(test.is_neg_zero());
156 assert!(test.bitwise_eq(expected));
158 // nextDown(-smallest) = -nextUp(smallest) = -smallest - inc.
159 let test = unpack!(status=, "-0x0.0000000000000000000000000001p-16382"
163 let expected = "-0x0.0000000000000000000000000002p-16382".parse::<Quad>().unwrap();
164 assert_eq!(status, Status::OK);
165 assert!(test.bitwise_eq(expected));
167 // nextUp(qNaN) = qNaN
168 let test = unpack!(status=, Quad::qnan(None).next_up());
169 let expected = Quad::qnan(None);
170 assert_eq!(status, Status::OK);
171 assert!(test.bitwise_eq(expected));
173 // nextDown(qNaN) = qNaN
174 let test = unpack!(status=, Quad::qnan(None).next_down());
175 let expected = Quad::qnan(None);
176 assert_eq!(status, Status::OK);
177 assert!(test.bitwise_eq(expected));
179 // nextUp(sNaN) = qNaN
180 let test = unpack!(status=, Quad::snan(None).next_up());
181 let expected = Quad::qnan(None);
182 assert_eq!(status, Status::INVALID_OP);
183 assert!(test.bitwise_eq(expected));
185 // nextDown(sNaN) = qNaN
186 let test = unpack!(status=, Quad::snan(None).next_down());
187 let expected = Quad::qnan(None);
188 assert_eq!(status, Status::INVALID_OP);
189 assert!(test.bitwise_eq(expected));
191 // nextUp(+0) = +smallest
192 let test = unpack!(status=, Quad::ZERO.next_up());
193 let expected = Quad::SMALLEST;
194 assert_eq!(status, Status::OK);
195 assert!(test.bitwise_eq(expected));
197 // nextDown(+0) = -nextUp(-0) = -smallest
198 let test = unpack!(status=, Quad::ZERO.next_down());
199 let expected = -Quad::SMALLEST;
200 assert_eq!(status, Status::OK);
201 assert!(test.bitwise_eq(expected));
203 // nextUp(-0) = +smallest
204 let test = unpack!(status=, (-Quad::ZERO).next_up());
205 let expected = Quad::SMALLEST;
206 assert_eq!(status, Status::OK);
207 assert!(test.bitwise_eq(expected));
209 // nextDown(-0) = -nextUp(0) = -smallest
210 let test = unpack!(status=, (-Quad::ZERO).next_down());
211 let expected = -Quad::SMALLEST;
212 assert_eq!(status, Status::OK);
213 assert!(test.bitwise_eq(expected));
215 // 2. Binade Boundary Tests.
217 // 2a. Test denormal <-> normal binade boundaries.
218 // * nextUp(+Largest Denormal) -> +Smallest Normal.
219 // * nextDown(-Largest Denormal) -> -Smallest Normal.
220 // * nextUp(-Smallest Normal) -> -Largest Denormal.
221 // * nextDown(+Smallest Normal) -> +Largest Denormal.
223 // nextUp(+Largest Denormal) -> +Smallest Normal.
224 let test = unpack!(status=, "0x0.ffffffffffffffffffffffffffffp-16382"
228 let expected = "0x1.0000000000000000000000000000p-16382".parse::<Quad>().unwrap();
229 assert_eq!(status, Status::OK);
230 assert!(!test.is_denormal());
231 assert!(test.bitwise_eq(expected));
233 // nextDown(-Largest Denormal) -> -Smallest Normal.
234 let test = unpack!(status=, "-0x0.ffffffffffffffffffffffffffffp-16382"
238 let expected = "-0x1.0000000000000000000000000000p-16382".parse::<Quad>().unwrap();
239 assert_eq!(status, Status::OK);
240 assert!(!test.is_denormal());
241 assert!(test.bitwise_eq(expected));
243 // nextUp(-Smallest Normal) -> -Largest Denormal.
244 let test = unpack!(status=, "-0x1.0000000000000000000000000000p-16382"
248 let expected = "-0x0.ffffffffffffffffffffffffffffp-16382".parse::<Quad>().unwrap();
249 assert_eq!(status, Status::OK);
250 assert!(test.is_denormal());
251 assert!(test.bitwise_eq(expected));
253 // nextDown(+Smallest Normal) -> +Largest Denormal.
254 let test = unpack!(status=, "+0x1.0000000000000000000000000000p-16382"
258 let expected = "+0x0.ffffffffffffffffffffffffffffp-16382".parse::<Quad>().unwrap();
259 assert_eq!(status, Status::OK);
260 assert!(test.is_denormal());
261 assert!(test.bitwise_eq(expected));
263 // 2b. Test normal <-> normal binade boundaries.
264 // * nextUp(-Normal Binade Boundary) -> -Normal Binade Boundary + 1.
265 // * nextDown(+Normal Binade Boundary) -> +Normal Binade Boundary - 1.
266 // * nextUp(+Normal Binade Boundary - 1) -> +Normal Binade Boundary.
267 // * nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
269 // nextUp(-Normal Binade Boundary) -> -Normal Binade Boundary + 1.
270 let test = unpack!(status=, "-0x1p+1".parse::<Quad>().unwrap().next_up());
271 let expected = "-0x1.ffffffffffffffffffffffffffffp+0".parse::<Quad>().unwrap();
272 assert_eq!(status, Status::OK);
273 assert!(test.bitwise_eq(expected));
275 // nextDown(+Normal Binade Boundary) -> +Normal Binade Boundary - 1.
276 let test = unpack!(status=, "0x1p+1".parse::<Quad>().unwrap().next_down());
277 let expected = "0x1.ffffffffffffffffffffffffffffp+0".parse::<Quad>().unwrap();
278 assert_eq!(status, Status::OK);
279 assert!(test.bitwise_eq(expected));
281 // nextUp(+Normal Binade Boundary - 1) -> +Normal Binade Boundary.
282 let test = unpack!(status=, "0x1.ffffffffffffffffffffffffffffp+0"
286 let expected = "0x1p+1".parse::<Quad>().unwrap();
287 assert_eq!(status, Status::OK);
288 assert!(test.bitwise_eq(expected));
290 // nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
291 let test = unpack!(status=, "-0x1.ffffffffffffffffffffffffffffp+0"
295 let expected = "-0x1p+1".parse::<Quad>().unwrap();
296 assert_eq!(status, Status::OK);
297 assert!(test.bitwise_eq(expected));
299 // 2c. Test using next at binade boundaries with a direction away from the
300 // binade boundary. Away from denormal <-> normal boundaries.
302 // This is to make sure that even though we are at a binade boundary, since
303 // we are rounding away, we do not trigger the binade boundary code. Thus we
305 // * nextUp(-Largest Denormal) -> -Largest Denormal + inc.
306 // * nextDown(+Largest Denormal) -> +Largest Denormal - inc.
307 // * nextUp(+Smallest Normal) -> +Smallest Normal + inc.
308 // * nextDown(-Smallest Normal) -> -Smallest Normal - inc.
310 // nextUp(-Largest Denormal) -> -Largest Denormal + inc.
311 let test = unpack!(status=, "-0x0.ffffffffffffffffffffffffffffp-16382"
315 let expected = "-0x0.fffffffffffffffffffffffffffep-16382".parse::<Quad>().unwrap();
316 assert_eq!(status, Status::OK);
317 assert!(test.is_denormal());
318 assert!(test.is_negative());
319 assert!(test.bitwise_eq(expected));
321 // nextDown(+Largest Denormal) -> +Largest Denormal - inc.
322 let test = unpack!(status=, "0x0.ffffffffffffffffffffffffffffp-16382"
326 let expected = "0x0.fffffffffffffffffffffffffffep-16382".parse::<Quad>().unwrap();
327 assert_eq!(status, Status::OK);
328 assert!(test.is_denormal());
329 assert!(!test.is_negative());
330 assert!(test.bitwise_eq(expected));
332 // nextUp(+Smallest Normal) -> +Smallest Normal + inc.
333 let test = unpack!(status=, "0x1.0000000000000000000000000000p-16382"
337 let expected = "0x1.0000000000000000000000000001p-16382".parse::<Quad>().unwrap();
338 assert_eq!(status, Status::OK);
339 assert!(!test.is_denormal());
340 assert!(!test.is_negative());
341 assert!(test.bitwise_eq(expected));
343 // nextDown(-Smallest Normal) -> -Smallest Normal - inc.
344 let test = unpack!(status=, "-0x1.0000000000000000000000000000p-16382"
348 let expected = "-0x1.0000000000000000000000000001p-16382".parse::<Quad>().unwrap();
349 assert_eq!(status, Status::OK);
350 assert!(!test.is_denormal());
351 assert!(test.is_negative());
352 assert!(test.bitwise_eq(expected));
354 // 2d. Test values which cause our exponent to go to min exponent. This
355 // is to ensure that guards in the code to check for min exponent
357 // * nextUp(-0x1p-16381) -> -0x1.ffffffffffffffffffffffffffffp-16382
358 // * nextDown(-0x1.ffffffffffffffffffffffffffffp-16382) ->
360 // * nextUp(0x1.ffffffffffffffffffffffffffffp-16382) -> 0x1p-16382
361 // * nextDown(0x1p-16382) -> 0x1.ffffffffffffffffffffffffffffp-16382
363 // nextUp(-0x1p-16381) -> -0x1.ffffffffffffffffffffffffffffp-16382
364 let test = unpack!(status=, "-0x1p-16381".parse::<Quad>().unwrap().next_up());
365 let expected = "-0x1.ffffffffffffffffffffffffffffp-16382".parse::<Quad>().unwrap();
366 assert_eq!(status, Status::OK);
367 assert!(test.bitwise_eq(expected));
369 // nextDown(-0x1.ffffffffffffffffffffffffffffp-16382) ->
371 let test = unpack!(status=, "-0x1.ffffffffffffffffffffffffffffp-16382"
375 let expected = "-0x1p-16381".parse::<Quad>().unwrap();
376 assert_eq!(status, Status::OK);
377 assert!(test.bitwise_eq(expected));
379 // nextUp(0x1.ffffffffffffffffffffffffffffp-16382) -> 0x1p-16381
380 let test = unpack!(status=, "0x1.ffffffffffffffffffffffffffffp-16382"
384 let expected = "0x1p-16381".parse::<Quad>().unwrap();
385 assert_eq!(status, Status::OK);
386 assert!(test.bitwise_eq(expected));
388 // nextDown(0x1p-16381) -> 0x1.ffffffffffffffffffffffffffffp-16382
389 let test = unpack!(status=, "0x1p-16381".parse::<Quad>().unwrap().next_down());
390 let expected = "0x1.ffffffffffffffffffffffffffffp-16382".parse::<Quad>().unwrap();
391 assert_eq!(status, Status::OK);
392 assert!(test.bitwise_eq(expected));
394 // 3. Now we test both denormal/normal computation which will not cause us
395 // to go across binade boundaries. Specifically we test:
396 // * nextUp(+Denormal) -> +Denormal.
397 // * nextDown(+Denormal) -> +Denormal.
398 // * nextUp(-Denormal) -> -Denormal.
399 // * nextDown(-Denormal) -> -Denormal.
400 // * nextUp(+Normal) -> +Normal.
401 // * nextDown(+Normal) -> +Normal.
402 // * nextUp(-Normal) -> -Normal.
403 // * nextDown(-Normal) -> -Normal.
405 // nextUp(+Denormal) -> +Denormal.
406 let test = unpack!(status=, "0x0.ffffffffffffffffffffffff000cp-16382"
410 let expected = "0x0.ffffffffffffffffffffffff000dp-16382".parse::<Quad>().unwrap();
411 assert_eq!(status, Status::OK);
412 assert!(test.is_denormal());
413 assert!(!test.is_negative());
414 assert!(test.bitwise_eq(expected));
416 // nextDown(+Denormal) -> +Denormal.
417 let test = unpack!(status=, "0x0.ffffffffffffffffffffffff000cp-16382"
421 let expected = "0x0.ffffffffffffffffffffffff000bp-16382".parse::<Quad>().unwrap();
422 assert_eq!(status, Status::OK);
423 assert!(test.is_denormal());
424 assert!(!test.is_negative());
425 assert!(test.bitwise_eq(expected));
427 // nextUp(-Denormal) -> -Denormal.
428 let test = unpack!(status=, "-0x0.ffffffffffffffffffffffff000cp-16382"
432 let expected = "-0x0.ffffffffffffffffffffffff000bp-16382".parse::<Quad>().unwrap();
433 assert_eq!(status, Status::OK);
434 assert!(test.is_denormal());
435 assert!(test.is_negative());
436 assert!(test.bitwise_eq(expected));
438 // nextDown(-Denormal) -> -Denormal
439 let test = unpack!(status=, "-0x0.ffffffffffffffffffffffff000cp-16382"
443 let expected = "-0x0.ffffffffffffffffffffffff000dp-16382".parse::<Quad>().unwrap();
444 assert_eq!(status, Status::OK);
445 assert!(test.is_denormal());
446 assert!(test.is_negative());
447 assert!(test.bitwise_eq(expected));
449 // nextUp(+Normal) -> +Normal.
450 let test = unpack!(status=, "0x1.ffffffffffffffffffffffff000cp-16000"
454 let expected = "0x1.ffffffffffffffffffffffff000dp-16000".parse::<Quad>().unwrap();
455 assert_eq!(status, Status::OK);
456 assert!(!test.is_denormal());
457 assert!(!test.is_negative());
458 assert!(test.bitwise_eq(expected));
460 // nextDown(+Normal) -> +Normal.
461 let test = unpack!(status=, "0x1.ffffffffffffffffffffffff000cp-16000"
465 let expected = "0x1.ffffffffffffffffffffffff000bp-16000".parse::<Quad>().unwrap();
466 assert_eq!(status, Status::OK);
467 assert!(!test.is_denormal());
468 assert!(!test.is_negative());
469 assert!(test.bitwise_eq(expected));
471 // nextUp(-Normal) -> -Normal.
472 let test = unpack!(status=, "-0x1.ffffffffffffffffffffffff000cp-16000"
476 let expected = "-0x1.ffffffffffffffffffffffff000bp-16000".parse::<Quad>().unwrap();
477 assert_eq!(status, Status::OK);
478 assert!(!test.is_denormal());
479 assert!(test.is_negative());
480 assert!(test.bitwise_eq(expected));
482 // nextDown(-Normal) -> -Normal.
483 let test = unpack!(status=, "-0x1.ffffffffffffffffffffffff000cp-16000"
487 let expected = "-0x1.ffffffffffffffffffffffff000dp-16000".parse::<Quad>().unwrap();
488 assert_eq!(status, Status::OK);
489 assert!(!test.is_denormal());
490 assert!(test.is_negative());
491 assert!(test.bitwise_eq(expected));
497 let mut f1 = Single::from_f32(14.5);
498 let f2 = Single::from_f32(-14.5);
499 let f3 = Single::from_f32(225.0);
500 f1 = f1.mul_add(f2, f3).value;
501 assert_eq!(14.75, f1.to_f32());
505 let val2 = Single::from_f32(2.0);
506 let mut f1 = Single::from_f32(1.17549435e-38);
507 let mut f2 = Single::from_f32(1.17549435e-38);
510 let f3 = Single::from_f32(12.0);
511 f1 = f1.mul_add(f2, f3).value;
512 assert_eq!(12.0, f1.to_f32());
515 // Test for correct zero sign when answer is exactly zero.
516 // fma(1.0, -1.0, 1.0) -> +ve 0.
518 let mut f1 = Double::from_f64(1.0);
519 let f2 = Double::from_f64(-1.0);
520 let f3 = Double::from_f64(1.0);
521 f1 = f1.mul_add(f2, f3).value;
522 assert!(!f1.is_negative() && f1.is_zero());
525 // Test for correct zero sign when answer is exactly zero and rounding towards
527 // fma(1.0, -1.0, 1.0) -> +ve 0.
529 let mut f1 = Double::from_f64(1.0);
530 let f2 = Double::from_f64(-1.0);
531 let f3 = Double::from_f64(1.0);
532 f1 = f1.mul_add_r(f2, f3, Round::TowardNegative).value;
533 assert!(f1.is_negative() && f1.is_zero());
536 // Test for correct (in this case -ve) sign when adding like signed zeros.
537 // Test fma(0.0, -0.0, -0.0) -> -ve 0.
539 let mut f1 = Double::from_f64(0.0);
540 let f2 = Double::from_f64(-0.0);
541 let f3 = Double::from_f64(-0.0);
542 f1 = f1.mul_add(f2, f3).value;
543 assert!(f1.is_negative() && f1.is_zero());
546 // Test -ve sign preservation when small negative results underflow.
548 let mut f1 = "-0x1p-1074".parse::<Double>().unwrap();
549 let f2 = "+0x1p-1074".parse::<Double>().unwrap();
550 let f3 = Double::from_f64(0.0);
551 f1 = f1.mul_add(f2, f3).value;
552 assert!(f1.is_negative() && f1.is_zero());
555 // Test x87 extended precision case from http://llvm.org/PR20728.
557 let mut m1 = X87DoubleExtended::from_u128(1).value;
558 let m2 = X87DoubleExtended::from_u128(1).value;
559 let a = X87DoubleExtended::from_u128(3).value;
561 let mut loses_info = false;
562 m1 = m1.mul_add(m2, a).value;
563 let r: Single = m1.convert(&mut loses_info).value;
564 assert!(!loses_info);
565 assert_eq!(4.0, r.to_f32());
571 let f = Double::from_bits(0x7FF0_0000_0000_0001u64 as u128);
572 let mut loses_info = false;
573 let sta = f.convert(&mut loses_info);
574 let r: Single = sta.value;
577 assert_eq!(sta.status, Status::INVALID_OP);
582 let f1 = Double::from_f64(1.0);
583 let f2 = Double::from_f64(2.0);
584 let nan = Double::NAN;
586 assert_eq!(1.0, f1.min(f2).to_f64());
587 assert_eq!(1.0, f2.min(f1).to_f64());
588 assert_eq!(1.0, f1.min(nan).to_f64());
589 assert_eq!(1.0, nan.min(f1).to_f64());
594 let f1 = Double::from_f64(1.0);
595 let f2 = Double::from_f64(2.0);
596 let nan = Double::NAN;
598 assert_eq!(2.0, f1.max(f2).to_f64());
599 assert_eq!(2.0, f2.max(f1).to_f64());
600 assert_eq!(1.0, f1.max(nan).to_f64());
601 assert_eq!(1.0, nan.max(f1).to_f64());
606 // Test single precision
608 assert!(!Single::from_f32(0.0).is_denormal());
610 let mut t = "1.17549435082228750797e-38".parse::<Single>().unwrap();
611 assert!(!t.is_denormal());
613 let val2 = Single::from_f32(2.0e0);
615 assert!(t.is_denormal());
618 // Test double precision
620 assert!(!Double::from_f64(0.0).is_denormal());
622 let mut t = "2.22507385850720138309e-308".parse::<Double>().unwrap();
623 assert!(!t.is_denormal());
625 let val2 = Double::from_f64(2.0e0);
627 assert!(t.is_denormal());
630 // Test Intel double-ext
632 assert!(!X87DoubleExtended::from_u128(0).value.is_denormal());
634 let mut t = "3.36210314311209350626e-4932".parse::<X87DoubleExtended>().unwrap();
635 assert!(!t.is_denormal());
637 t /= X87DoubleExtended::from_u128(2).value;
638 assert!(t.is_denormal());
641 // Test quadruple precision
643 assert!(!Quad::from_u128(0).value.is_denormal());
645 let mut t = "3.36210314311209350626267781732175260e-4932".parse::<Quad>().unwrap();
646 assert!(!t.is_denormal());
648 t /= Quad::from_u128(2).value;
649 assert!(t.is_denormal());
654 fn decimal_strings_without_null_terminators() {
655 // Make sure that we can parse strings without null terminators.
657 let val = "0.00"[..3].parse::<Double>().unwrap();
658 assert_eq!(val.to_f64(), 0.0);
659 let val = "0.01"[..3].parse::<Double>().unwrap();
660 assert_eq!(val.to_f64(), 0.0);
661 let val = "0.09"[..3].parse::<Double>().unwrap();
662 assert_eq!(val.to_f64(), 0.0);
663 let val = "0.095"[..4].parse::<Double>().unwrap();
664 assert_eq!(val.to_f64(), 0.09);
665 let val = "0.00e+3"[..7].parse::<Double>().unwrap();
666 assert_eq!(val.to_f64(), 0.00);
667 let val = "0e+3"[..4].parse::<Double>().unwrap();
668 assert_eq!(val.to_f64(), 0.00);
672 fn from_zero_decimal_string() {
673 assert_eq!(0.0, "0".parse::<Double>().unwrap().to_f64());
674 assert_eq!(0.0, "+0".parse::<Double>().unwrap().to_f64());
675 assert_eq!(-0.0, "-0".parse::<Double>().unwrap().to_f64());
677 assert_eq!(0.0, "0.".parse::<Double>().unwrap().to_f64());
678 assert_eq!(0.0, "+0.".parse::<Double>().unwrap().to_f64());
679 assert_eq!(-0.0, "-0.".parse::<Double>().unwrap().to_f64());
681 assert_eq!(0.0, ".0".parse::<Double>().unwrap().to_f64());
682 assert_eq!(0.0, "+.0".parse::<Double>().unwrap().to_f64());
683 assert_eq!(-0.0, "-.0".parse::<Double>().unwrap().to_f64());
685 assert_eq!(0.0, "0.0".parse::<Double>().unwrap().to_f64());
686 assert_eq!(0.0, "+0.0".parse::<Double>().unwrap().to_f64());
687 assert_eq!(-0.0, "-0.0".parse::<Double>().unwrap().to_f64());
689 assert_eq!(0.0, "00000.".parse::<Double>().unwrap().to_f64());
690 assert_eq!(0.0, "+00000.".parse::<Double>().unwrap().to_f64());
691 assert_eq!(-0.0, "-00000.".parse::<Double>().unwrap().to_f64());
693 assert_eq!(0.0, ".00000".parse::<Double>().unwrap().to_f64());
694 assert_eq!(0.0, "+.00000".parse::<Double>().unwrap().to_f64());
695 assert_eq!(-0.0, "-.00000".parse::<Double>().unwrap().to_f64());
697 assert_eq!(0.0, "0000.00000".parse::<Double>().unwrap().to_f64());
698 assert_eq!(0.0, "+0000.00000".parse::<Double>().unwrap().to_f64());
699 assert_eq!(-0.0, "-0000.00000".parse::<Double>().unwrap().to_f64());
703 fn from_zero_decimal_single_exponent_string() {
704 assert_eq!(0.0, "0e1".parse::<Double>().unwrap().to_f64());
705 assert_eq!(0.0, "+0e1".parse::<Double>().unwrap().to_f64());
706 assert_eq!(-0.0, "-0e1".parse::<Double>().unwrap().to_f64());
708 assert_eq!(0.0, "0e+1".parse::<Double>().unwrap().to_f64());
709 assert_eq!(0.0, "+0e+1".parse::<Double>().unwrap().to_f64());
710 assert_eq!(-0.0, "-0e+1".parse::<Double>().unwrap().to_f64());
712 assert_eq!(0.0, "0e-1".parse::<Double>().unwrap().to_f64());
713 assert_eq!(0.0, "+0e-1".parse::<Double>().unwrap().to_f64());
714 assert_eq!(-0.0, "-0e-1".parse::<Double>().unwrap().to_f64());
716 assert_eq!(0.0, "0.e1".parse::<Double>().unwrap().to_f64());
717 assert_eq!(0.0, "+0.e1".parse::<Double>().unwrap().to_f64());
718 assert_eq!(-0.0, "-0.e1".parse::<Double>().unwrap().to_f64());
720 assert_eq!(0.0, "0.e+1".parse::<Double>().unwrap().to_f64());
721 assert_eq!(0.0, "+0.e+1".parse::<Double>().unwrap().to_f64());
722 assert_eq!(-0.0, "-0.e+1".parse::<Double>().unwrap().to_f64());
724 assert_eq!(0.0, "0.e-1".parse::<Double>().unwrap().to_f64());
725 assert_eq!(0.0, "+0.e-1".parse::<Double>().unwrap().to_f64());
726 assert_eq!(-0.0, "-0.e-1".parse::<Double>().unwrap().to_f64());
728 assert_eq!(0.0, ".0e1".parse::<Double>().unwrap().to_f64());
729 assert_eq!(0.0, "+.0e1".parse::<Double>().unwrap().to_f64());
730 assert_eq!(-0.0, "-.0e1".parse::<Double>().unwrap().to_f64());
732 assert_eq!(0.0, ".0e+1".parse::<Double>().unwrap().to_f64());
733 assert_eq!(0.0, "+.0e+1".parse::<Double>().unwrap().to_f64());
734 assert_eq!(-0.0, "-.0e+1".parse::<Double>().unwrap().to_f64());
736 assert_eq!(0.0, ".0e-1".parse::<Double>().unwrap().to_f64());
737 assert_eq!(0.0, "+.0e-1".parse::<Double>().unwrap().to_f64());
738 assert_eq!(-0.0, "-.0e-1".parse::<Double>().unwrap().to_f64());
740 assert_eq!(0.0, "0.0e1".parse::<Double>().unwrap().to_f64());
741 assert_eq!(0.0, "+0.0e1".parse::<Double>().unwrap().to_f64());
742 assert_eq!(-0.0, "-0.0e1".parse::<Double>().unwrap().to_f64());
744 assert_eq!(0.0, "0.0e+1".parse::<Double>().unwrap().to_f64());
745 assert_eq!(0.0, "+0.0e+1".parse::<Double>().unwrap().to_f64());
746 assert_eq!(-0.0, "-0.0e+1".parse::<Double>().unwrap().to_f64());
748 assert_eq!(0.0, "0.0e-1".parse::<Double>().unwrap().to_f64());
749 assert_eq!(0.0, "+0.0e-1".parse::<Double>().unwrap().to_f64());
750 assert_eq!(-0.0, "-0.0e-1".parse::<Double>().unwrap().to_f64());
752 assert_eq!(0.0, "000.0000e1".parse::<Double>().unwrap().to_f64());
753 assert_eq!(0.0, "+000.0000e+1".parse::<Double>().unwrap().to_f64());
754 assert_eq!(-0.0, "-000.0000e+1".parse::<Double>().unwrap().to_f64());
758 fn from_zero_decimal_large_exponent_string() {
759 assert_eq!(0.0, "0e1234".parse::<Double>().unwrap().to_f64());
760 assert_eq!(0.0, "+0e1234".parse::<Double>().unwrap().to_f64());
761 assert_eq!(-0.0, "-0e1234".parse::<Double>().unwrap().to_f64());
763 assert_eq!(0.0, "0e+1234".parse::<Double>().unwrap().to_f64());
764 assert_eq!(0.0, "+0e+1234".parse::<Double>().unwrap().to_f64());
765 assert_eq!(-0.0, "-0e+1234".parse::<Double>().unwrap().to_f64());
767 assert_eq!(0.0, "0e-1234".parse::<Double>().unwrap().to_f64());
768 assert_eq!(0.0, "+0e-1234".parse::<Double>().unwrap().to_f64());
769 assert_eq!(-0.0, "-0e-1234".parse::<Double>().unwrap().to_f64());
771 assert_eq!(0.0, "000.0000e1234".parse::<Double>().unwrap().to_f64());
772 assert_eq!(0.0, "000.0000e-1234".parse::<Double>().unwrap().to_f64());
776 fn from_zero_hexadecimal_string() {
777 assert_eq!(0.0, "0x0p1".parse::<Double>().unwrap().to_f64());
778 assert_eq!(0.0, "+0x0p1".parse::<Double>().unwrap().to_f64());
779 assert_eq!(-0.0, "-0x0p1".parse::<Double>().unwrap().to_f64());
781 assert_eq!(0.0, "0x0p+1".parse::<Double>().unwrap().to_f64());
782 assert_eq!(0.0, "+0x0p+1".parse::<Double>().unwrap().to_f64());
783 assert_eq!(-0.0, "-0x0p+1".parse::<Double>().unwrap().to_f64());
785 assert_eq!(0.0, "0x0p-1".parse::<Double>().unwrap().to_f64());
786 assert_eq!(0.0, "+0x0p-1".parse::<Double>().unwrap().to_f64());
787 assert_eq!(-0.0, "-0x0p-1".parse::<Double>().unwrap().to_f64());
789 assert_eq!(0.0, "0x0.p1".parse::<Double>().unwrap().to_f64());
790 assert_eq!(0.0, "+0x0.p1".parse::<Double>().unwrap().to_f64());
791 assert_eq!(-0.0, "-0x0.p1".parse::<Double>().unwrap().to_f64());
793 assert_eq!(0.0, "0x0.p+1".parse::<Double>().unwrap().to_f64());
794 assert_eq!(0.0, "+0x0.p+1".parse::<Double>().unwrap().to_f64());
795 assert_eq!(-0.0, "-0x0.p+1".parse::<Double>().unwrap().to_f64());
797 assert_eq!(0.0, "0x0.p-1".parse::<Double>().unwrap().to_f64());
798 assert_eq!(0.0, "+0x0.p-1".parse::<Double>().unwrap().to_f64());
799 assert_eq!(-0.0, "-0x0.p-1".parse::<Double>().unwrap().to_f64());
801 assert_eq!(0.0, "0x.0p1".parse::<Double>().unwrap().to_f64());
802 assert_eq!(0.0, "+0x.0p1".parse::<Double>().unwrap().to_f64());
803 assert_eq!(-0.0, "-0x.0p1".parse::<Double>().unwrap().to_f64());
805 assert_eq!(0.0, "0x.0p+1".parse::<Double>().unwrap().to_f64());
806 assert_eq!(0.0, "+0x.0p+1".parse::<Double>().unwrap().to_f64());
807 assert_eq!(-0.0, "-0x.0p+1".parse::<Double>().unwrap().to_f64());
809 assert_eq!(0.0, "0x.0p-1".parse::<Double>().unwrap().to_f64());
810 assert_eq!(0.0, "+0x.0p-1".parse::<Double>().unwrap().to_f64());
811 assert_eq!(-0.0, "-0x.0p-1".parse::<Double>().unwrap().to_f64());
813 assert_eq!(0.0, "0x0.0p1".parse::<Double>().unwrap().to_f64());
814 assert_eq!(0.0, "+0x0.0p1".parse::<Double>().unwrap().to_f64());
815 assert_eq!(-0.0, "-0x0.0p1".parse::<Double>().unwrap().to_f64());
817 assert_eq!(0.0, "0x0.0p+1".parse::<Double>().unwrap().to_f64());
818 assert_eq!(0.0, "+0x0.0p+1".parse::<Double>().unwrap().to_f64());
819 assert_eq!(-0.0, "-0x0.0p+1".parse::<Double>().unwrap().to_f64());
821 assert_eq!(0.0, "0x0.0p-1".parse::<Double>().unwrap().to_f64());
822 assert_eq!(0.0, "+0x0.0p-1".parse::<Double>().unwrap().to_f64());
823 assert_eq!(-0.0, "-0x0.0p-1".parse::<Double>().unwrap().to_f64());
825 assert_eq!(0.0, "0x00000.p1".parse::<Double>().unwrap().to_f64());
826 assert_eq!(0.0, "0x0000.00000p1".parse::<Double>().unwrap().to_f64());
827 assert_eq!(0.0, "0x.00000p1".parse::<Double>().unwrap().to_f64());
828 assert_eq!(0.0, "0x0.p1".parse::<Double>().unwrap().to_f64());
829 assert_eq!(0.0, "0x0p1234".parse::<Double>().unwrap().to_f64());
830 assert_eq!(-0.0, "-0x0p1234".parse::<Double>().unwrap().to_f64());
831 assert_eq!(0.0, "0x00000.p1234".parse::<Double>().unwrap().to_f64());
832 assert_eq!(0.0, "0x0000.00000p1234".parse::<Double>().unwrap().to_f64());
833 assert_eq!(0.0, "0x.00000p1234".parse::<Double>().unwrap().to_f64());
834 assert_eq!(0.0, "0x0.p1234".parse::<Double>().unwrap().to_f64());
838 fn from_decimal_string() {
839 assert_eq!(1.0, "1".parse::<Double>().unwrap().to_f64());
840 assert_eq!(2.0, "2.".parse::<Double>().unwrap().to_f64());
841 assert_eq!(0.5, ".5".parse::<Double>().unwrap().to_f64());
842 assert_eq!(1.0, "1.0".parse::<Double>().unwrap().to_f64());
843 assert_eq!(-2.0, "-2".parse::<Double>().unwrap().to_f64());
844 assert_eq!(-4.0, "-4.".parse::<Double>().unwrap().to_f64());
845 assert_eq!(-0.5, "-.5".parse::<Double>().unwrap().to_f64());
846 assert_eq!(-1.5, "-1.5".parse::<Double>().unwrap().to_f64());
847 assert_eq!(1.25e12, "1.25e12".parse::<Double>().unwrap().to_f64());
848 assert_eq!(1.25e+12, "1.25e+12".parse::<Double>().unwrap().to_f64());
849 assert_eq!(1.25e-12, "1.25e-12".parse::<Double>().unwrap().to_f64());
850 assert_eq!(1024.0, "1024.".parse::<Double>().unwrap().to_f64());
851 assert_eq!(1024.05, "1024.05000".parse::<Double>().unwrap().to_f64());
852 assert_eq!(0.05, ".05000".parse::<Double>().unwrap().to_f64());
853 assert_eq!(2.0, "2.".parse::<Double>().unwrap().to_f64());
854 assert_eq!(2.0e2, "2.e2".parse::<Double>().unwrap().to_f64());
855 assert_eq!(2.0e+2, "2.e+2".parse::<Double>().unwrap().to_f64());
856 assert_eq!(2.0e-2, "2.e-2".parse::<Double>().unwrap().to_f64());
857 assert_eq!(2.05e2, "002.05000e2".parse::<Double>().unwrap().to_f64());
858 assert_eq!(2.05e+2, "002.05000e+2".parse::<Double>().unwrap().to_f64());
859 assert_eq!(2.05e-2, "002.05000e-2".parse::<Double>().unwrap().to_f64());
860 assert_eq!(2.05e12, "002.05000e12".parse::<Double>().unwrap().to_f64());
861 assert_eq!(2.05e+12, "002.05000e+12".parse::<Double>().unwrap().to_f64());
862 assert_eq!(2.05e-12, "002.05000e-12".parse::<Double>().unwrap().to_f64());
864 // These are "carefully selected" to overflow the fast log-base
865 // calculations in the implementation.
866 assert!("99e99999".parse::<Double>().unwrap().is_infinite());
867 assert!("-99e99999".parse::<Double>().unwrap().is_infinite());
868 assert!("1e-99999".parse::<Double>().unwrap().is_pos_zero());
869 assert!("-1e-99999".parse::<Double>().unwrap().is_neg_zero());
871 assert_eq!(2.71828, "2.71828".parse::<Double>().unwrap().to_f64());
875 fn from_hexadecimal_string() {
876 assert_eq!(1.0, "0x1p0".parse::<Double>().unwrap().to_f64());
877 assert_eq!(1.0, "+0x1p0".parse::<Double>().unwrap().to_f64());
878 assert_eq!(-1.0, "-0x1p0".parse::<Double>().unwrap().to_f64());
880 assert_eq!(1.0, "0x1p+0".parse::<Double>().unwrap().to_f64());
881 assert_eq!(1.0, "+0x1p+0".parse::<Double>().unwrap().to_f64());
882 assert_eq!(-1.0, "-0x1p+0".parse::<Double>().unwrap().to_f64());
884 assert_eq!(1.0, "0x1p-0".parse::<Double>().unwrap().to_f64());
885 assert_eq!(1.0, "+0x1p-0".parse::<Double>().unwrap().to_f64());
886 assert_eq!(-1.0, "-0x1p-0".parse::<Double>().unwrap().to_f64());
888 assert_eq!(2.0, "0x1p1".parse::<Double>().unwrap().to_f64());
889 assert_eq!(2.0, "+0x1p1".parse::<Double>().unwrap().to_f64());
890 assert_eq!(-2.0, "-0x1p1".parse::<Double>().unwrap().to_f64());
892 assert_eq!(2.0, "0x1p+1".parse::<Double>().unwrap().to_f64());
893 assert_eq!(2.0, "+0x1p+1".parse::<Double>().unwrap().to_f64());
894 assert_eq!(-2.0, "-0x1p+1".parse::<Double>().unwrap().to_f64());
896 assert_eq!(0.5, "0x1p-1".parse::<Double>().unwrap().to_f64());
897 assert_eq!(0.5, "+0x1p-1".parse::<Double>().unwrap().to_f64());
898 assert_eq!(-0.5, "-0x1p-1".parse::<Double>().unwrap().to_f64());
900 assert_eq!(3.0, "0x1.8p1".parse::<Double>().unwrap().to_f64());
901 assert_eq!(3.0, "+0x1.8p1".parse::<Double>().unwrap().to_f64());
902 assert_eq!(-3.0, "-0x1.8p1".parse::<Double>().unwrap().to_f64());
904 assert_eq!(3.0, "0x1.8p+1".parse::<Double>().unwrap().to_f64());
905 assert_eq!(3.0, "+0x1.8p+1".parse::<Double>().unwrap().to_f64());
906 assert_eq!(-3.0, "-0x1.8p+1".parse::<Double>().unwrap().to_f64());
908 assert_eq!(0.75, "0x1.8p-1".parse::<Double>().unwrap().to_f64());
909 assert_eq!(0.75, "+0x1.8p-1".parse::<Double>().unwrap().to_f64());
910 assert_eq!(-0.75, "-0x1.8p-1".parse::<Double>().unwrap().to_f64());
912 assert_eq!(8192.0, "0x1000.000p1".parse::<Double>().unwrap().to_f64());
913 assert_eq!(8192.0, "+0x1000.000p1".parse::<Double>().unwrap().to_f64());
914 assert_eq!(-8192.0, "-0x1000.000p1".parse::<Double>().unwrap().to_f64());
916 assert_eq!(8192.0, "0x1000.000p+1".parse::<Double>().unwrap().to_f64());
917 assert_eq!(8192.0, "+0x1000.000p+1".parse::<Double>().unwrap().to_f64());
918 assert_eq!(-8192.0, "-0x1000.000p+1".parse::<Double>().unwrap().to_f64());
920 assert_eq!(2048.0, "0x1000.000p-1".parse::<Double>().unwrap().to_f64());
921 assert_eq!(2048.0, "+0x1000.000p-1".parse::<Double>().unwrap().to_f64());
922 assert_eq!(-2048.0, "-0x1000.000p-1".parse::<Double>().unwrap().to_f64());
924 assert_eq!(8192.0, "0x1000p1".parse::<Double>().unwrap().to_f64());
925 assert_eq!(8192.0, "+0x1000p1".parse::<Double>().unwrap().to_f64());
926 assert_eq!(-8192.0, "-0x1000p1".parse::<Double>().unwrap().to_f64());
928 assert_eq!(8192.0, "0x1000p+1".parse::<Double>().unwrap().to_f64());
929 assert_eq!(8192.0, "+0x1000p+1".parse::<Double>().unwrap().to_f64());
930 assert_eq!(-8192.0, "-0x1000p+1".parse::<Double>().unwrap().to_f64());
932 assert_eq!(2048.0, "0x1000p-1".parse::<Double>().unwrap().to_f64());
933 assert_eq!(2048.0, "+0x1000p-1".parse::<Double>().unwrap().to_f64());
934 assert_eq!(-2048.0, "-0x1000p-1".parse::<Double>().unwrap().to_f64());
936 assert_eq!(16384.0, "0x10p10".parse::<Double>().unwrap().to_f64());
937 assert_eq!(16384.0, "+0x10p10".parse::<Double>().unwrap().to_f64());
938 assert_eq!(-16384.0, "-0x10p10".parse::<Double>().unwrap().to_f64());
940 assert_eq!(16384.0, "0x10p+10".parse::<Double>().unwrap().to_f64());
941 assert_eq!(16384.0, "+0x10p+10".parse::<Double>().unwrap().to_f64());
942 assert_eq!(-16384.0, "-0x10p+10".parse::<Double>().unwrap().to_f64());
944 assert_eq!(0.015625, "0x10p-10".parse::<Double>().unwrap().to_f64());
945 assert_eq!(0.015625, "+0x10p-10".parse::<Double>().unwrap().to_f64());
946 assert_eq!(-0.015625, "-0x10p-10".parse::<Double>().unwrap().to_f64());
948 assert_eq!(1.0625, "0x1.1p0".parse::<Double>().unwrap().to_f64());
949 assert_eq!(1.0, "0x1p0".parse::<Double>().unwrap().to_f64());
952 "0x1p-150".parse::<Double>().unwrap().to_f64(),
953 "+0x800000000000000001.p-221".parse::<Double>().unwrap().to_f64()
957 "0x80000000000004000000.010p-28".parse::<Double>().unwrap().to_f64()
963 let to_string = |d: f64, precision: usize, width: usize| {
964 let x = Double::from_f64(d);
966 format!("{:1$}", x, width)
968 format!("{:2$.1$}", x, precision, width)
971 assert_eq!("10", to_string(10.0, 6, 3));
972 assert_eq!("1.0E+1", to_string(10.0, 6, 0));
973 assert_eq!("10100", to_string(1.01E+4, 5, 2));
974 assert_eq!("1.01E+4", to_string(1.01E+4, 4, 2));
975 assert_eq!("1.01E+4", to_string(1.01E+4, 5, 1));
976 assert_eq!("0.0101", to_string(1.01E-2, 5, 2));
977 assert_eq!("0.0101", to_string(1.01E-2, 4, 2));
978 assert_eq!("1.01E-2", to_string(1.01E-2, 5, 1));
979 assert_eq!("0.78539816339744828", to_string(0.78539816339744830961, 0, 3));
980 assert_eq!("4.9406564584124654E-324", to_string(4.9406564584124654e-324, 0, 3));
981 assert_eq!("873.18340000000001", to_string(873.1834, 0, 1));
982 assert_eq!("8.7318340000000001E+2", to_string(873.1834, 0, 0));
983 assert_eq!("1.7976931348623157E+308", to_string(1.7976931348623157E+308, 0, 0));
985 let to_string = |d: f64, precision: usize, width: usize| {
986 let x = Double::from_f64(d);
988 format!("{:#1$}", x, width)
990 format!("{:#2$.1$}", x, precision, width)
993 assert_eq!("10", to_string(10.0, 6, 3));
994 assert_eq!("1.000000e+01", to_string(10.0, 6, 0));
995 assert_eq!("10100", to_string(1.01E+4, 5, 2));
996 assert_eq!("1.0100e+04", to_string(1.01E+4, 4, 2));
997 assert_eq!("1.01000e+04", to_string(1.01E+4, 5, 1));
998 assert_eq!("0.0101", to_string(1.01E-2, 5, 2));
999 assert_eq!("0.0101", to_string(1.01E-2, 4, 2));
1000 assert_eq!("1.01000e-02", to_string(1.01E-2, 5, 1));
1001 assert_eq!("0.78539816339744828", to_string(0.78539816339744830961, 0, 3));
1002 assert_eq!("4.94065645841246540e-324", to_string(4.9406564584124654e-324, 0, 3));
1003 assert_eq!("873.18340000000001", to_string(873.1834, 0, 1));
1004 assert_eq!("8.73183400000000010e+02", to_string(873.1834, 0, 0));
1005 assert_eq!("1.79769313486231570e+308", to_string(1.7976931348623157E+308, 0, 0));
1010 let mut is_exact = false;
1014 "10".parse::<Double>().unwrap().to_u128_r(5, Round::TowardZero, &mut is_exact,)
1019 Status::INVALID_OP.and(0),
1020 "-10".parse::<Double>().unwrap().to_u128_r(5, Round::TowardZero, &mut is_exact,)
1025 Status::INVALID_OP.and(31),
1026 "32".parse::<Double>().unwrap().to_u128_r(5, Round::TowardZero, &mut is_exact,)
1031 Status::INEXACT.and(7),
1032 "7.9".parse::<Double>().unwrap().to_u128_r(5, Round::TowardZero, &mut is_exact,)
1037 Status::OK.and(-10),
1038 "-10".parse::<Double>().unwrap().to_i128_r(5, Round::TowardZero, &mut is_exact,)
1043 Status::INVALID_OP.and(-16),
1044 "-17".parse::<Double>().unwrap().to_i128_r(5, Round::TowardZero, &mut is_exact,)
1049 Status::INVALID_OP.and(15),
1050 "16".parse::<Double>().unwrap().to_i128_r(5, Round::TowardZero, &mut is_exact,)
1057 fn nanbits<T: Float>(signaling: bool, negative: bool, fill: u128) -> u128 {
1058 let x = if signaling { T::snan(Some(fill)) } else { T::qnan(Some(fill)) };
1059 if negative { (-x).to_bits() } else { x.to_bits() }
1062 assert_eq!(0x7fc00000, nanbits::<Single>(false, false, 0));
1063 assert_eq!(0xffc00000, nanbits::<Single>(false, true, 0));
1064 assert_eq!(0x7fc0ae72, nanbits::<Single>(false, false, 0xae72));
1065 assert_eq!(0x7fffae72, nanbits::<Single>(false, false, 0xffffae72));
1066 assert_eq!(0x7fa00000, nanbits::<Single>(true, false, 0));
1067 assert_eq!(0xffa00000, nanbits::<Single>(true, true, 0));
1068 assert_eq!(0x7f80ae72, nanbits::<Single>(true, false, 0xae72));
1069 assert_eq!(0x7fbfae72, nanbits::<Single>(true, false, 0xffffae72));
1071 assert_eq!(0x7ff8000000000000, nanbits::<Double>(false, false, 0));
1072 assert_eq!(0xfff8000000000000, nanbits::<Double>(false, true, 0));
1073 assert_eq!(0x7ff800000000ae72, nanbits::<Double>(false, false, 0xae72));
1074 assert_eq!(0x7fffffffffffae72, nanbits::<Double>(false, false, 0xffffffffffffae72));
1075 assert_eq!(0x7ff4000000000000, nanbits::<Double>(true, false, 0));
1076 assert_eq!(0xfff4000000000000, nanbits::<Double>(true, true, 0));
1077 assert_eq!(0x7ff000000000ae72, nanbits::<Double>(true, false, 0xae72));
1078 assert_eq!(0x7ff7ffffffffae72, nanbits::<Double>(true, false, 0xffffffffffffae72));
1082 fn string_decimal_death() {
1083 assert_eq!("".parse::<Double>(), Err(ParseError("Invalid string length")));
1084 assert_eq!("+".parse::<Double>(), Err(ParseError("String has no digits")));
1085 assert_eq!("-".parse::<Double>(), Err(ParseError("String has no digits")));
1087 assert_eq!("\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1088 assert_eq!("1\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1089 assert_eq!("1\02".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1090 assert_eq!("1\02e1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1091 assert_eq!("1e\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1092 assert_eq!("1e1\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1093 assert_eq!("1e1\02".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1095 assert_eq!("1.0f".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1097 assert_eq!("..".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1098 assert_eq!("..0".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1099 assert_eq!("1.0.0".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1103 fn string_decimal_significand_death() {
1104 assert_eq!(".".parse::<Double>(), Err(ParseError("Significand has no digits")));
1105 assert_eq!("+.".parse::<Double>(), Err(ParseError("Significand has no digits")));
1106 assert_eq!("-.".parse::<Double>(), Err(ParseError("Significand has no digits")));
1108 assert_eq!("e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1109 assert_eq!("+e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1110 assert_eq!("-e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1112 assert_eq!("e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1113 assert_eq!("+e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1114 assert_eq!("-e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1116 assert_eq!(".e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1117 assert_eq!("+.e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1118 assert_eq!("-.e1".parse::<Double>(), Err(ParseError("Significand has no digits")));
1120 assert_eq!(".e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1121 assert_eq!("+.e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1122 assert_eq!("-.e".parse::<Double>(), Err(ParseError("Significand has no digits")));
1126 fn string_decimal_exponent_death() {
1127 assert_eq!("1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1128 assert_eq!("+1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1129 assert_eq!("-1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1131 assert_eq!("1.e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1132 assert_eq!("+1.e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1133 assert_eq!("-1.e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1135 assert_eq!(".1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1136 assert_eq!("+.1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1137 assert_eq!("-.1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1139 assert_eq!("1.1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1140 assert_eq!("+1.1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1141 assert_eq!("-1.1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1143 assert_eq!("1e+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1144 assert_eq!("1e-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1146 assert_eq!(".1e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1147 assert_eq!(".1e+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1148 assert_eq!(".1e-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1150 assert_eq!("1.0e".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1151 assert_eq!("1.0e+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1152 assert_eq!("1.0e-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1156 fn string_hexadecimal_death() {
1157 assert_eq!("0x".parse::<Double>(), Err(ParseError("Invalid string")));
1158 assert_eq!("+0x".parse::<Double>(), Err(ParseError("Invalid string")));
1159 assert_eq!("-0x".parse::<Double>(), Err(ParseError("Invalid string")));
1161 assert_eq!("0x0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1162 assert_eq!("+0x0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1163 assert_eq!("-0x0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1165 assert_eq!("0x0.".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1166 assert_eq!("+0x0.".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1167 assert_eq!("-0x0.".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1169 assert_eq!("0x.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1170 assert_eq!("+0x.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1171 assert_eq!("-0x.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1173 assert_eq!("0x0.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1174 assert_eq!("+0x0.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1175 assert_eq!("-0x0.0".parse::<Double>(), Err(ParseError("Hex strings require an exponent")));
1177 assert_eq!("0x\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1178 assert_eq!("0x1\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1179 assert_eq!("0x1\02".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1180 assert_eq!("0x1\02p1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
1181 assert_eq!("0x1p\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1182 assert_eq!("0x1p1\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1183 assert_eq!("0x1p1\02".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1185 assert_eq!("0x1p0f".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
1187 assert_eq!("0x..p1".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1188 assert_eq!("0x..0p1".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1189 assert_eq!("0x1.0.0p1".parse::<Double>(), Err(ParseError("String contains multiple dots")));
1193 fn string_hexadecimal_significand_death() {
1194 assert_eq!("0x.".parse::<Double>(), Err(ParseError("Significand has no digits")));
1195 assert_eq!("+0x.".parse::<Double>(), Err(ParseError("Significand has no digits")));
1196 assert_eq!("-0x.".parse::<Double>(), Err(ParseError("Significand has no digits")));
1198 assert_eq!("0xp".parse::<Double>(), Err(ParseError("Significand has no digits")));
1199 assert_eq!("+0xp".parse::<Double>(), Err(ParseError("Significand has no digits")));
1200 assert_eq!("-0xp".parse::<Double>(), Err(ParseError("Significand has no digits")));
1202 assert_eq!("0xp+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1203 assert_eq!("+0xp+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1204 assert_eq!("-0xp+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1206 assert_eq!("0xp-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1207 assert_eq!("+0xp-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1208 assert_eq!("-0xp-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1210 assert_eq!("0x.p".parse::<Double>(), Err(ParseError("Significand has no digits")));
1211 assert_eq!("+0x.p".parse::<Double>(), Err(ParseError("Significand has no digits")));
1212 assert_eq!("-0x.p".parse::<Double>(), Err(ParseError("Significand has no digits")));
1214 assert_eq!("0x.p+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1215 assert_eq!("+0x.p+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1216 assert_eq!("-0x.p+".parse::<Double>(), Err(ParseError("Significand has no digits")));
1218 assert_eq!("0x.p-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1219 assert_eq!("+0x.p-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1220 assert_eq!("-0x.p-".parse::<Double>(), Err(ParseError("Significand has no digits")));
1224 fn string_hexadecimal_exponent_death() {
1225 assert_eq!("0x1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1226 assert_eq!("+0x1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1227 assert_eq!("-0x1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1229 assert_eq!("0x1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1230 assert_eq!("+0x1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1231 assert_eq!("-0x1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1233 assert_eq!("0x1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1234 assert_eq!("+0x1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1235 assert_eq!("-0x1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1237 assert_eq!("0x1.p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1238 assert_eq!("+0x1.p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1239 assert_eq!("-0x1.p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1241 assert_eq!("0x1.p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1242 assert_eq!("+0x1.p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1243 assert_eq!("-0x1.p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1245 assert_eq!("0x1.p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1246 assert_eq!("+0x1.p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1247 assert_eq!("-0x1.p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1249 assert_eq!("0x.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1250 assert_eq!("+0x.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1251 assert_eq!("-0x.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1253 assert_eq!("0x.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1254 assert_eq!("+0x.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1255 assert_eq!("-0x.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1257 assert_eq!("0x.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1258 assert_eq!("+0x.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1259 assert_eq!("-0x.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1261 assert_eq!("0x1.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1262 assert_eq!("+0x1.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1263 assert_eq!("-0x1.1p".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1265 assert_eq!("0x1.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1266 assert_eq!("+0x1.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1267 assert_eq!("-0x1.1p+".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1269 assert_eq!("0x1.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1270 assert_eq!("+0x1.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1271 assert_eq!("-0x1.1p-".parse::<Double>(), Err(ParseError("Exponent has no digits")));
1275 fn exact_inverse() {
1276 // Trivial operation.
1277 assert!(Double::from_f64(2.0).get_exact_inverse().unwrap().bitwise_eq(Double::from_f64(0.5)));
1278 assert!(Single::from_f32(2.0).get_exact_inverse().unwrap().bitwise_eq(Single::from_f32(0.5)));
1283 .get_exact_inverse()
1285 .bitwise_eq("0.5".parse::<Quad>().unwrap())
1289 .parse::<X87DoubleExtended>()
1291 .get_exact_inverse()
1293 .bitwise_eq("0.5".parse::<X87DoubleExtended>().unwrap())
1298 Single::from_f32(1.17549435e-38)
1299 .get_exact_inverse()
1301 .bitwise_eq(Single::from_f32(8.5070592e+37))
1304 // Large float, inverse is a denormal.
1305 assert!(Single::from_f32(1.7014118e38).get_exact_inverse().is_none());
1307 assert!(Double::from_f64(0.0).get_exact_inverse().is_none());
1308 // Denormalized float
1309 assert!(Single::from_f32(1.40129846e-45).get_exact_inverse().is_none());
1313 fn round_to_integral() {
1314 let t = Double::from_f64(-0.5);
1315 assert_eq!(-0.0, t.round_to_integral(Round::TowardZero).value.to_f64());
1316 assert_eq!(-1.0, t.round_to_integral(Round::TowardNegative).value.to_f64());
1317 assert_eq!(-0.0, t.round_to_integral(Round::TowardPositive).value.to_f64());
1318 assert_eq!(-0.0, t.round_to_integral(Round::NearestTiesToEven).value.to_f64());
1320 let s = Double::from_f64(3.14);
1321 assert_eq!(3.0, s.round_to_integral(Round::TowardZero).value.to_f64());
1322 assert_eq!(3.0, s.round_to_integral(Round::TowardNegative).value.to_f64());
1323 assert_eq!(4.0, s.round_to_integral(Round::TowardPositive).value.to_f64());
1324 assert_eq!(3.0, s.round_to_integral(Round::NearestTiesToEven).value.to_f64());
1326 let r = Double::largest();
1327 assert_eq!(r.to_f64(), r.round_to_integral(Round::TowardZero).value.to_f64());
1328 assert_eq!(r.to_f64(), r.round_to_integral(Round::TowardNegative).value.to_f64());
1329 assert_eq!(r.to_f64(), r.round_to_integral(Round::TowardPositive).value.to_f64());
1330 assert_eq!(r.to_f64(), r.round_to_integral(Round::NearestTiesToEven).value.to_f64());
1332 let p = Double::ZERO.round_to_integral(Round::TowardZero).value;
1333 assert_eq!(0.0, p.to_f64());
1334 let p = (-Double::ZERO).round_to_integral(Round::TowardZero).value;
1335 assert_eq!(-0.0, p.to_f64());
1336 let p = Double::NAN.round_to_integral(Round::TowardZero).value;
1337 assert!(p.to_f64().is_nan());
1338 let p = Double::INFINITY.round_to_integral(Round::TowardZero).value;
1339 assert!(p.to_f64().is_infinite() && p.to_f64() > 0.0);
1340 let p = (-Double::INFINITY).round_to_integral(Round::TowardZero).value;
1341 assert!(p.to_f64().is_infinite() && p.to_f64() < 0.0);
1346 let t = Double::from_f64(-0.0);
1347 assert!(t.is_integer());
1348 let t = Double::from_f64(3.14159);
1349 assert!(!t.is_integer());
1350 let t = Double::NAN;
1351 assert!(!t.is_integer());
1352 let t = Double::INFINITY;
1353 assert!(!t.is_integer());
1354 let t = -Double::INFINITY;
1355 assert!(!t.is_integer());
1356 let t = Double::largest();
1357 assert!(t.is_integer());
1362 assert_eq!(3.402823466e+38, Single::largest().to_f32());
1363 assert_eq!(1.7976931348623158e+308, Double::largest().to_f64());
1368 let test = Single::SMALLEST;
1369 let expected = "0x0.000002p-126".parse::<Single>().unwrap();
1370 assert!(!test.is_negative());
1371 assert!(test.is_finite_non_zero());
1372 assert!(test.is_denormal());
1373 assert!(test.bitwise_eq(expected));
1375 let test = -Single::SMALLEST;
1376 let expected = "-0x0.000002p-126".parse::<Single>().unwrap();
1377 assert!(test.is_negative());
1378 assert!(test.is_finite_non_zero());
1379 assert!(test.is_denormal());
1380 assert!(test.bitwise_eq(expected));
1382 let test = Quad::SMALLEST;
1383 let expected = "0x0.0000000000000000000000000001p-16382".parse::<Quad>().unwrap();
1384 assert!(!test.is_negative());
1385 assert!(test.is_finite_non_zero());
1386 assert!(test.is_denormal());
1387 assert!(test.bitwise_eq(expected));
1389 let test = -Quad::SMALLEST;
1390 let expected = "-0x0.0000000000000000000000000001p-16382".parse::<Quad>().unwrap();
1391 assert!(test.is_negative());
1392 assert!(test.is_finite_non_zero());
1393 assert!(test.is_denormal());
1394 assert!(test.bitwise_eq(expected));
1398 fn smallest_normalized() {
1399 let test = Single::smallest_normalized();
1400 let expected = "0x1p-126".parse::<Single>().unwrap();
1401 assert!(!test.is_negative());
1402 assert!(test.is_finite_non_zero());
1403 assert!(!test.is_denormal());
1404 assert!(test.bitwise_eq(expected));
1406 let test = -Single::smallest_normalized();
1407 let expected = "-0x1p-126".parse::<Single>().unwrap();
1408 assert!(test.is_negative());
1409 assert!(test.is_finite_non_zero());
1410 assert!(!test.is_denormal());
1411 assert!(test.bitwise_eq(expected));
1413 let test = Quad::smallest_normalized();
1414 let expected = "0x1p-16382".parse::<Quad>().unwrap();
1415 assert!(!test.is_negative());
1416 assert!(test.is_finite_non_zero());
1417 assert!(!test.is_denormal());
1418 assert!(test.bitwise_eq(expected));
1420 let test = -Quad::smallest_normalized();
1421 let expected = "-0x1p-16382".parse::<Quad>().unwrap();
1422 assert!(test.is_negative());
1423 assert!(test.is_finite_non_zero());
1424 assert!(!test.is_denormal());
1425 assert!(test.bitwise_eq(expected));
1430 assert_eq!(0.0, Single::from_f32(0.0).to_f32());
1431 assert_eq!(-0.0, Single::from_f32(-0.0).to_f32());
1432 assert!(Single::from_f32(-0.0).is_negative());
1434 assert_eq!(0.0, Double::from_f64(0.0).to_f64());
1435 assert_eq!(-0.0, Double::from_f64(-0.0).to_f64());
1436 assert!(Double::from_f64(-0.0).is_negative());
1438 fn test<T: Float>(sign: bool, bits: u128) {
1439 let test = if sign { -T::ZERO } else { T::ZERO };
1440 let pattern = if sign { "-0x0p+0" } else { "0x0p+0" };
1441 let expected = pattern.parse::<T>().unwrap();
1442 assert!(test.is_zero());
1443 assert_eq!(sign, test.is_negative());
1444 assert!(test.bitwise_eq(expected));
1445 assert_eq!(bits, test.to_bits());
1447 test::<Half>(false, 0);
1448 test::<Half>(true, 0x8000);
1449 test::<Single>(false, 0);
1450 test::<Single>(true, 0x80000000);
1451 test::<Double>(false, 0);
1452 test::<Double>(true, 0x8000000000000000);
1453 test::<Quad>(false, 0);
1454 test::<Quad>(true, 0x8000000000000000_0000000000000000);
1455 test::<X87DoubleExtended>(false, 0);
1456 test::<X87DoubleExtended>(true, 0x8000_0000000000000000);
1462 Double::from_f64(-42.0)
1463 .bitwise_eq(Double::from_f64(42.0).copy_sign(Double::from_f64(-1.0),),)
1466 Double::from_f64(42.0)
1467 .bitwise_eq(Double::from_f64(-42.0).copy_sign(Double::from_f64(1.0),),)
1470 Double::from_f64(-42.0)
1471 .bitwise_eq(Double::from_f64(-42.0).copy_sign(Double::from_f64(-1.0),),)
1474 Double::from_f64(42.0)
1475 .bitwise_eq(Double::from_f64(42.0).copy_sign(Double::from_f64(1.0),),)
1481 let mut loses_info = false;
1482 let test = "1.0".parse::<Double>().unwrap();
1483 let test: Single = test.convert(&mut loses_info).value;
1484 assert_eq!(1.0, test.to_f32());
1485 assert!(!loses_info);
1487 let mut test = "0x1p-53".parse::<X87DoubleExtended>().unwrap();
1488 let one = "1.0".parse::<X87DoubleExtended>().unwrap();
1490 let test: Double = test.convert(&mut loses_info).value;
1491 assert_eq!(1.0, test.to_f64());
1492 assert!(loses_info);
1494 let mut test = "0x1p-53".parse::<Quad>().unwrap();
1495 let one = "1.0".parse::<Quad>().unwrap();
1497 let test: Double = test.convert(&mut loses_info).value;
1498 assert_eq!(1.0, test.to_f64());
1499 assert!(loses_info);
1501 let test = "0xf.fffffffp+28".parse::<X87DoubleExtended>().unwrap();
1502 let test: Double = test.convert(&mut loses_info).value;
1503 assert_eq!(4294967295.0, test.to_f64());
1504 assert!(!loses_info);
1506 let test = Single::qnan(None);
1507 let x87_qnan = X87DoubleExtended::qnan(None);
1508 let test: X87DoubleExtended = test.convert(&mut loses_info).value;
1509 assert!(test.bitwise_eq(x87_qnan));
1510 assert!(!loses_info);
1512 let test = Single::snan(None);
1513 let sta = test.convert(&mut loses_info);
1514 let test: X87DoubleExtended = sta.value;
1515 assert!(test.is_nan());
1516 assert!(!test.is_signaling());
1517 assert!(!loses_info);
1518 assert_eq!(sta.status, Status::INVALID_OP);
1520 let test = X87DoubleExtended::qnan(None);
1521 let test: X87DoubleExtended = test.convert(&mut loses_info).value;
1522 assert!(test.bitwise_eq(x87_qnan));
1523 assert!(!loses_info);
1525 let test = X87DoubleExtended::snan(None);
1526 let sta = test.convert(&mut loses_info);
1527 let test: X87DoubleExtended = sta.value;
1528 assert!(test.is_nan());
1529 assert!(!test.is_signaling());
1530 assert!(!loses_info);
1531 assert_eq!(sta.status, Status::INVALID_OP);
1536 let t = "0x1p+0".parse::<Single>().unwrap();
1537 assert!(!t.is_negative());
1538 let t = "-0x1p+0".parse::<Single>().unwrap();
1539 assert!(t.is_negative());
1541 assert!(!Single::INFINITY.is_negative());
1542 assert!((-Single::INFINITY).is_negative());
1544 assert!(!Single::ZERO.is_negative());
1545 assert!((-Single::ZERO).is_negative());
1547 assert!(!Single::NAN.is_negative());
1548 assert!((-Single::NAN).is_negative());
1550 assert!(!Single::snan(None).is_negative());
1551 assert!((-Single::snan(None)).is_negative());
1556 let t = "0x1p+0".parse::<Single>().unwrap();
1557 assert!(t.is_normal());
1559 assert!(!Single::INFINITY.is_normal());
1560 assert!(!Single::ZERO.is_normal());
1561 assert!(!Single::NAN.is_normal());
1562 assert!(!Single::snan(None).is_normal());
1563 assert!(!"0x1p-149".parse::<Single>().unwrap().is_normal());
1568 let t = "0x1p+0".parse::<Single>().unwrap();
1569 assert!(t.is_finite());
1570 assert!(!Single::INFINITY.is_finite());
1571 assert!(Single::ZERO.is_finite());
1572 assert!(!Single::NAN.is_finite());
1573 assert!(!Single::snan(None).is_finite());
1574 assert!("0x1p-149".parse::<Single>().unwrap().is_finite());
1579 let t = "0x1p+0".parse::<Single>().unwrap();
1580 assert!(!t.is_infinite());
1581 assert!(Single::INFINITY.is_infinite());
1582 assert!(!Single::ZERO.is_infinite());
1583 assert!(!Single::NAN.is_infinite());
1584 assert!(!Single::snan(None).is_infinite());
1585 assert!(!"0x1p-149".parse::<Single>().unwrap().is_infinite());
1590 let t = "0x1p+0".parse::<Single>().unwrap();
1591 assert!(!t.is_nan());
1592 assert!(!Single::INFINITY.is_nan());
1593 assert!(!Single::ZERO.is_nan());
1594 assert!(Single::NAN.is_nan());
1595 assert!(Single::snan(None).is_nan());
1596 assert!(!"0x1p-149".parse::<Single>().unwrap().is_nan());
1600 fn is_finite_non_zero() {
1601 // Test positive/negative normal value.
1602 assert!("0x1p+0".parse::<Single>().unwrap().is_finite_non_zero());
1603 assert!("-0x1p+0".parse::<Single>().unwrap().is_finite_non_zero());
1605 // Test positive/negative denormal value.
1606 assert!("0x1p-149".parse::<Single>().unwrap().is_finite_non_zero());
1607 assert!("-0x1p-149".parse::<Single>().unwrap().is_finite_non_zero());
1609 // Test +/- Infinity.
1610 assert!(!Single::INFINITY.is_finite_non_zero());
1611 assert!(!(-Single::INFINITY).is_finite_non_zero());
1614 assert!(!Single::ZERO.is_finite_non_zero());
1615 assert!(!(-Single::ZERO).is_finite_non_zero());
1617 // Test +/- qNaN. +/- don't mean anything with qNaN but paranoia can't hurt in
1619 assert!(!Single::NAN.is_finite_non_zero());
1620 assert!(!(-Single::NAN).is_finite_non_zero());
1622 // Test +/- sNaN. +/- don't mean anything with sNaN but paranoia can't hurt in
1624 assert!(!Single::snan(None).is_finite_non_zero());
1625 assert!(!(-Single::snan(None)).is_finite_non_zero());
1630 // Test Special Cases against each other and normal values.
1633 // 1. Since we perform only default exception handling all operations with
1634 // signaling NaNs should have a result that is a quiet NaN. Currently they
1637 let p_inf = Single::INFINITY;
1638 let m_inf = -Single::INFINITY;
1639 let p_zero = Single::ZERO;
1640 let m_zero = -Single::ZERO;
1641 let qnan = Single::NAN;
1642 let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
1643 let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
1644 let p_largest_value = Single::largest();
1645 let m_largest_value = -Single::largest();
1646 let p_smallest_value = Single::SMALLEST;
1647 let m_smallest_value = -Single::SMALLEST;
1648 let p_smallest_normalized = Single::smallest_normalized();
1649 let m_smallest_normalized = -Single::smallest_normalized();
1651 let overflow_status = Status::OVERFLOW | Status::INEXACT;
1653 let special_cases = [
1654 (p_inf, p_inf, "inf", Status::OK, Category::Infinity),
1655 (p_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
1656 (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
1657 (p_inf, m_zero, "inf", Status::OK, Category::Infinity),
1658 (p_inf, qnan, "nan", Status::OK, Category::NaN),
1661 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
1663 (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
1664 (p_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
1665 (p_inf, p_largest_value, "inf", Status::OK, Category::Infinity),
1666 (p_inf, m_largest_value, "inf", Status::OK, Category::Infinity),
1667 (p_inf, p_smallest_value, "inf", Status::OK, Category::Infinity),
1668 (p_inf, m_smallest_value, "inf", Status::OK, Category::Infinity),
1669 (p_inf, p_smallest_normalized, "inf", Status::OK, Category::Infinity),
1670 (p_inf, m_smallest_normalized, "inf", Status::OK, Category::Infinity),
1671 (m_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
1672 (m_inf, m_inf, "-inf", Status::OK, Category::Infinity),
1673 (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
1674 (m_inf, m_zero, "-inf", Status::OK, Category::Infinity),
1675 (m_inf, qnan, "nan", Status::OK, Category::NaN),
1678 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
1680 (m_inf, p_normal_value, "-inf", Status::OK, Category::Infinity),
1681 (m_inf, m_normal_value, "-inf", Status::OK, Category::Infinity),
1682 (m_inf, p_largest_value, "-inf", Status::OK, Category::Infinity),
1683 (m_inf, m_largest_value, "-inf", Status::OK, Category::Infinity),
1684 (m_inf, p_smallest_value, "-inf", Status::OK, Category::Infinity),
1685 (m_inf, m_smallest_value, "-inf", Status::OK, Category::Infinity),
1686 (m_inf, p_smallest_normalized, "-inf", Status::OK, Category::Infinity),
1687 (m_inf, m_smallest_normalized, "-inf", Status::OK, Category::Infinity),
1688 (p_zero, p_inf, "inf", Status::OK, Category::Infinity),
1689 (p_zero, m_inf, "-inf", Status::OK, Category::Infinity),
1690 (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
1691 (p_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
1692 (p_zero, qnan, "nan", Status::OK, Category::NaN),
1695 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
1697 (p_zero, p_normal_value, "0x1p+0", Status::OK, Category::Normal),
1698 (p_zero, m_normal_value, "-0x1p+0", Status::OK, Category::Normal),
1699 (p_zero, p_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
1700 (p_zero, m_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
1701 (p_zero, p_smallest_value, "0x1p-149", Status::OK, Category::Normal),
1702 (p_zero, m_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
1703 (p_zero, p_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
1704 (p_zero, m_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
1705 (m_zero, p_inf, "inf", Status::OK, Category::Infinity),
1706 (m_zero, m_inf, "-inf", Status::OK, Category::Infinity),
1707 (m_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
1708 (m_zero, m_zero, "-0x0p+0", Status::OK, Category::Zero),
1709 (m_zero, qnan, "nan", Status::OK, Category::NaN),
1712 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
1714 (m_zero, p_normal_value, "0x1p+0", Status::OK, Category::Normal),
1715 (m_zero, m_normal_value, "-0x1p+0", Status::OK, Category::Normal),
1716 (m_zero, p_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
1717 (m_zero, m_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
1718 (m_zero, p_smallest_value, "0x1p-149", Status::OK, Category::Normal),
1719 (m_zero, m_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
1720 (m_zero, p_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
1721 (m_zero, m_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
1722 (qnan, p_inf, "nan", Status::OK, Category::NaN),
1723 (qnan, m_inf, "nan", Status::OK, Category::NaN),
1724 (qnan, p_zero, "nan", Status::OK, Category::NaN),
1725 (qnan, m_zero, "nan", Status::OK, Category::NaN),
1726 (qnan, qnan, "nan", Status::OK, Category::NaN),
1729 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
1731 (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
1732 (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
1733 (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
1734 (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
1735 (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
1736 (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
1737 (qnan, p_smallest_normalized, "nan", Status::OK, Category::NaN),
1738 (qnan, m_smallest_normalized, "nan", Status::OK, Category::NaN),
1741 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
1742 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
1743 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
1744 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
1745 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
1746 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
1747 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
1748 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
1749 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
1750 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
1751 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
1752 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
1753 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
1754 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
1756 (p_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
1757 (p_normal_value, m_inf, "-inf", Status::OK, Category::Infinity),
1758 (p_normal_value, p_zero, "0x1p+0", Status::OK, Category::Normal),
1759 (p_normal_value, m_zero, "0x1p+0", Status::OK, Category::Normal),
1760 (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
1763 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1765 (p_normal_value, p_normal_value, "0x1p+1", Status::OK, Category::Normal),
1766 (p_normal_value, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
1767 (p_normal_value, p_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1768 (p_normal_value, m_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1769 (p_normal_value, p_smallest_value, "0x1p+0", Status::INEXACT, Category::Normal),
1770 (p_normal_value, m_smallest_value, "0x1p+0", Status::INEXACT, Category::Normal),
1771 (p_normal_value, p_smallest_normalized, "0x1p+0", Status::INEXACT, Category::Normal),
1772 (p_normal_value, m_smallest_normalized, "0x1p+0", Status::INEXACT, Category::Normal),
1773 (m_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
1774 (m_normal_value, m_inf, "-inf", Status::OK, Category::Infinity),
1775 (m_normal_value, p_zero, "-0x1p+0", Status::OK, Category::Normal),
1776 (m_normal_value, m_zero, "-0x1p+0", Status::OK, Category::Normal),
1777 (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
1780 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1782 (m_normal_value, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
1783 (m_normal_value, m_normal_value, "-0x1p+1", Status::OK, Category::Normal),
1784 (m_normal_value, p_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1785 (m_normal_value, m_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1786 (m_normal_value, p_smallest_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1787 (m_normal_value, m_smallest_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1788 (m_normal_value, p_smallest_normalized, "-0x1p+0", Status::INEXACT, Category::Normal),
1789 (m_normal_value, m_smallest_normalized, "-0x1p+0", Status::INEXACT, Category::Normal),
1790 (p_largest_value, p_inf, "inf", Status::OK, Category::Infinity),
1791 (p_largest_value, m_inf, "-inf", Status::OK, Category::Infinity),
1792 (p_largest_value, p_zero, "0x1.fffffep+127", Status::OK, Category::Normal),
1793 (p_largest_value, m_zero, "0x1.fffffep+127", Status::OK, Category::Normal),
1794 (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
1797 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1799 (p_largest_value, p_normal_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1800 (p_largest_value, m_normal_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1801 (p_largest_value, p_largest_value, "inf", overflow_status, Category::Infinity),
1802 (p_largest_value, m_largest_value, "0x0p+0", Status::OK, Category::Zero),
1803 (p_largest_value, p_smallest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1804 (p_largest_value, m_smallest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1807 p_smallest_normalized,
1814 m_smallest_normalized,
1819 (m_largest_value, p_inf, "inf", Status::OK, Category::Infinity),
1820 (m_largest_value, m_inf, "-inf", Status::OK, Category::Infinity),
1821 (m_largest_value, p_zero, "-0x1.fffffep+127", Status::OK, Category::Normal),
1822 (m_largest_value, m_zero, "-0x1.fffffep+127", Status::OK, Category::Normal),
1823 (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
1826 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1828 (m_largest_value, p_normal_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1829 (m_largest_value, m_normal_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1830 (m_largest_value, p_largest_value, "0x0p+0", Status::OK, Category::Zero),
1831 (m_largest_value, m_largest_value, "-inf", overflow_status, Category::Infinity),
1832 (m_largest_value, p_smallest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1833 (m_largest_value, m_smallest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1836 p_smallest_normalized,
1843 m_smallest_normalized,
1848 (p_smallest_value, p_inf, "inf", Status::OK, Category::Infinity),
1849 (p_smallest_value, m_inf, "-inf", Status::OK, Category::Infinity),
1850 (p_smallest_value, p_zero, "0x1p-149", Status::OK, Category::Normal),
1851 (p_smallest_value, m_zero, "0x1p-149", Status::OK, Category::Normal),
1852 (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
1855 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1857 (p_smallest_value, p_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
1858 (p_smallest_value, m_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1859 (p_smallest_value, p_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1860 (p_smallest_value, m_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1861 (p_smallest_value, p_smallest_value, "0x1p-148", Status::OK, Category::Normal),
1862 (p_smallest_value, m_smallest_value, "0x0p+0", Status::OK, Category::Zero),
1863 (p_smallest_value, p_smallest_normalized, "0x1.000002p-126", Status::OK, Category::Normal),
1864 (p_smallest_value, m_smallest_normalized, "-0x1.fffffcp-127", Status::OK, Category::Normal),
1865 (m_smallest_value, p_inf, "inf", Status::OK, Category::Infinity),
1866 (m_smallest_value, m_inf, "-inf", Status::OK, Category::Infinity),
1867 (m_smallest_value, p_zero, "-0x1p-149", Status::OK, Category::Normal),
1868 (m_smallest_value, m_zero, "-0x1p-149", Status::OK, Category::Normal),
1869 (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
1872 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
1874 (m_smallest_value, p_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
1875 (m_smallest_value, m_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1876 (m_smallest_value, p_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
1877 (m_smallest_value, m_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
1878 (m_smallest_value, p_smallest_value, "0x0p+0", Status::OK, Category::Zero),
1879 (m_smallest_value, m_smallest_value, "-0x1p-148", Status::OK, Category::Normal),
1880 (m_smallest_value, p_smallest_normalized, "0x1.fffffcp-127", Status::OK, Category::Normal),
1881 (m_smallest_value, m_smallest_normalized, "-0x1.000002p-126", Status::OK, Category::Normal),
1882 (p_smallest_normalized, p_inf, "inf", Status::OK, Category::Infinity),
1883 (p_smallest_normalized, m_inf, "-inf", Status::OK, Category::Infinity),
1884 (p_smallest_normalized, p_zero, "0x1p-126", Status::OK, Category::Normal),
1885 (p_smallest_normalized, m_zero, "0x1p-126", Status::OK, Category::Normal),
1886 (p_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
1889 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
1891 (p_smallest_normalized, p_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
1892 (p_smallest_normalized, m_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1894 p_smallest_normalized,
1901 p_smallest_normalized,
1907 (p_smallest_normalized, p_smallest_value, "0x1.000002p-126", Status::OK, Category::Normal),
1908 (p_smallest_normalized, m_smallest_value, "0x1.fffffcp-127", Status::OK, Category::Normal),
1909 (p_smallest_normalized, p_smallest_normalized, "0x1p-125", Status::OK, Category::Normal),
1910 (p_smallest_normalized, m_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
1911 (m_smallest_normalized, p_inf, "inf", Status::OK, Category::Infinity),
1912 (m_smallest_normalized, m_inf, "-inf", Status::OK, Category::Infinity),
1913 (m_smallest_normalized, p_zero, "-0x1p-126", Status::OK, Category::Normal),
1914 (m_smallest_normalized, m_zero, "-0x1p-126", Status::OK, Category::Normal),
1915 (m_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
1918 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
1920 (m_smallest_normalized, p_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
1921 (m_smallest_normalized, m_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
1923 m_smallest_normalized,
1930 m_smallest_normalized,
1936 (m_smallest_normalized, p_smallest_value, "-0x1.fffffcp-127", Status::OK, Category::Normal),
1937 (m_smallest_normalized, m_smallest_value, "-0x1.000002p-126", Status::OK, Category::Normal),
1938 (m_smallest_normalized, p_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
1939 (m_smallest_normalized, m_smallest_normalized, "-0x1p-125", Status::OK, Category::Normal),
1942 for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
1944 let result = unpack!(status=, x + y);
1945 assert_eq!(status, e_status);
1946 assert_eq!(result.category(), e_category);
1947 assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
1953 // Test Special Cases against each other and normal values.
1956 // 1. Since we perform only default exception handling all operations with
1957 // signaling NaNs should have a result that is a quiet NaN. Currently they
1960 let p_inf = Single::INFINITY;
1961 let m_inf = -Single::INFINITY;
1962 let p_zero = Single::ZERO;
1963 let m_zero = -Single::ZERO;
1964 let qnan = Single::NAN;
1965 let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
1966 let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
1967 let p_largest_value = Single::largest();
1968 let m_largest_value = -Single::largest();
1969 let p_smallest_value = Single::SMALLEST;
1970 let m_smallest_value = -Single::SMALLEST;
1971 let p_smallest_normalized = Single::smallest_normalized();
1972 let m_smallest_normalized = -Single::smallest_normalized();
1974 let overflow_status = Status::OVERFLOW | Status::INEXACT;
1976 let special_cases = [
1977 (p_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
1978 (p_inf, m_inf, "inf", Status::OK, Category::Infinity),
1979 (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
1980 (p_inf, m_zero, "inf", Status::OK, Category::Infinity),
1981 (p_inf, qnan, "-nan", Status::OK, Category::NaN),
1984 (p_inf, snan, "-nan", Status::INVALID_OP, Category::NaN),
1986 (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
1987 (p_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
1988 (p_inf, p_largest_value, "inf", Status::OK, Category::Infinity),
1989 (p_inf, m_largest_value, "inf", Status::OK, Category::Infinity),
1990 (p_inf, p_smallest_value, "inf", Status::OK, Category::Infinity),
1991 (p_inf, m_smallest_value, "inf", Status::OK, Category::Infinity),
1992 (p_inf, p_smallest_normalized, "inf", Status::OK, Category::Infinity),
1993 (p_inf, m_smallest_normalized, "inf", Status::OK, Category::Infinity),
1994 (m_inf, p_inf, "-inf", Status::OK, Category::Infinity),
1995 (m_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
1996 (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
1997 (m_inf, m_zero, "-inf", Status::OK, Category::Infinity),
1998 (m_inf, qnan, "-nan", Status::OK, Category::NaN),
2001 (m_inf, snan, "-nan", Status::INVALID_OP, Category::NaN),
2003 (m_inf, p_normal_value, "-inf", Status::OK, Category::Infinity),
2004 (m_inf, m_normal_value, "-inf", Status::OK, Category::Infinity),
2005 (m_inf, p_largest_value, "-inf", Status::OK, Category::Infinity),
2006 (m_inf, m_largest_value, "-inf", Status::OK, Category::Infinity),
2007 (m_inf, p_smallest_value, "-inf", Status::OK, Category::Infinity),
2008 (m_inf, m_smallest_value, "-inf", Status::OK, Category::Infinity),
2009 (m_inf, p_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2010 (m_inf, m_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2011 (p_zero, p_inf, "-inf", Status::OK, Category::Infinity),
2012 (p_zero, m_inf, "inf", Status::OK, Category::Infinity),
2013 (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
2014 (p_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
2015 (p_zero, qnan, "-nan", Status::OK, Category::NaN),
2018 (p_zero, snan, "-nan", Status::INVALID_OP, Category::NaN),
2020 (p_zero, p_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2021 (p_zero, m_normal_value, "0x1p+0", Status::OK, Category::Normal),
2022 (p_zero, p_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2023 (p_zero, m_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2024 (p_zero, p_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
2025 (p_zero, m_smallest_value, "0x1p-149", Status::OK, Category::Normal),
2026 (p_zero, p_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
2027 (p_zero, m_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
2028 (m_zero, p_inf, "-inf", Status::OK, Category::Infinity),
2029 (m_zero, m_inf, "inf", Status::OK, Category::Infinity),
2030 (m_zero, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2031 (m_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
2032 (m_zero, qnan, "-nan", Status::OK, Category::NaN),
2035 (m_zero, snan, "-nan", Status::INVALID_OP, Category::NaN),
2037 (m_zero, p_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2038 (m_zero, m_normal_value, "0x1p+0", Status::OK, Category::Normal),
2039 (m_zero, p_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2040 (m_zero, m_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2041 (m_zero, p_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
2042 (m_zero, m_smallest_value, "0x1p-149", Status::OK, Category::Normal),
2043 (m_zero, p_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
2044 (m_zero, m_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
2045 (qnan, p_inf, "nan", Status::OK, Category::NaN),
2046 (qnan, m_inf, "nan", Status::OK, Category::NaN),
2047 (qnan, p_zero, "nan", Status::OK, Category::NaN),
2048 (qnan, m_zero, "nan", Status::OK, Category::NaN),
2049 (qnan, qnan, "nan", Status::OK, Category::NaN),
2052 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
2054 (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
2055 (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
2056 (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
2057 (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
2058 (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
2059 (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
2060 (qnan, p_smallest_normalized, "nan", Status::OK, Category::NaN),
2061 (qnan, m_smallest_normalized, "nan", Status::OK, Category::NaN),
2064 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2065 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2066 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2067 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2068 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
2069 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
2070 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2071 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2072 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2073 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2074 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2075 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2076 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2077 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2079 (p_normal_value, p_inf, "-inf", Status::OK, Category::Infinity),
2080 (p_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
2081 (p_normal_value, p_zero, "0x1p+0", Status::OK, Category::Normal),
2082 (p_normal_value, m_zero, "0x1p+0", Status::OK, Category::Normal),
2083 (p_normal_value, qnan, "-nan", Status::OK, Category::NaN),
2086 (p_normal_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2088 (p_normal_value, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
2089 (p_normal_value, m_normal_value, "0x1p+1", Status::OK, Category::Normal),
2090 (p_normal_value, p_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2091 (p_normal_value, m_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2092 (p_normal_value, p_smallest_value, "0x1p+0", Status::INEXACT, Category::Normal),
2093 (p_normal_value, m_smallest_value, "0x1p+0", Status::INEXACT, Category::Normal),
2094 (p_normal_value, p_smallest_normalized, "0x1p+0", Status::INEXACT, Category::Normal),
2095 (p_normal_value, m_smallest_normalized, "0x1p+0", Status::INEXACT, Category::Normal),
2096 (m_normal_value, p_inf, "-inf", Status::OK, Category::Infinity),
2097 (m_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
2098 (m_normal_value, p_zero, "-0x1p+0", Status::OK, Category::Normal),
2099 (m_normal_value, m_zero, "-0x1p+0", Status::OK, Category::Normal),
2100 (m_normal_value, qnan, "-nan", Status::OK, Category::NaN),
2103 (m_normal_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2105 (m_normal_value, p_normal_value, "-0x1p+1", Status::OK, Category::Normal),
2106 (m_normal_value, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
2107 (m_normal_value, p_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2108 (m_normal_value, m_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2109 (m_normal_value, p_smallest_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2110 (m_normal_value, m_smallest_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2111 (m_normal_value, p_smallest_normalized, "-0x1p+0", Status::INEXACT, Category::Normal),
2112 (m_normal_value, m_smallest_normalized, "-0x1p+0", Status::INEXACT, Category::Normal),
2113 (p_largest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2114 (p_largest_value, m_inf, "inf", Status::OK, Category::Infinity),
2115 (p_largest_value, p_zero, "0x1.fffffep+127", Status::OK, Category::Normal),
2116 (p_largest_value, m_zero, "0x1.fffffep+127", Status::OK, Category::Normal),
2117 (p_largest_value, qnan, "-nan", Status::OK, Category::NaN),
2120 (p_largest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2122 (p_largest_value, p_normal_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2123 (p_largest_value, m_normal_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2124 (p_largest_value, p_largest_value, "0x0p+0", Status::OK, Category::Zero),
2125 (p_largest_value, m_largest_value, "inf", overflow_status, Category::Infinity),
2126 (p_largest_value, p_smallest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2127 (p_largest_value, m_smallest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2130 p_smallest_normalized,
2137 m_smallest_normalized,
2142 (m_largest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2143 (m_largest_value, m_inf, "inf", Status::OK, Category::Infinity),
2144 (m_largest_value, p_zero, "-0x1.fffffep+127", Status::OK, Category::Normal),
2145 (m_largest_value, m_zero, "-0x1.fffffep+127", Status::OK, Category::Normal),
2146 (m_largest_value, qnan, "-nan", Status::OK, Category::NaN),
2149 (m_largest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2151 (m_largest_value, p_normal_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2152 (m_largest_value, m_normal_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2153 (m_largest_value, p_largest_value, "-inf", overflow_status, Category::Infinity),
2154 (m_largest_value, m_largest_value, "0x0p+0", Status::OK, Category::Zero),
2155 (m_largest_value, p_smallest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2156 (m_largest_value, m_smallest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2159 p_smallest_normalized,
2166 m_smallest_normalized,
2171 (p_smallest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2172 (p_smallest_value, m_inf, "inf", Status::OK, Category::Infinity),
2173 (p_smallest_value, p_zero, "0x1p-149", Status::OK, Category::Normal),
2174 (p_smallest_value, m_zero, "0x1p-149", Status::OK, Category::Normal),
2175 (p_smallest_value, qnan, "-nan", Status::OK, Category::NaN),
2178 (p_smallest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2180 (p_smallest_value, p_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2181 (p_smallest_value, m_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
2182 (p_smallest_value, p_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2183 (p_smallest_value, m_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2184 (p_smallest_value, p_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2185 (p_smallest_value, m_smallest_value, "0x1p-148", Status::OK, Category::Normal),
2186 (p_smallest_value, p_smallest_normalized, "-0x1.fffffcp-127", Status::OK, Category::Normal),
2187 (p_smallest_value, m_smallest_normalized, "0x1.000002p-126", Status::OK, Category::Normal),
2188 (m_smallest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2189 (m_smallest_value, m_inf, "inf", Status::OK, Category::Infinity),
2190 (m_smallest_value, p_zero, "-0x1p-149", Status::OK, Category::Normal),
2191 (m_smallest_value, m_zero, "-0x1p-149", Status::OK, Category::Normal),
2192 (m_smallest_value, qnan, "-nan", Status::OK, Category::NaN),
2195 (m_smallest_value, snan, "-nan", Status::INVALID_OP, Category::NaN),
2197 (m_smallest_value, p_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2198 (m_smallest_value, m_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
2199 (m_smallest_value, p_largest_value, "-0x1.fffffep+127", Status::INEXACT, Category::Normal),
2200 (m_smallest_value, m_largest_value, "0x1.fffffep+127", Status::INEXACT, Category::Normal),
2201 (m_smallest_value, p_smallest_value, "-0x1p-148", Status::OK, Category::Normal),
2202 (m_smallest_value, m_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2203 (m_smallest_value, p_smallest_normalized, "-0x1.000002p-126", Status::OK, Category::Normal),
2204 (m_smallest_value, m_smallest_normalized, "0x1.fffffcp-127", Status::OK, Category::Normal),
2205 (p_smallest_normalized, p_inf, "-inf", Status::OK, Category::Infinity),
2206 (p_smallest_normalized, m_inf, "inf", Status::OK, Category::Infinity),
2207 (p_smallest_normalized, p_zero, "0x1p-126", Status::OK, Category::Normal),
2208 (p_smallest_normalized, m_zero, "0x1p-126", Status::OK, Category::Normal),
2209 (p_smallest_normalized, qnan, "-nan", Status::OK, Category::NaN),
2212 (p_smallest_normalized, snan, "-nan", Status::INVALID_OP, Category::NaN),
2214 (p_smallest_normalized, p_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2215 (p_smallest_normalized, m_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
2217 p_smallest_normalized,
2224 p_smallest_normalized,
2230 (p_smallest_normalized, p_smallest_value, "0x1.fffffcp-127", Status::OK, Category::Normal),
2231 (p_smallest_normalized, m_smallest_value, "0x1.000002p-126", Status::OK, Category::Normal),
2232 (p_smallest_normalized, p_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2233 (p_smallest_normalized, m_smallest_normalized, "0x1p-125", Status::OK, Category::Normal),
2234 (m_smallest_normalized, p_inf, "-inf", Status::OK, Category::Infinity),
2235 (m_smallest_normalized, m_inf, "inf", Status::OK, Category::Infinity),
2236 (m_smallest_normalized, p_zero, "-0x1p-126", Status::OK, Category::Normal),
2237 (m_smallest_normalized, m_zero, "-0x1p-126", Status::OK, Category::Normal),
2238 (m_smallest_normalized, qnan, "-nan", Status::OK, Category::NaN),
2241 (m_smallest_normalized, snan, "-nan", Status::INVALID_OP, Category::NaN),
2243 (m_smallest_normalized, p_normal_value, "-0x1p+0", Status::INEXACT, Category::Normal),
2244 (m_smallest_normalized, m_normal_value, "0x1p+0", Status::INEXACT, Category::Normal),
2246 m_smallest_normalized,
2253 m_smallest_normalized,
2259 (m_smallest_normalized, p_smallest_value, "-0x1.000002p-126", Status::OK, Category::Normal),
2260 (m_smallest_normalized, m_smallest_value, "-0x1.fffffcp-127", Status::OK, Category::Normal),
2261 (m_smallest_normalized, p_smallest_normalized, "-0x1p-125", Status::OK, Category::Normal),
2262 (m_smallest_normalized, m_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2265 for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
2267 let result = unpack!(status=, x - y);
2268 assert_eq!(status, e_status);
2269 assert_eq!(result.category(), e_category);
2270 assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
2276 // Test Special Cases against each other and normal values.
2279 // 1. Since we perform only default exception handling all operations with
2280 // signaling NaNs should have a result that is a quiet NaN. Currently they
2283 let p_inf = Single::INFINITY;
2284 let m_inf = -Single::INFINITY;
2285 let p_zero = Single::ZERO;
2286 let m_zero = -Single::ZERO;
2287 let qnan = Single::NAN;
2288 let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
2289 let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
2290 let p_largest_value = Single::largest();
2291 let m_largest_value = -Single::largest();
2292 let p_smallest_value = Single::SMALLEST;
2293 let m_smallest_value = -Single::SMALLEST;
2294 let p_smallest_normalized = Single::smallest_normalized();
2295 let m_smallest_normalized = -Single::smallest_normalized();
2297 let overflow_status = Status::OVERFLOW | Status::INEXACT;
2298 let underflow_status = Status::UNDERFLOW | Status::INEXACT;
2300 let special_cases = [
2301 (p_inf, p_inf, "inf", Status::OK, Category::Infinity),
2302 (p_inf, m_inf, "-inf", Status::OK, Category::Infinity),
2303 (p_inf, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2304 (p_inf, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2305 (p_inf, qnan, "nan", Status::OK, Category::NaN),
2308 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2310 (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
2311 (p_inf, m_normal_value, "-inf", Status::OK, Category::Infinity),
2312 (p_inf, p_largest_value, "inf", Status::OK, Category::Infinity),
2313 (p_inf, m_largest_value, "-inf", Status::OK, Category::Infinity),
2314 (p_inf, p_smallest_value, "inf", Status::OK, Category::Infinity),
2315 (p_inf, m_smallest_value, "-inf", Status::OK, Category::Infinity),
2316 (p_inf, p_smallest_normalized, "inf", Status::OK, Category::Infinity),
2317 (p_inf, m_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2318 (m_inf, p_inf, "-inf", Status::OK, Category::Infinity),
2319 (m_inf, m_inf, "inf", Status::OK, Category::Infinity),
2320 (m_inf, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2321 (m_inf, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2322 (m_inf, qnan, "nan", Status::OK, Category::NaN),
2325 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2327 (m_inf, p_normal_value, "-inf", Status::OK, Category::Infinity),
2328 (m_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
2329 (m_inf, p_largest_value, "-inf", Status::OK, Category::Infinity),
2330 (m_inf, m_largest_value, "inf", Status::OK, Category::Infinity),
2331 (m_inf, p_smallest_value, "-inf", Status::OK, Category::Infinity),
2332 (m_inf, m_smallest_value, "inf", Status::OK, Category::Infinity),
2333 (m_inf, p_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2334 (m_inf, m_smallest_normalized, "inf", Status::OK, Category::Infinity),
2335 (p_zero, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2336 (p_zero, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2337 (p_zero, p_zero, "0x0p+0", Status::OK, Category::Zero),
2338 (p_zero, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2339 (p_zero, qnan, "nan", Status::OK, Category::NaN),
2342 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2344 (p_zero, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
2345 (p_zero, m_normal_value, "-0x0p+0", Status::OK, Category::Zero),
2346 (p_zero, p_largest_value, "0x0p+0", Status::OK, Category::Zero),
2347 (p_zero, m_largest_value, "-0x0p+0", Status::OK, Category::Zero),
2348 (p_zero, p_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2349 (p_zero, m_smallest_value, "-0x0p+0", Status::OK, Category::Zero),
2350 (p_zero, p_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2351 (p_zero, m_smallest_normalized, "-0x0p+0", Status::OK, Category::Zero),
2352 (m_zero, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2353 (m_zero, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2354 (m_zero, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2355 (m_zero, m_zero, "0x0p+0", Status::OK, Category::Zero),
2356 (m_zero, qnan, "nan", Status::OK, Category::NaN),
2359 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2361 (m_zero, p_normal_value, "-0x0p+0", Status::OK, Category::Zero),
2362 (m_zero, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
2363 (m_zero, p_largest_value, "-0x0p+0", Status::OK, Category::Zero),
2364 (m_zero, m_largest_value, "0x0p+0", Status::OK, Category::Zero),
2365 (m_zero, p_smallest_value, "-0x0p+0", Status::OK, Category::Zero),
2366 (m_zero, m_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2367 (m_zero, p_smallest_normalized, "-0x0p+0", Status::OK, Category::Zero),
2368 (m_zero, m_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2369 (qnan, p_inf, "nan", Status::OK, Category::NaN),
2370 (qnan, m_inf, "nan", Status::OK, Category::NaN),
2371 (qnan, p_zero, "nan", Status::OK, Category::NaN),
2372 (qnan, m_zero, "nan", Status::OK, Category::NaN),
2373 (qnan, qnan, "nan", Status::OK, Category::NaN),
2376 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
2378 (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
2379 (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
2380 (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
2381 (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
2382 (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
2383 (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
2384 (qnan, p_smallest_normalized, "nan", Status::OK, Category::NaN),
2385 (qnan, m_smallest_normalized, "nan", Status::OK, Category::NaN),
2388 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2389 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2390 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2391 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2392 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
2393 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
2394 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2395 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2396 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2397 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2398 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2399 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2400 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2401 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2403 (p_normal_value, p_inf, "inf", Status::OK, Category::Infinity),
2404 (p_normal_value, m_inf, "-inf", Status::OK, Category::Infinity),
2405 (p_normal_value, p_zero, "0x0p+0", Status::OK, Category::Zero),
2406 (p_normal_value, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2407 (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
2410 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2412 (p_normal_value, p_normal_value, "0x1p+0", Status::OK, Category::Normal),
2413 (p_normal_value, m_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2414 (p_normal_value, p_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2415 (p_normal_value, m_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2416 (p_normal_value, p_smallest_value, "0x1p-149", Status::OK, Category::Normal),
2417 (p_normal_value, m_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
2418 (p_normal_value, p_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
2419 (p_normal_value, m_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
2420 (m_normal_value, p_inf, "-inf", Status::OK, Category::Infinity),
2421 (m_normal_value, m_inf, "inf", Status::OK, Category::Infinity),
2422 (m_normal_value, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2423 (m_normal_value, m_zero, "0x0p+0", Status::OK, Category::Zero),
2424 (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
2427 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2429 (m_normal_value, p_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2430 (m_normal_value, m_normal_value, "0x1p+0", Status::OK, Category::Normal),
2431 (m_normal_value, p_largest_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2432 (m_normal_value, m_largest_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2433 (m_normal_value, p_smallest_value, "-0x1p-149", Status::OK, Category::Normal),
2434 (m_normal_value, m_smallest_value, "0x1p-149", Status::OK, Category::Normal),
2435 (m_normal_value, p_smallest_normalized, "-0x1p-126", Status::OK, Category::Normal),
2436 (m_normal_value, m_smallest_normalized, "0x1p-126", Status::OK, Category::Normal),
2437 (p_largest_value, p_inf, "inf", Status::OK, Category::Infinity),
2438 (p_largest_value, m_inf, "-inf", Status::OK, Category::Infinity),
2439 (p_largest_value, p_zero, "0x0p+0", Status::OK, Category::Zero),
2440 (p_largest_value, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2441 (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
2444 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2446 (p_largest_value, p_normal_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2447 (p_largest_value, m_normal_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2448 (p_largest_value, p_largest_value, "inf", overflow_status, Category::Infinity),
2449 (p_largest_value, m_largest_value, "-inf", overflow_status, Category::Infinity),
2450 (p_largest_value, p_smallest_value, "0x1.fffffep-22", Status::OK, Category::Normal),
2451 (p_largest_value, m_smallest_value, "-0x1.fffffep-22", Status::OK, Category::Normal),
2452 (p_largest_value, p_smallest_normalized, "0x1.fffffep+1", Status::OK, Category::Normal),
2453 (p_largest_value, m_smallest_normalized, "-0x1.fffffep+1", Status::OK, Category::Normal),
2454 (m_largest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2455 (m_largest_value, m_inf, "inf", Status::OK, Category::Infinity),
2456 (m_largest_value, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2457 (m_largest_value, m_zero, "0x0p+0", Status::OK, Category::Zero),
2458 (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
2461 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2463 (m_largest_value, p_normal_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2464 (m_largest_value, m_normal_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2465 (m_largest_value, p_largest_value, "-inf", overflow_status, Category::Infinity),
2466 (m_largest_value, m_largest_value, "inf", overflow_status, Category::Infinity),
2467 (m_largest_value, p_smallest_value, "-0x1.fffffep-22", Status::OK, Category::Normal),
2468 (m_largest_value, m_smallest_value, "0x1.fffffep-22", Status::OK, Category::Normal),
2469 (m_largest_value, p_smallest_normalized, "-0x1.fffffep+1", Status::OK, Category::Normal),
2470 (m_largest_value, m_smallest_normalized, "0x1.fffffep+1", Status::OK, Category::Normal),
2471 (p_smallest_value, p_inf, "inf", Status::OK, Category::Infinity),
2472 (p_smallest_value, m_inf, "-inf", Status::OK, Category::Infinity),
2473 (p_smallest_value, p_zero, "0x0p+0", Status::OK, Category::Zero),
2474 (p_smallest_value, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2475 (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2478 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2480 (p_smallest_value, p_normal_value, "0x1p-149", Status::OK, Category::Normal),
2481 (p_smallest_value, m_normal_value, "-0x1p-149", Status::OK, Category::Normal),
2482 (p_smallest_value, p_largest_value, "0x1.fffffep-22", Status::OK, Category::Normal),
2483 (p_smallest_value, m_largest_value, "-0x1.fffffep-22", Status::OK, Category::Normal),
2484 (p_smallest_value, p_smallest_value, "0x0p+0", underflow_status, Category::Zero),
2485 (p_smallest_value, m_smallest_value, "-0x0p+0", underflow_status, Category::Zero),
2486 (p_smallest_value, p_smallest_normalized, "0x0p+0", underflow_status, Category::Zero),
2487 (p_smallest_value, m_smallest_normalized, "-0x0p+0", underflow_status, Category::Zero),
2488 (m_smallest_value, p_inf, "-inf", Status::OK, Category::Infinity),
2489 (m_smallest_value, m_inf, "inf", Status::OK, Category::Infinity),
2490 (m_smallest_value, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2491 (m_smallest_value, m_zero, "0x0p+0", Status::OK, Category::Zero),
2492 (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2495 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2497 (m_smallest_value, p_normal_value, "-0x1p-149", Status::OK, Category::Normal),
2498 (m_smallest_value, m_normal_value, "0x1p-149", Status::OK, Category::Normal),
2499 (m_smallest_value, p_largest_value, "-0x1.fffffep-22", Status::OK, Category::Normal),
2500 (m_smallest_value, m_largest_value, "0x1.fffffep-22", Status::OK, Category::Normal),
2501 (m_smallest_value, p_smallest_value, "-0x0p+0", underflow_status, Category::Zero),
2502 (m_smallest_value, m_smallest_value, "0x0p+0", underflow_status, Category::Zero),
2503 (m_smallest_value, p_smallest_normalized, "-0x0p+0", underflow_status, Category::Zero),
2504 (m_smallest_value, m_smallest_normalized, "0x0p+0", underflow_status, Category::Zero),
2505 (p_smallest_normalized, p_inf, "inf", Status::OK, Category::Infinity),
2506 (p_smallest_normalized, m_inf, "-inf", Status::OK, Category::Infinity),
2507 (p_smallest_normalized, p_zero, "0x0p+0", Status::OK, Category::Zero),
2508 (p_smallest_normalized, m_zero, "-0x0p+0", Status::OK, Category::Zero),
2509 (p_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
2512 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
2514 (p_smallest_normalized, p_normal_value, "0x1p-126", Status::OK, Category::Normal),
2515 (p_smallest_normalized, m_normal_value, "-0x1p-126", Status::OK, Category::Normal),
2516 (p_smallest_normalized, p_largest_value, "0x1.fffffep+1", Status::OK, Category::Normal),
2517 (p_smallest_normalized, m_largest_value, "-0x1.fffffep+1", Status::OK, Category::Normal),
2518 (p_smallest_normalized, p_smallest_value, "0x0p+0", underflow_status, Category::Zero),
2519 (p_smallest_normalized, m_smallest_value, "-0x0p+0", underflow_status, Category::Zero),
2520 (p_smallest_normalized, p_smallest_normalized, "0x0p+0", underflow_status, Category::Zero),
2521 (p_smallest_normalized, m_smallest_normalized, "-0x0p+0", underflow_status, Category::Zero),
2522 (m_smallest_normalized, p_inf, "-inf", Status::OK, Category::Infinity),
2523 (m_smallest_normalized, m_inf, "inf", Status::OK, Category::Infinity),
2524 (m_smallest_normalized, p_zero, "-0x0p+0", Status::OK, Category::Zero),
2525 (m_smallest_normalized, m_zero, "0x0p+0", Status::OK, Category::Zero),
2526 (m_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
2529 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
2531 (m_smallest_normalized, p_normal_value, "-0x1p-126", Status::OK, Category::Normal),
2532 (m_smallest_normalized, m_normal_value, "0x1p-126", Status::OK, Category::Normal),
2533 (m_smallest_normalized, p_largest_value, "-0x1.fffffep+1", Status::OK, Category::Normal),
2534 (m_smallest_normalized, m_largest_value, "0x1.fffffep+1", Status::OK, Category::Normal),
2535 (m_smallest_normalized, p_smallest_value, "-0x0p+0", underflow_status, Category::Zero),
2536 (m_smallest_normalized, m_smallest_value, "0x0p+0", underflow_status, Category::Zero),
2537 (m_smallest_normalized, p_smallest_normalized, "-0x0p+0", underflow_status, Category::Zero),
2538 (m_smallest_normalized, m_smallest_normalized, "0x0p+0", underflow_status, Category::Zero),
2541 for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
2543 let result = unpack!(status=, x * y);
2544 assert_eq!(status, e_status);
2545 assert_eq!(result.category(), e_category);
2546 assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
2552 // Test Special Cases against each other and normal values.
2555 // 1. Since we perform only default exception handling all operations with
2556 // signaling NaNs should have a result that is a quiet NaN. Currently they
2559 let p_inf = Single::INFINITY;
2560 let m_inf = -Single::INFINITY;
2561 let p_zero = Single::ZERO;
2562 let m_zero = -Single::ZERO;
2563 let qnan = Single::NAN;
2564 let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
2565 let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
2566 let p_largest_value = Single::largest();
2567 let m_largest_value = -Single::largest();
2568 let p_smallest_value = Single::SMALLEST;
2569 let m_smallest_value = -Single::SMALLEST;
2570 let p_smallest_normalized = Single::smallest_normalized();
2571 let m_smallest_normalized = -Single::smallest_normalized();
2573 let overflow_status = Status::OVERFLOW | Status::INEXACT;
2574 let underflow_status = Status::UNDERFLOW | Status::INEXACT;
2576 let special_cases = [
2577 (p_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2578 (p_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2579 (p_inf, p_zero, "inf", Status::OK, Category::Infinity),
2580 (p_inf, m_zero, "-inf", Status::OK, Category::Infinity),
2581 (p_inf, qnan, "nan", Status::OK, Category::NaN),
2584 (p_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2586 (p_inf, p_normal_value, "inf", Status::OK, Category::Infinity),
2587 (p_inf, m_normal_value, "-inf", Status::OK, Category::Infinity),
2588 (p_inf, p_largest_value, "inf", Status::OK, Category::Infinity),
2589 (p_inf, m_largest_value, "-inf", Status::OK, Category::Infinity),
2590 (p_inf, p_smallest_value, "inf", Status::OK, Category::Infinity),
2591 (p_inf, m_smallest_value, "-inf", Status::OK, Category::Infinity),
2592 (p_inf, p_smallest_normalized, "inf", Status::OK, Category::Infinity),
2593 (p_inf, m_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2594 (m_inf, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2595 (m_inf, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2596 (m_inf, p_zero, "-inf", Status::OK, Category::Infinity),
2597 (m_inf, m_zero, "inf", Status::OK, Category::Infinity),
2598 (m_inf, qnan, "nan", Status::OK, Category::NaN),
2601 (m_inf, snan, "nan", Status::INVALID_OP, Category::NaN),
2603 (m_inf, p_normal_value, "-inf", Status::OK, Category::Infinity),
2604 (m_inf, m_normal_value, "inf", Status::OK, Category::Infinity),
2605 (m_inf, p_largest_value, "-inf", Status::OK, Category::Infinity),
2606 (m_inf, m_largest_value, "inf", Status::OK, Category::Infinity),
2607 (m_inf, p_smallest_value, "-inf", Status::OK, Category::Infinity),
2608 (m_inf, m_smallest_value, "inf", Status::OK, Category::Infinity),
2609 (m_inf, p_smallest_normalized, "-inf", Status::OK, Category::Infinity),
2610 (m_inf, m_smallest_normalized, "inf", Status::OK, Category::Infinity),
2611 (p_zero, p_inf, "0x0p+0", Status::OK, Category::Zero),
2612 (p_zero, m_inf, "-0x0p+0", Status::OK, Category::Zero),
2613 (p_zero, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2614 (p_zero, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2615 (p_zero, qnan, "nan", Status::OK, Category::NaN),
2618 (p_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2620 (p_zero, p_normal_value, "0x0p+0", Status::OK, Category::Zero),
2621 (p_zero, m_normal_value, "-0x0p+0", Status::OK, Category::Zero),
2622 (p_zero, p_largest_value, "0x0p+0", Status::OK, Category::Zero),
2623 (p_zero, m_largest_value, "-0x0p+0", Status::OK, Category::Zero),
2624 (p_zero, p_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2625 (p_zero, m_smallest_value, "-0x0p+0", Status::OK, Category::Zero),
2626 (p_zero, p_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2627 (p_zero, m_smallest_normalized, "-0x0p+0", Status::OK, Category::Zero),
2628 (m_zero, p_inf, "-0x0p+0", Status::OK, Category::Zero),
2629 (m_zero, m_inf, "0x0p+0", Status::OK, Category::Zero),
2630 (m_zero, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2631 (m_zero, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2632 (m_zero, qnan, "nan", Status::OK, Category::NaN),
2635 (m_zero, snan, "nan", Status::INVALID_OP, Category::NaN),
2637 (m_zero, p_normal_value, "-0x0p+0", Status::OK, Category::Zero),
2638 (m_zero, m_normal_value, "0x0p+0", Status::OK, Category::Zero),
2639 (m_zero, p_largest_value, "-0x0p+0", Status::OK, Category::Zero),
2640 (m_zero, m_largest_value, "0x0p+0", Status::OK, Category::Zero),
2641 (m_zero, p_smallest_value, "-0x0p+0", Status::OK, Category::Zero),
2642 (m_zero, m_smallest_value, "0x0p+0", Status::OK, Category::Zero),
2643 (m_zero, p_smallest_normalized, "-0x0p+0", Status::OK, Category::Zero),
2644 (m_zero, m_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
2645 (qnan, p_inf, "nan", Status::OK, Category::NaN),
2646 (qnan, m_inf, "nan", Status::OK, Category::NaN),
2647 (qnan, p_zero, "nan", Status::OK, Category::NaN),
2648 (qnan, m_zero, "nan", Status::OK, Category::NaN),
2649 (qnan, qnan, "nan", Status::OK, Category::NaN),
2652 (qnan, snan, "nan", Status::INVALID_OP, Category::NaN),
2654 (qnan, p_normal_value, "nan", Status::OK, Category::NaN),
2655 (qnan, m_normal_value, "nan", Status::OK, Category::NaN),
2656 (qnan, p_largest_value, "nan", Status::OK, Category::NaN),
2657 (qnan, m_largest_value, "nan", Status::OK, Category::NaN),
2658 (qnan, p_smallest_value, "nan", Status::OK, Category::NaN),
2659 (qnan, m_smallest_value, "nan", Status::OK, Category::NaN),
2660 (qnan, p_smallest_normalized, "nan", Status::OK, Category::NaN),
2661 (qnan, m_smallest_normalized, "nan", Status::OK, Category::NaN),
2664 (snan, p_inf, "nan", Status::INVALID_OP, Category::NaN),
2665 (snan, m_inf, "nan", Status::INVALID_OP, Category::NaN),
2666 (snan, p_zero, "nan", Status::INVALID_OP, Category::NaN),
2667 (snan, m_zero, "nan", Status::INVALID_OP, Category::NaN),
2668 (snan, qnan, "nan", Status::INVALID_OP, Category::NaN),
2669 (snan, snan, "nan", Status::INVALID_OP, Category::NaN),
2670 (snan, p_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2671 (snan, m_normal_value, "nan", Status::INVALID_OP, Category::NaN),
2672 (snan, p_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2673 (snan, m_largest_value, "nan", Status::INVALID_OP, Category::NaN),
2674 (snan, p_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2675 (snan, m_smallest_value, "nan", Status::INVALID_OP, Category::NaN),
2676 (snan, p_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2677 (snan, m_smallest_normalized, "nan", Status::INVALID_OP, Category::NaN),
2679 (p_normal_value, p_inf, "0x0p+0", Status::OK, Category::Zero),
2680 (p_normal_value, m_inf, "-0x0p+0", Status::OK, Category::Zero),
2681 (p_normal_value, p_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2682 (p_normal_value, m_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2683 (p_normal_value, qnan, "nan", Status::OK, Category::NaN),
2686 (p_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2688 (p_normal_value, p_normal_value, "0x1p+0", Status::OK, Category::Normal),
2689 (p_normal_value, m_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2690 (p_normal_value, p_largest_value, "0x1p-128", underflow_status, Category::Normal),
2691 (p_normal_value, m_largest_value, "-0x1p-128", underflow_status, Category::Normal),
2692 (p_normal_value, p_smallest_value, "inf", overflow_status, Category::Infinity),
2693 (p_normal_value, m_smallest_value, "-inf", overflow_status, Category::Infinity),
2694 (p_normal_value, p_smallest_normalized, "0x1p+126", Status::OK, Category::Normal),
2695 (p_normal_value, m_smallest_normalized, "-0x1p+126", Status::OK, Category::Normal),
2696 (m_normal_value, p_inf, "-0x0p+0", Status::OK, Category::Zero),
2697 (m_normal_value, m_inf, "0x0p+0", Status::OK, Category::Zero),
2698 (m_normal_value, p_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2699 (m_normal_value, m_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2700 (m_normal_value, qnan, "nan", Status::OK, Category::NaN),
2703 (m_normal_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2705 (m_normal_value, p_normal_value, "-0x1p+0", Status::OK, Category::Normal),
2706 (m_normal_value, m_normal_value, "0x1p+0", Status::OK, Category::Normal),
2707 (m_normal_value, p_largest_value, "-0x1p-128", underflow_status, Category::Normal),
2708 (m_normal_value, m_largest_value, "0x1p-128", underflow_status, Category::Normal),
2709 (m_normal_value, p_smallest_value, "-inf", overflow_status, Category::Infinity),
2710 (m_normal_value, m_smallest_value, "inf", overflow_status, Category::Infinity),
2711 (m_normal_value, p_smallest_normalized, "-0x1p+126", Status::OK, Category::Normal),
2712 (m_normal_value, m_smallest_normalized, "0x1p+126", Status::OK, Category::Normal),
2713 (p_largest_value, p_inf, "0x0p+0", Status::OK, Category::Zero),
2714 (p_largest_value, m_inf, "-0x0p+0", Status::OK, Category::Zero),
2715 (p_largest_value, p_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2716 (p_largest_value, m_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2717 (p_largest_value, qnan, "nan", Status::OK, Category::NaN),
2720 (p_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2722 (p_largest_value, p_normal_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2723 (p_largest_value, m_normal_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2724 (p_largest_value, p_largest_value, "0x1p+0", Status::OK, Category::Normal),
2725 (p_largest_value, m_largest_value, "-0x1p+0", Status::OK, Category::Normal),
2726 (p_largest_value, p_smallest_value, "inf", overflow_status, Category::Infinity),
2727 (p_largest_value, m_smallest_value, "-inf", overflow_status, Category::Infinity),
2728 (p_largest_value, p_smallest_normalized, "inf", overflow_status, Category::Infinity),
2729 (p_largest_value, m_smallest_normalized, "-inf", overflow_status, Category::Infinity),
2730 (m_largest_value, p_inf, "-0x0p+0", Status::OK, Category::Zero),
2731 (m_largest_value, m_inf, "0x0p+0", Status::OK, Category::Zero),
2732 (m_largest_value, p_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2733 (m_largest_value, m_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2734 (m_largest_value, qnan, "nan", Status::OK, Category::NaN),
2737 (m_largest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2739 (m_largest_value, p_normal_value, "-0x1.fffffep+127", Status::OK, Category::Normal),
2740 (m_largest_value, m_normal_value, "0x1.fffffep+127", Status::OK, Category::Normal),
2741 (m_largest_value, p_largest_value, "-0x1p+0", Status::OK, Category::Normal),
2742 (m_largest_value, m_largest_value, "0x1p+0", Status::OK, Category::Normal),
2743 (m_largest_value, p_smallest_value, "-inf", overflow_status, Category::Infinity),
2744 (m_largest_value, m_smallest_value, "inf", overflow_status, Category::Infinity),
2745 (m_largest_value, p_smallest_normalized, "-inf", overflow_status, Category::Infinity),
2746 (m_largest_value, m_smallest_normalized, "inf", overflow_status, Category::Infinity),
2747 (p_smallest_value, p_inf, "0x0p+0", Status::OK, Category::Zero),
2748 (p_smallest_value, m_inf, "-0x0p+0", Status::OK, Category::Zero),
2749 (p_smallest_value, p_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2750 (p_smallest_value, m_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2751 (p_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2754 (p_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2756 (p_smallest_value, p_normal_value, "0x1p-149", Status::OK, Category::Normal),
2757 (p_smallest_value, m_normal_value, "-0x1p-149", Status::OK, Category::Normal),
2758 (p_smallest_value, p_largest_value, "0x0p+0", underflow_status, Category::Zero),
2759 (p_smallest_value, m_largest_value, "-0x0p+0", underflow_status, Category::Zero),
2760 (p_smallest_value, p_smallest_value, "0x1p+0", Status::OK, Category::Normal),
2761 (p_smallest_value, m_smallest_value, "-0x1p+0", Status::OK, Category::Normal),
2762 (p_smallest_value, p_smallest_normalized, "0x1p-23", Status::OK, Category::Normal),
2763 (p_smallest_value, m_smallest_normalized, "-0x1p-23", Status::OK, Category::Normal),
2764 (m_smallest_value, p_inf, "-0x0p+0", Status::OK, Category::Zero),
2765 (m_smallest_value, m_inf, "0x0p+0", Status::OK, Category::Zero),
2766 (m_smallest_value, p_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2767 (m_smallest_value, m_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2768 (m_smallest_value, qnan, "nan", Status::OK, Category::NaN),
2771 (m_smallest_value, snan, "nan", Status::INVALID_OP, Category::NaN),
2773 (m_smallest_value, p_normal_value, "-0x1p-149", Status::OK, Category::Normal),
2774 (m_smallest_value, m_normal_value, "0x1p-149", Status::OK, Category::Normal),
2775 (m_smallest_value, p_largest_value, "-0x0p+0", underflow_status, Category::Zero),
2776 (m_smallest_value, m_largest_value, "0x0p+0", underflow_status, Category::Zero),
2777 (m_smallest_value, p_smallest_value, "-0x1p+0", Status::OK, Category::Normal),
2778 (m_smallest_value, m_smallest_value, "0x1p+0", Status::OK, Category::Normal),
2779 (m_smallest_value, p_smallest_normalized, "-0x1p-23", Status::OK, Category::Normal),
2780 (m_smallest_value, m_smallest_normalized, "0x1p-23", Status::OK, Category::Normal),
2781 (p_smallest_normalized, p_inf, "0x0p+0", Status::OK, Category::Zero),
2782 (p_smallest_normalized, m_inf, "-0x0p+0", Status::OK, Category::Zero),
2783 (p_smallest_normalized, p_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2784 (p_smallest_normalized, m_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2785 (p_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
2788 (p_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
2790 (p_smallest_normalized, p_normal_value, "0x1p-126", Status::OK, Category::Normal),
2791 (p_smallest_normalized, m_normal_value, "-0x1p-126", Status::OK, Category::Normal),
2792 (p_smallest_normalized, p_largest_value, "0x0p+0", underflow_status, Category::Zero),
2793 (p_smallest_normalized, m_largest_value, "-0x0p+0", underflow_status, Category::Zero),
2794 (p_smallest_normalized, p_smallest_value, "0x1p+23", Status::OK, Category::Normal),
2795 (p_smallest_normalized, m_smallest_value, "-0x1p+23", Status::OK, Category::Normal),
2796 (p_smallest_normalized, p_smallest_normalized, "0x1p+0", Status::OK, Category::Normal),
2797 (p_smallest_normalized, m_smallest_normalized, "-0x1p+0", Status::OK, Category::Normal),
2798 (m_smallest_normalized, p_inf, "-0x0p+0", Status::OK, Category::Zero),
2799 (m_smallest_normalized, m_inf, "0x0p+0", Status::OK, Category::Zero),
2800 (m_smallest_normalized, p_zero, "-inf", Status::DIV_BY_ZERO, Category::Infinity),
2801 (m_smallest_normalized, m_zero, "inf", Status::DIV_BY_ZERO, Category::Infinity),
2802 (m_smallest_normalized, qnan, "nan", Status::OK, Category::NaN),
2805 (m_smallest_normalized, snan, "nan", Status::INVALID_OP, Category::NaN),
2807 (m_smallest_normalized, p_normal_value, "-0x1p-126", Status::OK, Category::Normal),
2808 (m_smallest_normalized, m_normal_value, "0x1p-126", Status::OK, Category::Normal),
2809 (m_smallest_normalized, p_largest_value, "-0x0p+0", underflow_status, Category::Zero),
2810 (m_smallest_normalized, m_largest_value, "0x0p+0", underflow_status, Category::Zero),
2811 (m_smallest_normalized, p_smallest_value, "-0x1p+23", Status::OK, Category::Normal),
2812 (m_smallest_normalized, m_smallest_value, "0x1p+23", Status::OK, Category::Normal),
2813 (m_smallest_normalized, p_smallest_normalized, "-0x1p+0", Status::OK, Category::Normal),
2814 (m_smallest_normalized, m_smallest_normalized, "0x1p+0", Status::OK, Category::Normal),
2817 for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
2819 let result = unpack!(status=, x / y);
2820 assert_eq!(status, e_status);
2821 assert_eq!(result.category(), e_category);
2822 assert!(result.bitwise_eq(e_result.parse::<Single>().unwrap()));
2827 fn operator_overloads() {
2828 // This is mostly testing that these operator overloads compile.
2829 let one = "0x1p+0".parse::<Single>().unwrap();
2830 let two = "0x2p+0".parse::<Single>().unwrap();
2831 assert!(two.bitwise_eq((one + one).value));
2832 assert!(one.bitwise_eq((two - one).value));
2833 assert!(two.bitwise_eq((one * two).value));
2834 assert!(one.bitwise_eq((two / two).value));
2839 let p_inf = Single::INFINITY;
2840 let m_inf = -Single::INFINITY;
2841 let p_zero = Single::ZERO;
2842 let m_zero = -Single::ZERO;
2843 let p_qnan = Single::NAN;
2844 let m_qnan = -Single::NAN;
2845 let p_snan = Single::snan(None);
2846 let m_snan = -Single::snan(None);
2847 let p_normal_value = "0x1p+0".parse::<Single>().unwrap();
2848 let m_normal_value = "-0x1p+0".parse::<Single>().unwrap();
2849 let p_largest_value = Single::largest();
2850 let m_largest_value = -Single::largest();
2851 let p_smallest_value = Single::SMALLEST;
2852 let m_smallest_value = -Single::SMALLEST;
2853 let p_smallest_normalized = Single::smallest_normalized();
2854 let m_smallest_normalized = -Single::smallest_normalized();
2856 assert!(p_inf.bitwise_eq(p_inf.abs()));
2857 assert!(p_inf.bitwise_eq(m_inf.abs()));
2858 assert!(p_zero.bitwise_eq(p_zero.abs()));
2859 assert!(p_zero.bitwise_eq(m_zero.abs()));
2860 assert!(p_qnan.bitwise_eq(p_qnan.abs()));
2861 assert!(p_qnan.bitwise_eq(m_qnan.abs()));
2862 assert!(p_snan.bitwise_eq(p_snan.abs()));
2863 assert!(p_snan.bitwise_eq(m_snan.abs()));
2864 assert!(p_normal_value.bitwise_eq(p_normal_value.abs()));
2865 assert!(p_normal_value.bitwise_eq(m_normal_value.abs()));
2866 assert!(p_largest_value.bitwise_eq(p_largest_value.abs()));
2867 assert!(p_largest_value.bitwise_eq(m_largest_value.abs()));
2868 assert!(p_smallest_value.bitwise_eq(p_smallest_value.abs()));
2869 assert!(p_smallest_value.bitwise_eq(m_smallest_value.abs()));
2870 assert!(p_smallest_normalized.bitwise_eq(p_smallest_normalized.abs(),));
2871 assert!(p_smallest_normalized.bitwise_eq(m_smallest_normalized.abs(),));
2876 let one = "1.0".parse::<Single>().unwrap();
2877 let neg_one = "-1.0".parse::<Single>().unwrap();
2878 let zero = Single::ZERO;
2879 let neg_zero = -Single::ZERO;
2880 let inf = Single::INFINITY;
2881 let neg_inf = -Single::INFINITY;
2882 let qnan = Single::NAN;
2883 let neg_qnan = -Single::NAN;
2885 assert!(neg_one.bitwise_eq(-one));
2886 assert!(one.bitwise_eq(-neg_one));
2887 assert!(neg_zero.bitwise_eq(-zero));
2888 assert!(zero.bitwise_eq(-neg_zero));
2889 assert!(neg_inf.bitwise_eq(-inf));
2890 assert!(inf.bitwise_eq(-neg_inf));
2891 assert!(neg_inf.bitwise_eq(-inf));
2892 assert!(inf.bitwise_eq(-neg_inf));
2893 assert!(neg_qnan.bitwise_eq(-qnan));
2894 assert!(qnan.bitwise_eq(-neg_qnan));
2899 assert_eq!(-1074, Double::SMALLEST.ilogb());
2900 assert_eq!(-1074, (-Double::SMALLEST).ilogb());
2901 assert_eq!(-1023, "0x1.ffffffffffffep-1024".parse::<Double>().unwrap().ilogb());
2902 assert_eq!(-1023, "0x1.ffffffffffffep-1023".parse::<Double>().unwrap().ilogb());
2903 assert_eq!(-1023, "-0x1.ffffffffffffep-1023".parse::<Double>().unwrap().ilogb());
2904 assert_eq!(-51, "0x1p-51".parse::<Double>().unwrap().ilogb());
2905 assert_eq!(-1023, "0x1.c60f120d9f87cp-1023".parse::<Double>().unwrap().ilogb());
2906 assert_eq!(-2, "0x0.ffffp-1".parse::<Double>().unwrap().ilogb());
2907 assert_eq!(-1023, "0x1.fffep-1023".parse::<Double>().unwrap().ilogb());
2908 assert_eq!(1023, Double::largest().ilogb());
2909 assert_eq!(1023, (-Double::largest()).ilogb());
2911 assert_eq!(0, "0x1p+0".parse::<Single>().unwrap().ilogb());
2912 assert_eq!(0, "-0x1p+0".parse::<Single>().unwrap().ilogb());
2913 assert_eq!(42, "0x1p+42".parse::<Single>().unwrap().ilogb());
2914 assert_eq!(-42, "0x1p-42".parse::<Single>().unwrap().ilogb());
2916 assert_eq!(IEK_INF, Single::INFINITY.ilogb());
2917 assert_eq!(IEK_INF, (-Single::INFINITY).ilogb());
2918 assert_eq!(IEK_ZERO, Single::ZERO.ilogb());
2919 assert_eq!(IEK_ZERO, (-Single::ZERO).ilogb());
2920 assert_eq!(IEK_NAN, Single::NAN.ilogb());
2921 assert_eq!(IEK_NAN, Single::snan(None).ilogb());
2923 assert_eq!(127, Single::largest().ilogb());
2924 assert_eq!(127, (-Single::largest()).ilogb());
2926 assert_eq!(-149, Single::SMALLEST.ilogb());
2927 assert_eq!(-149, (-Single::SMALLEST).ilogb());
2928 assert_eq!(-126, Single::smallest_normalized().ilogb());
2929 assert_eq!(-126, (-Single::smallest_normalized()).ilogb());
2938 .bitwise_eq("0x1p+0".parse::<Single>().unwrap().scalbn(0),)
2944 .bitwise_eq("0x1p+0".parse::<Single>().unwrap().scalbn(42),)
2950 .bitwise_eq("0x1p+0".parse::<Single>().unwrap().scalbn(-42),)
2953 let p_inf = Single::INFINITY;
2954 let m_inf = -Single::INFINITY;
2955 let p_zero = Single::ZERO;
2956 let m_zero = -Single::ZERO;
2957 let p_qnan = Single::NAN;
2958 let m_qnan = -Single::NAN;
2959 let snan = Single::snan(None);
2961 assert!(p_inf.bitwise_eq(p_inf.scalbn(0)));
2962 assert!(m_inf.bitwise_eq(m_inf.scalbn(0)));
2963 assert!(p_zero.bitwise_eq(p_zero.scalbn(0)));
2964 assert!(m_zero.bitwise_eq(m_zero.scalbn(0)));
2965 assert!(p_qnan.bitwise_eq(p_qnan.scalbn(0)));
2966 assert!(m_qnan.bitwise_eq(m_qnan.scalbn(0)));
2967 assert!(!snan.scalbn(0).is_signaling());
2969 let scalbn_snan = snan.scalbn(1);
2970 assert!(scalbn_snan.is_nan() && !scalbn_snan.is_signaling());
2972 // Make sure highest bit of payload is preserved.
2973 let payload = (1 << 50) | (1 << 49) | (1234 << 32) | 1;
2975 let snan_with_payload = Double::snan(Some(payload));
2976 let quiet_payload = snan_with_payload.scalbn(1);
2977 assert!(quiet_payload.is_nan() && !quiet_payload.is_signaling());
2978 assert_eq!(payload, quiet_payload.to_bits() & ((1 << 51) - 1));
2980 assert!(p_inf.bitwise_eq("0x1p+0".parse::<Single>().unwrap().scalbn(128),));
2981 assert!(m_inf.bitwise_eq("-0x1p+0".parse::<Single>().unwrap().scalbn(128),));
2982 assert!(p_inf.bitwise_eq("0x1p+127".parse::<Single>().unwrap().scalbn(1),));
2983 assert!(p_zero.bitwise_eq("0x1p-127".parse::<Single>().unwrap().scalbn(-127),));
2984 assert!(m_zero.bitwise_eq("-0x1p-127".parse::<Single>().unwrap().scalbn(-127),));
2989 .bitwise_eq("-0x1p-127".parse::<Single>().unwrap().scalbn(-22),)
2991 assert!(p_zero.bitwise_eq("0x1p-126".parse::<Single>().unwrap().scalbn(-24),));
2993 let smallest_f64 = Double::SMALLEST;
2994 let neg_smallest_f64 = -Double::SMALLEST;
2996 let largest_f64 = Double::largest();
2997 let neg_largest_f64 = -Double::largest();
2999 let largest_denormal_f64 = "0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
3000 let neg_largest_denormal_f64 = "-0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
3002 assert!(smallest_f64.bitwise_eq("0x1p-1074".parse::<Double>().unwrap().scalbn(0),));
3003 assert!(neg_smallest_f64.bitwise_eq("-0x1p-1074".parse::<Double>().unwrap().scalbn(0),));
3005 assert!("0x1p+1023".parse::<Double>().unwrap().bitwise_eq(smallest_f64.scalbn(2097,),));
3007 assert!(smallest_f64.scalbn(-2097).is_pos_zero());
3008 assert!(smallest_f64.scalbn(-2098).is_pos_zero());
3009 assert!(smallest_f64.scalbn(-2099).is_pos_zero());
3010 assert!("0x1p+1022".parse::<Double>().unwrap().bitwise_eq(smallest_f64.scalbn(2096,),));
3011 assert!("0x1p+1023".parse::<Double>().unwrap().bitwise_eq(smallest_f64.scalbn(2097,),));
3012 assert!(smallest_f64.scalbn(2098).is_infinite());
3013 assert!(smallest_f64.scalbn(2099).is_infinite());
3015 // Test for integer overflows when adding to exponent.
3016 assert!(smallest_f64.scalbn(-ExpInt::MAX).is_pos_zero());
3017 assert!(largest_f64.scalbn(ExpInt::MAX).is_infinite());
3019 assert!(largest_denormal_f64.bitwise_eq(largest_denormal_f64.scalbn(0),));
3020 assert!(neg_largest_denormal_f64.bitwise_eq(neg_largest_denormal_f64.scalbn(0),));
3023 "0x1.ffffffffffffep-1022"
3026 .bitwise_eq(largest_denormal_f64.scalbn(1))
3029 "-0x1.ffffffffffffep-1021"
3032 .bitwise_eq(neg_largest_denormal_f64.scalbn(2))
3036 "0x1.ffffffffffffep+1"
3039 .bitwise_eq(largest_denormal_f64.scalbn(1024))
3041 assert!(largest_denormal_f64.scalbn(-1023).is_pos_zero());
3042 assert!(largest_denormal_f64.scalbn(-1024).is_pos_zero());
3043 assert!(largest_denormal_f64.scalbn(-2048).is_pos_zero());
3044 assert!(largest_denormal_f64.scalbn(2047).is_infinite());
3045 assert!(largest_denormal_f64.scalbn(2098).is_infinite());
3046 assert!(largest_denormal_f64.scalbn(2099).is_infinite());
3049 "0x1.ffffffffffffep-2"
3052 .bitwise_eq(largest_denormal_f64.scalbn(1021))
3055 "0x1.ffffffffffffep-1"
3058 .bitwise_eq(largest_denormal_f64.scalbn(1022))
3061 "0x1.ffffffffffffep+0"
3064 .bitwise_eq(largest_denormal_f64.scalbn(1023))
3067 "0x1.ffffffffffffep+1023"
3070 .bitwise_eq(largest_denormal_f64.scalbn(2046))
3072 assert!("0x1p+974".parse::<Double>().unwrap().bitwise_eq(smallest_f64.scalbn(2048,),));
3074 let random_denormal_f64 = "0x1.c60f120d9f87cp+51".parse::<Double>().unwrap();
3076 "0x1.c60f120d9f87cp-972"
3079 .bitwise_eq(random_denormal_f64.scalbn(-1023))
3082 "0x1.c60f120d9f87cp-1"
3085 .bitwise_eq(random_denormal_f64.scalbn(-52))
3088 "0x1.c60f120d9f87cp-2"
3091 .bitwise_eq(random_denormal_f64.scalbn(-53))
3094 "0x1.c60f120d9f87cp+0"
3097 .bitwise_eq(random_denormal_f64.scalbn(-51))
3100 assert!(random_denormal_f64.scalbn(-2097).is_pos_zero());
3101 assert!(random_denormal_f64.scalbn(-2090).is_pos_zero());
3103 assert!("-0x1p-1073".parse::<Double>().unwrap().bitwise_eq(neg_largest_f64.scalbn(-2097),));
3105 assert!("-0x1p-1024".parse::<Double>().unwrap().bitwise_eq(neg_largest_f64.scalbn(-2048),));
3107 assert!("0x1p-1073".parse::<Double>().unwrap().bitwise_eq(largest_f64.scalbn(-2097,),));
3109 assert!("0x1p-1074".parse::<Double>().unwrap().bitwise_eq(largest_f64.scalbn(-2098,),));
3110 assert!("-0x1p-1074".parse::<Double>().unwrap().bitwise_eq(neg_largest_f64.scalbn(-2098),));
3111 assert!(neg_largest_f64.scalbn(-2099).is_neg_zero());
3112 assert!(largest_f64.scalbn(1).is_infinite());
3118 .bitwise_eq("0x1p+52".parse::<Double>().unwrap().scalbn(-52),)
3125 .bitwise_eq("0x1p-51".parse::<Double>().unwrap().scalbn(-52),)
3131 let p_zero = Double::ZERO;
3132 let m_zero = -Double::ZERO;
3133 let one = Double::from_f64(1.0);
3134 let m_one = Double::from_f64(-1.0);
3136 let largest_denormal = "0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
3137 let neg_largest_denormal = "-0x1.ffffffffffffep-1023".parse::<Double>().unwrap();
3139 let smallest = Double::SMALLEST;
3140 let neg_smallest = -Double::SMALLEST;
3142 let largest = Double::largest();
3143 let neg_largest = -Double::largest();
3145 let p_inf = Double::INFINITY;
3146 let m_inf = -Double::INFINITY;
3148 let p_qnan = Double::NAN;
3149 let m_qnan = -Double::NAN;
3150 let snan = Double::snan(None);
3152 // Make sure highest bit of payload is preserved.
3153 let payload = (1 << 50) | (1 << 49) | (1234 << 32) | 1;
3155 let snan_with_payload = Double::snan(Some(payload));
3159 let frac = p_zero.frexp(&mut exp);
3161 assert!(frac.is_pos_zero());
3163 let frac = m_zero.frexp(&mut exp);
3165 assert!(frac.is_neg_zero());
3167 let frac = one.frexp(&mut exp);
3169 assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
3171 let frac = m_one.frexp(&mut exp);
3173 assert!("-0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
3175 let frac = largest_denormal.frexp(&mut exp);
3176 assert_eq!(-1022, exp);
3177 assert!("0x1.ffffffffffffep-1".parse::<Double>().unwrap().bitwise_eq(frac));
3179 let frac = neg_largest_denormal.frexp(&mut exp);
3180 assert_eq!(-1022, exp);
3181 assert!("-0x1.ffffffffffffep-1".parse::<Double>().unwrap().bitwise_eq(frac));
3183 let frac = smallest.frexp(&mut exp);
3184 assert_eq!(-1073, exp);
3185 assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
3187 let frac = neg_smallest.frexp(&mut exp);
3188 assert_eq!(-1073, exp);
3189 assert!("-0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
3191 let frac = largest.frexp(&mut exp);
3192 assert_eq!(1024, exp);
3193 assert!("0x1.fffffffffffffp-1".parse::<Double>().unwrap().bitwise_eq(frac));
3195 let frac = neg_largest.frexp(&mut exp);
3196 assert_eq!(1024, exp);
3197 assert!("-0x1.fffffffffffffp-1".parse::<Double>().unwrap().bitwise_eq(frac));
3199 let frac = p_inf.frexp(&mut exp);
3200 assert_eq!(IEK_INF, exp);
3201 assert!(frac.is_infinite() && !frac.is_negative());
3203 let frac = m_inf.frexp(&mut exp);
3204 assert_eq!(IEK_INF, exp);
3205 assert!(frac.is_infinite() && frac.is_negative());
3207 let frac = p_qnan.frexp(&mut exp);
3208 assert_eq!(IEK_NAN, exp);
3209 assert!(frac.is_nan());
3211 let frac = m_qnan.frexp(&mut exp);
3212 assert_eq!(IEK_NAN, exp);
3213 assert!(frac.is_nan());
3215 let frac = snan.frexp(&mut exp);
3216 assert_eq!(IEK_NAN, exp);
3217 assert!(frac.is_nan() && !frac.is_signaling());
3219 let frac = snan_with_payload.frexp(&mut exp);
3220 assert_eq!(IEK_NAN, exp);
3221 assert!(frac.is_nan() && !frac.is_signaling());
3222 assert_eq!(payload, frac.to_bits() & ((1 << 51) - 1));
3224 let frac = "0x0.ffffp-1".parse::<Double>().unwrap().frexp(&mut exp);
3225 assert_eq!(-1, exp);
3226 assert!("0x1.fffep-1".parse::<Double>().unwrap().bitwise_eq(frac));
3228 let frac = "0x1p-51".parse::<Double>().unwrap().frexp(&mut exp);
3229 assert_eq!(-50, exp);
3230 assert!("0x1p-1".parse::<Double>().unwrap().bitwise_eq(frac));
3232 let frac = "0x1.c60f120d9f87cp+51".parse::<Double>().unwrap().frexp(&mut exp);
3233 assert_eq!(52, exp);
3234 assert!("0x1.c60f120d9f87cp-1".parse::<Double>().unwrap().bitwise_eq(frac));
3241 let f1 = "1.5".parse::<Double>().unwrap();
3242 let f2 = "1.0".parse::<Double>().unwrap();
3243 let expected = "0.5".parse::<Double>().unwrap();
3244 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3245 assert_eq!(status, Status::OK);
3248 let f1 = "0.5".parse::<Double>().unwrap();
3249 let f2 = "1.0".parse::<Double>().unwrap();
3250 let expected = "0.5".parse::<Double>().unwrap();
3251 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3252 assert_eq!(status, Status::OK);
3255 let f1 = "0x1.3333333333333p-2".parse::<Double>().unwrap(); // 0.3
3256 let f2 = "0x1.47ae147ae147bp-7".parse::<Double>().unwrap(); // 0.01
3257 // 0.009999999999999983
3258 let expected = "0x1.47ae147ae1471p-7".parse::<Double>().unwrap();
3259 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3260 assert_eq!(status, Status::OK);
3263 let f1 = "0x1p64".parse::<Double>().unwrap(); // 1.8446744073709552e19
3264 let f2 = "1.5".parse::<Double>().unwrap();
3265 let expected = "1.0".parse::<Double>().unwrap();
3266 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3267 assert_eq!(status, Status::OK);
3270 let f1 = "0x1p1000".parse::<Double>().unwrap();
3271 let f2 = "0x1p-1000".parse::<Double>().unwrap();
3272 let expected = "0.0".parse::<Double>().unwrap();
3273 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3274 assert_eq!(status, Status::OK);
3277 let f1 = "0.0".parse::<Double>().unwrap();
3278 let f2 = "1.0".parse::<Double>().unwrap();
3279 let expected = "0.0".parse::<Double>().unwrap();
3280 assert!(unpack!(status=, f1 % f2).bitwise_eq(expected));
3281 assert_eq!(status, Status::OK);
3284 let f1 = "1.0".parse::<Double>().unwrap();
3285 let f2 = "0.0".parse::<Double>().unwrap();
3286 assert!(unpack!(status=, f1 % f2).is_nan());
3287 assert_eq!(status, Status::INVALID_OP);
3290 let f1 = "0.0".parse::<Double>().unwrap();
3291 let f2 = "0.0".parse::<Double>().unwrap();
3292 assert!(unpack!(status=, f1 % f2).is_nan());
3293 assert_eq!(status, Status::INVALID_OP);
3296 let f1 = Double::INFINITY;
3297 let f2 = "1.0".parse::<Double>().unwrap();
3298 assert!(unpack!(status=, f1 % f2).is_nan());
3299 assert_eq!(status, Status::INVALID_OP);