@@ -11,19 +11,92 @@ mod parse;
1111// Requires a *polymorphic literal*, i.e., one that can serve as f64 as well as f32.
1212macro_rules! test_literal {
1313 ( $x: expr) => { {
14+ let x16: f16 = $x;
1415 let x32: f32 = $x;
1516 let x64: f64 = $x;
1617 let inputs = & [ stringify!( $x) . into( ) , format!( "{:?}" , x64) , format!( "{:e}" , x64) ] ;
18+
1719 for input in inputs {
18- assert_eq!( input. parse( ) , Ok ( x64) ) ;
19- assert_eq!( input. parse( ) , Ok ( x32) ) ;
20+ assert_eq!( input. parse( ) , Ok ( x64) , "failed f64 {input}" ) ;
21+ assert_eq!( input. parse( ) , Ok ( x32) , "failed f32 {input}" ) ;
22+ assert_eq!( input. parse( ) , Ok ( x16) , "failed f16 {input}" ) ;
23+
2024 let neg_input = format!( "-{input}" ) ;
21- assert_eq!( neg_input. parse( ) , Ok ( -x64) ) ;
22- assert_eq!( neg_input. parse( ) , Ok ( -x32) ) ;
25+ assert_eq!( neg_input. parse( ) , Ok ( -x64) , "failed f64 {neg_input}" ) ;
26+ assert_eq!( neg_input. parse( ) , Ok ( -x32) , "failed f32 {neg_input}" ) ;
27+ assert_eq!( neg_input. parse( ) , Ok ( -x16) , "failed f16 {neg_input}" ) ;
2328 }
2429 } } ;
2530}
2631
32+ // #[test]
33+ // fn foo() {
34+ // use core::num::dec2flt::float::RawFloat;
35+ // use core::num::dec2flt::parse::parse_number;
36+
37+ // fn x<F: RawFloat + std::fmt::Display>(r: &str) {
38+ // let mut s = r.as_bytes();
39+ // let c = s[0];
40+ // let negative = c == b'-';
41+ // if c == b'-' || c == b'+' {
42+ // s = &s[1..];
43+ // }
44+ // let mut num = parse_number(s).unwrap();
45+ // num.negative = negative;
46+ // if let Some(value) = num.try_fast_path::<F>() {
47+ // // return Ok(value);
48+ // println!("fast path {value}");
49+ // return;
50+ // }
51+
52+ // let q = num.exponent;
53+ // let w = num.mantissa;
54+
55+ // println!(
56+ // "float {r} {q} {w} {q:#066b} {w:#066b} sm10 {} lg10 {} ty {} chk {}",
57+ // F::SMALLEST_POWER_OF_TEN,
58+ // F::LARGEST_POWER_OF_TEN,
59+ // std::any::type_name::<F>(),
60+ // if w == 0 || q < F::SMALLEST_POWER_OF_TEN as i64 {
61+ // "lt small 10"
62+ // } else if q > F::LARGEST_POWER_OF_TEN as i64 {
63+ // "gt big 10"
64+ // } else {
65+ // ""
66+ // }
67+ // );
68+ // }
69+
70+ // // test_literal2!(1e-20);
71+ // // test_literal2!(1e-30);
72+ // // test_literal2!(1e-40);
73+ // // test_literal2!(1e-50);
74+ // // test_literal2!(1e-60);
75+ // // test_literal2!(1e-63);
76+ // // test_literal2!(1e-64);
77+ // // test_literal2!(1e-65);
78+ // // test_literal2!(1e-66);
79+ // // test_literal2!(1e-70);
80+ // // test_literal2!(1e-70);
81+ // // test_literal2!(1e-70);
82+ // // test_literal2!(1e-70);
83+ // // test_literal2!(2.225073858507201136057409796709131975934819546351645648023426109724822222021076945516529523908135087914149158913039621106870086438694594645527657207407820621743379988141063267329253552286881372149012981122451451889849057222307285255133155755015914397476397983411801999323962548289017107081850690630666655994938275772572015763062690663332647565300009245888316433037779791869612049497390377829704905051080609940730262937128958950003583799967207254304360284078895771796150945516748243471030702609144621572289880258182545180325707018860872113128079512233426288368622321503775666622503982534335974568884423900265498198385487948292206894721689831099698365846814022854243330660339850886445804001034933970427567186443383770486037861622771738545623065874679014086723327636718749999999999999999999999999999999999999e-308);
84+ // // test_literal2!(1.175494140627517859246175898662808184331245864732796240031385942718174675986064769972472277004271745681762695312500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-38);
85+ // // panic!();
86+ // }
87+
88+ // #[test]
89+ // fn foobar() {
90+ // use core::num::dec2flt::float::RawFloat;
91+ // panic!(
92+ // "{} {} {} {}",
93+ // <f32 as RawFloat>::LARGEST_POWER_OF_TEN,
94+ // <f32 as RawFloat>::SMALLEST_POWER_OF_TEN,
95+ // <f64 as RawFloat>::LARGEST_POWER_OF_TEN,
96+ // <f64 as RawFloat>::SMALLEST_POWER_OF_TEN,
97+ // )
98+ // }
99+
27100#[ test]
28101fn ordinary ( ) {
29102 test_literal ! ( 1.0 ) ;
@@ -34,6 +107,65 @@ fn ordinary() {
34107 test_literal ! ( 2.2250738585072014e-308 ) ;
35108}
36109
110+ #[ test]
111+ fn stats ( ) {
112+ // use
113+ use core:: num:: dec2flt:: float:: RawFloat ;
114+ dbg ! (
115+ f16:: BITS ,
116+ f16:: MANTISSA_BITS ,
117+ f16:: MANTISSA_EXPLICIT_BITS ,
118+ f16:: EXPONENT_BITS ,
119+ f16:: MAX_EXPONENT_FAST_PATH ,
120+ f16:: MIN_EXPONENT_FAST_PATH ,
121+ f16:: MIN_EXPONENT_ROUND_TO_EVEN ,
122+ f16:: MAX_EXPONENT_ROUND_TO_EVEN ,
123+ f16:: MINIMUM_EXPONENT ,
124+ f16:: MAXIMUM_EXPONENT ,
125+ f16:: EXPONENT_BIAS ,
126+ f16:: INFINITE_POWER ,
127+ f16:: LARGEST_POWER_OF_TEN ,
128+ f16:: SMALLEST_POWER_OF_TEN ,
129+ f16:: MAX_MANTISSA_FAST_PATH
130+ ) ;
131+ dbg ! (
132+ f32 :: BITS ,
133+ f32 :: MANTISSA_BITS ,
134+ f32 :: MANTISSA_EXPLICIT_BITS ,
135+ f32 :: EXPONENT_BITS ,
136+ f32 :: MAX_EXPONENT_FAST_PATH ,
137+ f32 :: MIN_EXPONENT_FAST_PATH ,
138+ f32 :: MIN_EXPONENT_ROUND_TO_EVEN ,
139+ f32 :: MAX_EXPONENT_ROUND_TO_EVEN ,
140+ f32 :: MINIMUM_EXPONENT ,
141+ f32 :: MAXIMUM_EXPONENT ,
142+ f32 :: EXPONENT_BIAS ,
143+ f32 :: INFINITE_POWER ,
144+ f32 :: LARGEST_POWER_OF_TEN ,
145+ f32 :: SMALLEST_POWER_OF_TEN ,
146+ f32 :: MAX_MANTISSA_FAST_PATH
147+ ) ;
148+ dbg ! (
149+ f64 :: BITS ,
150+ f64 :: MANTISSA_BITS ,
151+ f64 :: MANTISSA_EXPLICIT_BITS ,
152+ f64 :: EXPONENT_BITS ,
153+ f64 :: MAX_EXPONENT_FAST_PATH ,
154+ f64 :: MIN_EXPONENT_FAST_PATH ,
155+ f64 :: MIN_EXPONENT_ROUND_TO_EVEN ,
156+ f64 :: MAX_EXPONENT_ROUND_TO_EVEN ,
157+ f64 :: MINIMUM_EXPONENT ,
158+ f64 :: MAXIMUM_EXPONENT ,
159+ f64 :: EXPONENT_BIAS ,
160+ f64 :: INFINITE_POWER ,
161+ f64 :: LARGEST_POWER_OF_TEN ,
162+ f64 :: SMALLEST_POWER_OF_TEN ,
163+ f64 :: MAX_MANTISSA_FAST_PATH
164+ ) ;
165+
166+ panic ! ( ) ;
167+ }
168+
37169#[ test]
38170fn special_code_paths ( ) {
39171 test_literal ! ( 36893488147419103229.0 ) ; // 2^65 - 3, triggers half-to-even with even significand
0 commit comments