1 use minimal_lexical::number::Number;
2
3 #[test]
is_fast_path_test()4 fn is_fast_path_test() {
5 let mut number = Number {
6 exponent: -4,
7 mantissa: 12345,
8 many_digits: false,
9 };
10 assert_eq!(number.is_fast_path::<f32>(), true);
11 assert_eq!(number.is_fast_path::<f64>(), true);
12
13 number.exponent = -15;
14 assert_eq!(number.is_fast_path::<f32>(), false);
15 assert_eq!(number.is_fast_path::<f64>(), true);
16
17 number.exponent = -25;
18 assert_eq!(number.is_fast_path::<f32>(), false);
19 assert_eq!(number.is_fast_path::<f64>(), false);
20
21 number.exponent = 25;
22 assert_eq!(number.is_fast_path::<f32>(), false);
23 assert_eq!(number.is_fast_path::<f64>(), true);
24
25 number.exponent = 36;
26 assert_eq!(number.is_fast_path::<f32>(), false);
27 assert_eq!(number.is_fast_path::<f64>(), true);
28
29 number.exponent = 38;
30 assert_eq!(number.is_fast_path::<f32>(), false);
31 assert_eq!(number.is_fast_path::<f64>(), false);
32
33 number.mantissa = 1 << 25;
34 number.exponent = 0;
35 assert_eq!(number.is_fast_path::<f32>(), false);
36 assert_eq!(number.is_fast_path::<f64>(), true);
37
38 number.mantissa = 1 << 54;
39 assert_eq!(number.is_fast_path::<f32>(), false);
40 assert_eq!(number.is_fast_path::<f64>(), false);
41
42 number.mantissa = 1 << 52;
43 assert_eq!(number.is_fast_path::<f32>(), false);
44 assert_eq!(number.is_fast_path::<f64>(), true);
45
46 number.many_digits = true;
47 assert_eq!(number.is_fast_path::<f32>(), false);
48 assert_eq!(number.is_fast_path::<f64>(), false);
49 }
50
51 #[test]
try_fast_path_test()52 fn try_fast_path_test() {
53 let mut number = Number {
54 exponent: -4,
55 mantissa: 12345,
56 many_digits: false,
57 };
58 assert_eq!(number.try_fast_path::<f32>(), Some(1.2345));
59 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345));
60
61 number.exponent = -10;
62 assert_eq!(number.try_fast_path::<f32>(), Some(1.2345e-6));
63 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345e-6));
64
65 number.exponent = -20;
66 assert_eq!(number.try_fast_path::<f32>(), None);
67 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345e-16));
68
69 number.exponent = -25;
70 assert_eq!(number.try_fast_path::<f32>(), None);
71 assert_eq!(number.try_fast_path::<f64>(), None);
72
73 number.exponent = 12;
74 assert_eq!(number.try_fast_path::<f32>(), Some(1.2345e16));
75 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345e16));
76
77 number.exponent = 25;
78 assert_eq!(number.try_fast_path::<f32>(), None);
79 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345e29));
80
81 number.exponent = 32;
82 assert_eq!(number.try_fast_path::<f32>(), None);
83 assert_eq!(number.try_fast_path::<f64>(), Some(1.2345e36));
84
85 number.exponent = 36;
86 assert_eq!(number.try_fast_path::<f32>(), None);
87 assert_eq!(number.try_fast_path::<f64>(), None);
88 }
89