diff --git a/src/format.rs b/src/format.rs index b8ce1f1..491ff25 100644 --- a/src/format.rs +++ b/src/format.rs @@ -309,13 +309,13 @@ impl Printf for f64 { } if use_scientific { - let normal = abs / 10.0_f64.powi(exponent); + let normal = abs / 10.0_f64.powf(exponent as f64); number.push_str(&format!("{}", normal.trunc())); if precision > 0 { number.push('.'); let mut tail = - ((normal - normal.trunc()) * 10.0_f64.powi(precision)).round() as u64; + ((normal - normal.trunc()) * 10.0_f64.powf(precision as f64)).round() as u64; let mut rev_tail_str = String::new(); for _ in 0..precision { rev_tail_str.push((b'0' + (tail % 10) as u8) as char); @@ -332,7 +332,7 @@ impl Printf for f64 { number.push_str(&format!("{}", abs.trunc())); if precision > 0 { number.push('.'); - let mut tail = ((abs - abs.trunc()) * 10.0_f64.powi(precision)).round() as u64; + let mut tail = ((abs - abs.trunc()) * 10.0_f64.powf(precision as f64)).round() as u64; let mut rev_tail_str = String::new(); for _ in 0..precision { rev_tail_str.push((b'0' + (tail % 10) as u8) as char); diff --git a/tests/compare_to_libc.rs b/tests/compare_to_libc.rs index ffec41f..c46c221 100644 --- a/tests/compare_to_libc.rs +++ b/tests/compare_to_libc.rs @@ -70,6 +70,7 @@ fn test_float() { check_fmt("%f", -46.38); check_fmt("%012.3f", 1.2); check_fmt("%012.3e", 1.7); + check_fmt("%e", 1e300); check_fmt("%012.3g%%!", 2.6); check_fmt("%012.5G", -2.69); check_fmt("%+7.4f", 42.785);