@@ -9,19 +9,112 @@ mod parse;
99// Requires a *polymorphic literal*, i.e., one that can serve as f64 as well as f32.
1010macro_rules! test_literal {
1111 ( $x: expr) => { {
12+ let x16: f16 = $x;
1213 let x32: f32 = $x;
1314 let x64: f64 = $x;
1415 let inputs = & [ stringify!( $x) . into( ) , format!( "{:?}" , x64) , format!( "{:e}" , x64) ] ;
16+
1517 for input in inputs {
16- assert_eq!( input. parse( ) , Ok ( x64) ) ;
17- assert_eq!( input. parse( ) , Ok ( x32) ) ;
18+ assert_eq!( input. parse( ) , Ok ( x64) , "failed f64 {input}" ) ;
19+ assert_eq!( input. parse( ) , Ok ( x32) , "failed f32 {input}" ) ;
20+ assert_eq!( input. parse( ) , Ok ( x16) , "failed f16 {input}" ) ;
21+
1822 let neg_input = format!( "-{input}" ) ;
19- assert_eq!( neg_input. parse( ) , Ok ( -x64) ) ;
20- assert_eq!( neg_input. parse( ) , Ok ( -x32) ) ;
23+ assert_eq!( neg_input. parse( ) , Ok ( -x64) , "failed f64 {neg_input}" ) ;
24+ assert_eq!( neg_input. parse( ) , Ok ( -x32) , "failed f32 {neg_input}" ) ;
25+ assert_eq!( neg_input. parse( ) , Ok ( -x16) , "failed f16 {neg_input}" ) ;
2126 }
2227 } } ;
2328}
2429
30+ // macro_rules! test_literal2 {
31+ // ($x: expr) => {{
32+ // // let x32: f32 = $x;
33+ // let x64: f64 = $x;
34+ // x::<f32>(stringify!($x));
35+ // x::<f64>(stringify!($x));
36+
37+ // let inputs = &[stringify!($x).into(), format!("{:?}", x64), format!("{:e}", x64)];
38+ // for input in inputs {
39+ // println!("{}", input.parse::<f32>().unwrap());
40+ // println!("{}", input.parse::<f64>().unwrap());
41+ // // assert_eq!(input.parse(), Ok(x64), "failed f64 {input}");
42+ // // assert_eq!(input.parse(), Ok(x32), "failed f32 {input}");
43+ // // let neg_input = format!("-{input}");
44+ // // assert_eq!(neg_input.parse(), Ok(-x64), "failed f64 {neg_input}");
45+ // // assert_eq!(neg_input.parse(), Ok(-x32), "failed f32 {neg_input}");
46+ // }
47+ // }};
48+ // }
49+
50+ // #[test]
51+ // fn foo() {
52+ // use core::num::dec2flt::float::RawFloat;
53+ // use core::num::dec2flt::parse::parse_number;
54+
55+ // fn x<F: RawFloat + std::fmt::Display>(r: &str) {
56+ // let mut s = r.as_bytes();
57+ // let c = s[0];
58+ // let negative = c == b'-';
59+ // if c == b'-' || c == b'+' {
60+ // s = &s[1..];
61+ // }
62+ // let mut num = parse_number(s).unwrap();
63+ // num.negative = negative;
64+ // if let Some(value) = num.try_fast_path::<F>() {
65+ // // return Ok(value);
66+ // println!("fast path {value}");
67+ // return;
68+ // }
69+
70+ // let q = num.exponent;
71+ // let w = num.mantissa;
72+
73+ // println!(
74+ // "float {r} {q} {w} {q:#066b} {w:#066b} sm10 {} lg10 {} ty {} chk {}",
75+ // F::SMALLEST_POWER_OF_TEN,
76+ // F::LARGEST_POWER_OF_TEN,
77+ // std::any::type_name::<F>(),
78+ // if w == 0 || q < F::SMALLEST_POWER_OF_TEN as i64 {
79+ // "lt small 10"
80+ // } else if q > F::LARGEST_POWER_OF_TEN as i64 {
81+ // "gt big 10"
82+ // } else {
83+ // ""
84+ // }
85+ // );
86+ // }
87+
88+ // // test_literal2!(1e-20);
89+ // // test_literal2!(1e-30);
90+ // // test_literal2!(1e-40);
91+ // // test_literal2!(1e-50);
92+ // // test_literal2!(1e-60);
93+ // // test_literal2!(1e-63);
94+ // // test_literal2!(1e-64);
95+ // // test_literal2!(1e-65);
96+ // // test_literal2!(1e-66);
97+ // // test_literal2!(1e-70);
98+ // // test_literal2!(1e-70);
99+ // // test_literal2!(1e-70);
100+ // // test_literal2!(1e-70);
101+ // // test_literal2!(2.225073858507201136057409796709131975934819546351645648023426109724822222021076945516529523908135087914149158913039621106870086438694594645527657207407820621743379988141063267329253552286881372149012981122451451889849057222307285255133155755015914397476397983411801999323962548289017107081850690630666655994938275772572015763062690663332647565300009245888316433037779791869612049497390377829704905051080609940730262937128958950003583799967207254304360284078895771796150945516748243471030702609144621572289880258182545180325707018860872113128079512233426288368622321503775666622503982534335974568884423900265498198385487948292206894721689831099698365846814022854243330660339850886445804001034933970427567186443383770486037861622771738545623065874679014086723327636718749999999999999999999999999999999999999e-308);
102+ // // test_literal2!(1.175494140627517859246175898662808184331245864732796240031385942718174675986064769972472277004271745681762695312500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-38);
103+ // // panic!();
104+ // }
105+
106+ // #[test]
107+ // fn foobar() {
108+ // use core::num::dec2flt::float::RawFloat;
109+ // panic!(
110+ // "{} {} {} {}",
111+ // <f32 as RawFloat>::LARGEST_POWER_OF_TEN,
112+ // <f32 as RawFloat>::SMALLEST_POWER_OF_TEN,
113+ // <f64 as RawFloat>::LARGEST_POWER_OF_TEN,
114+ // <f64 as RawFloat>::SMALLEST_POWER_OF_TEN,
115+ // )
116+ // }
117+
25118#[ test]
26119fn ordinary ( ) {
27120 test_literal ! ( 1.0 ) ;
0 commit comments