| 1 |
#![allow( |
| 2 |
clippy::approx_constant, |
| 3 |
clippy::unreadable_literal, |
| 4 |
clippy::unseparated_literal_suffix |
| 5 |
)] |
| 6 |
|
| 7 |
use std::{f32, f64}; |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn test_f64() { |
| 11 |
test_write(1.234e20f64, "123400000000000000000.0"); |
| 12 |
test_write(1.234e21f64, "1.234e21"); |
| 13 |
test_write(2.71828f64, "2.71828"); |
| 14 |
test_write(0.0f64, "0.0"); |
| 15 |
test_write(-0.0f64, "-0.0"); |
| 16 |
test_write(1.1e128f64, "1.1e128"); |
| 17 |
test_write(1.1e-64f64, "1.1e-64"); |
| 18 |
test_write(2.718281828459045f64, "2.718281828459045"); |
| 19 |
test_write(5e-324f64, "5e-324"); |
| 20 |
test_write(f64::MAX, "1.7976931348623157e308"); |
| 21 |
test_write(f64::MIN, "-1.7976931348623157e308"); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn test_f32() { |
| 26 |
test_write(1.234e20f32, "123400000000000000000.0"); |
| 27 |
test_write(1.234e21f32, "1.234e21"); |
| 28 |
test_write(2.71828f32, "2.71828"); |
| 29 |
test_write(0.0f32, "0.0"); |
| 30 |
test_write(-0.0f32, "-0.0"); |
| 31 |
test_write(1.1e32f32, "1.1e32"); |
| 32 |
test_write(1.1e-32f32, "1.1e-32"); |
| 33 |
test_write(2.7182817f32, "2.7182817"); |
| 34 |
test_write(1e-45f32, "1e-45"); |
| 35 |
test_write(f32::MAX, "3.4028235e38"); |
| 36 |
test_write(f32::MIN, "-3.4028235e38"); |
| 37 |
} |
| 38 |
|
| 39 |
fn test_write<F: dtoa::Float>(value: F, expected: &'static str) { |
| 40 |
let mut buffer = dtoa::Buffer::new(); |
| 41 |
let string = buffer.format(value); |
| 42 |
assert_eq!(string, expected); |
| 43 |
} |