From efd5b0a73ccd693581ea545af8eff0e0908223db Mon Sep 17 00:00:00 2001 From: Dmitriy Shestavin Date: Wed, 28 Feb 2024 15:40:07 +0800 Subject: [PATCH] feat: Implemented parsing from string with scientific notation. --- CHANGELOG.md | 2 + src/string.rs | 185 ++++++++- tests/it/convert_str.rs | 829 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 1011 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f813f7f..948fded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- Implemented parsing from string with scientific notation. ## [0.9.2] - 2023-03-02 ### Added diff --git a/src/string.rs b/src/string.rs index 6e59efc..4ace0e6 100644 --- a/src/string.rs +++ b/src/string.rs @@ -17,7 +17,7 @@ macro_rules! impl_for { /// /// Use `from_str_exact` to parse without rounding. fn from_str(str: &str) -> Result { - Self::parse_str::(str) + Self::parse_str_with_scientific::(str) } } @@ -27,10 +27,12 @@ macro_rules! impl_for { /// /// Use the `FromStr` instance to parse with rounding. pub fn from_str_exact(str: &str) -> Result { - Self::parse_str::(str) + Self::parse_str_with_scientific::(str) } - fn parse_str(str: &str) -> Result { + fn parse_str_without_scientific( + str: &str, + ) -> Result { let str = str.trim(); let (integral_str, mut fractional_str) = if let Some(parts) = str.split_once('.') { @@ -97,6 +99,183 @@ macro_rules! impl_for { .map(Self::from_bits) .ok_or_else(|| ConvertError::new("too big number")) } + + fn parse_str_with_scientific( + str: &str, + ) -> Result { + let str = str.trim(); + + let (integral_and_fractional_str, exponent_str) = if let Some(exponent_char) = + str.chars().find(|c| *c == 'e' || *c == 'E') + { + if let Some(parts) = str.split_once(exponent_char) { + parts + } else { + // This error should never happen because `exponent_char` already found. + return Err(ConvertError::new("unable to split string by exponent char")); + } + } else { + return Self::parse_str_without_scientific::(str); + }; + + let mut exponent: i32 = exponent_str + .parse() + .map_err(|_| ConvertError::new("can't parse exponent"))?; + + let (mut integral_str, mut fractional_str) = + if let Some((integral_str, fractional_str)) = + integral_and_fractional_str.split_once('.') + { + (integral_str.to_owned(), fractional_str.to_owned()) + } else { + (integral_and_fractional_str.to_owned(), "".to_owned()) + }; + + if !integral_str.is_empty() { + let mut chars = integral_str.chars(); + let first_char = chars.next().expect("unreachable"); + if first_char == '+' || first_char == '-' { + integral_str = chars.as_str().to_owned(); + } + + integral_str = integral_str.trim_start_matches('0').to_owned(); + } + + let exponent_abs = exponent.abs() as usize; + // Main idea here is to keep one of parts empty or zero exponent. + if exponent >= 0 { + if exponent_abs >= fractional_str.len() { + integral_str.push_str(fractional_str.as_str()); + exponent = exponent + .checked_sub(fractional_str.len() as i32) // `as i32`` is safe because `exponent.abs() as usize >= fractional_str.len()` + .ok_or(ConvertError::new("too small exponent"))?; + fractional_str = "".to_owned(); + } else { + integral_str.push_str(&fractional_str[0..exponent_abs]); + fractional_str = fractional_str[exponent_abs..].to_owned(); + exponent = 0; + } + } else { + if exponent_abs >= integral_str.len() { + fractional_str.insert_str(0, integral_str.as_str()); + exponent = exponent + .checked_add(integral_str.len() as i32) // `as i32`` is safe because `exponent.abs() as usize >= integral_str.len()` + .ok_or(ConvertError::new("too large exponent"))?; + integral_str = "".to_owned(); + } else { + fractional_str.insert_str( + 0, + &integral_str[integral_str.len() - exponent_abs..integral_str.len()], + ); + integral_str = integral_str[..integral_str.len() - exponent_abs].to_owned(); + exponent = 0; + } + } + + if !integral_str.is_empty() { + integral_str = integral_str.trim_start_matches('0').to_owned(); + } + + // `exponent_abs` must be reevaluated + let exponent_abs = exponent.abs() as usize; + + debug_assert!( + exponent == 0 || fractional_str.is_empty() || integral_str.is_empty() + ); + let integral: $layout = if integral_str.is_empty() { + debug_assert!((exponent == 0 || fractional_str.is_empty()) && exponent <= 0); + 0 + } else { + // If at this point `integral_str` part can't be represent as `$layout` then + // it obviously can't be represented as `$layout` after multiplication by `exponent` + // because `exponent` here is not less than zero. + debug_assert!((exponent == 0 || fractional_str.is_empty()) && exponent >= 0); + integral_str + .parse() + .map_err(|_| ConvertError::new("can't parse integral part"))? + }; + + if EXACT { + // if `fractional_str` contains trailing zeroes this error will be misleading + fractional_str = fractional_str.trim_end_matches('0').to_owned(); + if fractional_str.len() > (Self::PRECISION.abs() + exponent) as usize { + return Err(ConvertError::new("requested precision is too high")); + } + } + + let signum = if str.as_bytes()[0] == b'-' { -1 } else { 1 }; + let last_idx = Self::PRECISION + exponent; + let last_idx_abs = last_idx.abs() as usize; + let round = if !EXACT && last_idx >= 0 && last_idx_abs < fractional_str.len() { + let extra = fractional_str.as_bytes()[last_idx_abs]; + fractional_str = fractional_str[..last_idx_abs].to_owned(); + Some(signum).filter(|_| extra >= b'5') + } else { + None + }; + + let ten: $layout = 10; + let fractional_multiplier = ten.pow( + (fractional_str.len() + exponent_abs) + .try_into() + .map_err(|_| ConvertError::new("too big fractional_str"))?, + ); + + if EXACT && fractional_multiplier > Self::COEF { + return Err(ConvertError::new("requested precision is too high")); + } + + debug_assert!(fractional_multiplier <= Self::COEF); + + let fractional: Option<$layout> = if !fractional_str.is_empty() { + Some( + fractional_str + .parse() + .map_err(|_| ConvertError::new("can't parse fractional part"))?, + ) + } else { + None + }; + + let integral_multiplier = ten.pow( + (Self::PRECISION + exponent) + .try_into() + .map_err(|_| ConvertError::new("too big exponent"))?, + ); + let mut final_integral = integral + .checked_mul(integral_multiplier) + .ok_or(ConvertError::new("too big integral"))?; + + if signum < 0 { + final_integral = -final_integral; + } + + let mut final_fractional = fractional + .map(|fractional| signum * Self::COEF / fractional_multiplier * fractional); + + if let Some(round) = round { + debug_assert!(!EXACT); + if let Some(final_fractional_inner) = final_fractional.as_mut() { + final_fractional = Some( + final_fractional_inner + .checked_add(round) + .ok_or(ConvertError::new("requested precision is too high"))?, + ); + } else { + final_integral = final_integral + .checked_add(round) + .ok_or(ConvertError::new("too big integral"))?; + } + } + + if let Some(&mut final_fractional) = final_fractional.as_mut() { + final_integral = final_integral + .checked_add(final_fractional) + .ok_or(ConvertError::new("too big number"))?; + } + + Ok(Self::from_bits(final_integral)) + } } impl Stringify for FixedPoint<$layout, P> { diff --git a/tests/it/convert_str.rs b/tests/it/convert_str.rs index df0e47e..ccc233e 100644 --- a/tests/it/convert_str.rs +++ b/tests/it/convert_str.rs @@ -38,6 +38,143 @@ fn from_good_str_exact() -> Result<()> { ("123456789.123456789", 123456789123456789); ("9223372036.854775807", 9223372036854775807); ("-9223372036.854775808", -9223372036854775808); + + ("1e0", 1000000000); + ("1E0", 1000000000); + ("+1E+0", 1000000000); + ("-1E+0", -1000000000); + ("1E-0", 1000000000); + ("-1E-0", -1000000000); + + ("110E-2", 1100000000); + ("11E-1", 1100000000); + ("1.1E0", 1100000000); + ("0.11E1", 1100000000); + ("0.011E+2", 1100000000); + + ("-110E-2", -1100000000); + ("-11E-1", -1100000000); + ("-1.1E0", -1100000000); + ("-0.11E1", -1100000000); + ("-0.011E+2", -1100000000); + + ("1020e-3", 1020000000); + ("102e-2", 1020000000); + ("10.2e-1", 1020000000); + ("1.02e0", 1020000000); + ("0.102e1", 1020000000); + ("0.0102e2", 1020000000); + + ("-1020e-3", -1020000000); + ("-102e-2", -1020000000); + ("-10.2e-1", -1020000000); + ("-1.02e0", -1020000000); + ("-0.102e1", -1020000000); + ("-0.0102e2", -1020000000); + + ("12340E-5", 123400000); + ("1234E-4", 123400000); + ("123.4E-3", 123400000); + ("12.34E-2", 123400000); + ("1.234E-1", 123400000); + ("0.1234E0", 123400000); + ("0.01234E1", 123400000); + + ("-12340E-5", -123400000); + ("-1234E-4", -123400000); + ("-123.4E-3", -123400000); + ("-12.34E-2", -123400000); + ("-1.234E-1", -123400000); + ("-0.1234E0", -123400000); + ("-0.01234E1", -123400000); + + ("1234567891234567890e-10", 123456789123456789); + ("123456789123456789e-9", 123456789123456789); + ("12345678912345678.9e-8", 123456789123456789); + ("1234567891234567.89e-7", 123456789123456789); + ("123456789123456.789e-6", 123456789123456789); + ("12345678912345.6789e-5", 123456789123456789); + ("1234567891234.56789e-4", 123456789123456789); + ("123456789123.456789e-3", 123456789123456789); + ("12345678912.3456789e-2", 123456789123456789); + ("1234567891.23456789e-1", 123456789123456789); + ("123456789.123456789e0", 123456789123456789); + ("12345678.9123456789e1", 123456789123456789); + ("1234567.89123456789e2", 123456789123456789); + ("123456.789123456789e3", 123456789123456789); + ("12345.6789123456789e4", 123456789123456789); + ("1234.56789123456789e5", 123456789123456789); + ("123.456789123456789e6", 123456789123456789); + ("12.3456789123456789e7", 123456789123456789); + ("1.23456789123456789e8", 123456789123456789); + ("0.123456789123456789e9", 123456789123456789); + + ("92233720368547758070e-10", 9223372036854775807); + ("9223372036854775807e-9", 9223372036854775807); + ("922337203685477580.7e-8", 9223372036854775807); + ("92233720368547758.07e-7", 9223372036854775807); + ("9223372036854775.807e-6", 9223372036854775807); + ("922337203685477.5807e-5", 9223372036854775807); + ("92233720368547.75807e-4", 9223372036854775807); + ("9223372036854.775807e-3", 9223372036854775807); + ("922337203685.4775807e-2", 9223372036854775807); + ("92233720368.54775807e-1", 9223372036854775807); + ("9223372036.854775807e0", 9223372036854775807); + ("922337203.6854775807e1", 9223372036854775807); + ("92233720.36854775807e2", 9223372036854775807); + ("9223372.036854775807e3", 9223372036854775807); + ("922337.2036854775807e4", 9223372036854775807); + ("92233.72036854775807e5", 9223372036854775807); + ("9223.372036854775807e6", 9223372036854775807); + ("922.3372036854775807e7", 9223372036854775807); + ("92.23372036854775807e8", 9223372036854775807); + ("9.223372036854775807e9", 9223372036854775807); + ("0.9223372036854775807e10", 9223372036854775807); + ("0.09223372036854775807e11", 9223372036854775807); + + ("-922337203685477580800.0e-11", -9223372036854775808); + ("-92233720368547758080.0e-10", -9223372036854775808); + ("-9223372036854775808.0e-9", -9223372036854775808); + ("-922337203685477580.8e-8", -9223372036854775808); + ("-92233720368547758.08e-7", -9223372036854775808); + ("-9223372036854775.808e-6", -9223372036854775808); + ("-922337203685477.5808e-5", -9223372036854775808); + ("-92233720368547.75808e-4", -9223372036854775808); + ("-9223372036854.775808e-3", -9223372036854775808); + ("-922337203685.4775808e-2", -9223372036854775808); + ("-92233720368.54775808e-1", -9223372036854775808); + ("-9223372036.854775808e0", -9223372036854775808); + ("-922337203.6854775808e1", -9223372036854775808); + ("-92233720.36854775808e2", -9223372036854775808); + ("-9223372.036854775808e3", -9223372036854775808); + ("-922337.2036854775808e4", -9223372036854775808); + ("-92233.72036854775808e5", -9223372036854775808); + ("-9223.372036854775808e6", -9223372036854775808); + ("-922.3372036854775808e7", -9223372036854775808); + ("-92.23372036854775808e8", -9223372036854775808); + ("-9.223372036854775808e9", -9223372036854775808); + ("-00.9223372036854775808e10", -9223372036854775808); + ("-000.09223372036854775808e11", -9223372036854775808); + + ("10e-1", 1000000000); + ("10000000000e-10", 1000000000); + ("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", 1000000000); + ("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", 1000000000); + + ("0.1e1", 1000000000); + ("0.0000000001e10", 1000000000); + ("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", 1000000000); + ("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", 1000000000); + + ("-10e-1", -1000000000); + ("-10000000000e-10", -1000000000); + ("-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", -1000000000); + ("-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", -1000000000); + + ("-0.1e1", -1000000000); + ("-0.0000000001e10", -1000000000); + ("-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", -1000000000); + ("-000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", -1000000000); }, fp128 { ("1", 1000000000000000000); @@ -54,6 +191,237 @@ fn from_good_str_exact() -> Result<()> { 170141183460469231731687303715884105727); ("-170141183460469231731.687303715884105728", -170141183460469231731687303715884105728); + + ("1e0", 1000000000000000000); + ("1E0", 1000000000000000000); + ("+1E+0", 1000000000000000000); + ("-1E+0", -1000000000000000000); + ("1E-0", 1000000000000000000); + ("-1E-0", -1000000000000000000); + + ("110E-2", 1100000000000000000); + ("11E-1", 1100000000000000000); + ("1.1E0", 1100000000000000000); + ("0.11E1", 1100000000000000000); + ("0.011E+2", 1100000000000000000); + + ("-110E-2", -1100000000000000000); + ("-11E-1", -1100000000000000000); + ("-1.1E0", -1100000000000000000); + ("-0.11E1", -1100000000000000000); + ("-0.011E+2", -1100000000000000000); + + ("1020e-3", 1020000000000000000); + ("102e-2", 1020000000000000000); + ("10.2e-1", 1020000000000000000); + ("1.02e0", 1020000000000000000); + ("0.102e1", 1020000000000000000); + ("0.0102e2", 1020000000000000000); + + ("-1020e-3", -1020000000000000000); + ("-102e-2", -1020000000000000000); + ("-10.2e-1", -1020000000000000000); + ("-1.02e0", -1020000000000000000); + ("-0.102e1", -1020000000000000000); + ("-0.0102e2", -1020000000000000000); + + ("12340E-5", 123400000000000000); + ("1234E-4", 123400000000000000); + ("123.4E-3", 123400000000000000); + ("12.34E-2", 123400000000000000); + ("1.234E-1", 123400000000000000); + ("0.1234E0", 123400000000000000); + ("0.01234E1", 123400000000000000); + + ("-12340E-5", -123400000000000000); + ("-1234E-4", -123400000000000000); + ("-123.4E-3", -123400000000000000); + ("-12.34E-2", -123400000000000000); + ("-1.234E-1", -123400000000000000); + ("-0.1234E0", -123400000000000000); + ("-0.01234E1", -123400000000000000); + + ("1234567891234567890e-10", 123456789123456789000000000); + ("123456789123456789e-9", 123456789123456789000000000); + ("12345678912345678.9e-8", 123456789123456789000000000); + ("1234567891234567.89e-7", 123456789123456789000000000); + ("123456789123456.789e-6", 123456789123456789000000000); + ("12345678912345.6789e-5", 123456789123456789000000000); + ("1234567891234.56789e-4", 123456789123456789000000000); + ("123456789123.456789e-3", 123456789123456789000000000); + ("12345678912.3456789e-2", 123456789123456789000000000); + ("1234567891.23456789e-1", 123456789123456789000000000); + ("123456789.123456789e0", 123456789123456789000000000); + ("12345678.9123456789e1", 123456789123456789000000000); + ("1234567.89123456789e2", 123456789123456789000000000); + ("123456.789123456789e3", 123456789123456789000000000); + ("12345.6789123456789e4", 123456789123456789000000000); + ("1234.56789123456789e5", 123456789123456789000000000); + ("123.456789123456789e6", 123456789123456789000000000); + ("12.3456789123456789e7", 123456789123456789000000000); + ("1.23456789123456789e8", 123456789123456789000000000); + ("0.123456789123456789e9", 123456789123456789000000000); + + ("92233720368547758070e-10", 9223372036854775807000000000); + ("9223372036854775807e-9", 9223372036854775807000000000); + ("922337203685477580.7e-8", 9223372036854775807000000000); + ("92233720368547758.07e-7", 9223372036854775807000000000); + ("9223372036854775.807e-6", 9223372036854775807000000000); + ("922337203685477.5807e-5", 9223372036854775807000000000); + ("92233720368547.75807e-4", 9223372036854775807000000000); + ("9223372036854.775807e-3", 9223372036854775807000000000); + ("922337203685.4775807e-2", 9223372036854775807000000000); + ("92233720368.54775807e-1", 9223372036854775807000000000); + ("9223372036.854775807e0", 9223372036854775807000000000); + ("922337203.6854775807e1", 9223372036854775807000000000); + ("92233720.36854775807e2", 9223372036854775807000000000); + ("9223372.036854775807e3", 9223372036854775807000000000); + ("922337.2036854775807e4", 9223372036854775807000000000); + ("92233.72036854775807e5", 9223372036854775807000000000); + ("9223.372036854775807e6", 9223372036854775807000000000); + ("922.3372036854775807e7", 9223372036854775807000000000); + ("92.23372036854775807e8", 9223372036854775807000000000); + ("9.223372036854775807e9", 9223372036854775807000000000); + ("0.9223372036854775807e10", 9223372036854775807000000000); + ("0.09223372036854775807e11", 9223372036854775807000000000); + + ("-922337203685477580800.0e-11", -9223372036854775808000000000); + ("-92233720368547758080.0e-10", -9223372036854775808000000000); + ("-9223372036854775808.0e-9", -9223372036854775808000000000); + ("-922337203685477580.8e-8", -9223372036854775808000000000); + ("-92233720368547758.08e-7", -9223372036854775808000000000); + ("-9223372036854775.808e-6", -9223372036854775808000000000); + ("-922337203685477.5808e-5", -9223372036854775808000000000); + ("-92233720368547.75808e-4", -9223372036854775808000000000); + ("-9223372036854.775808e-3", -9223372036854775808000000000); + ("-922337203685.4775808e-2", -9223372036854775808000000000); + ("-92233720368.54775808e-1", -9223372036854775808000000000); + ("-9223372036.854775808e0", -9223372036854775808000000000); + ("-922337203.6854775808e1", -9223372036854775808000000000); + ("-92233720.36854775808e2", -9223372036854775808000000000); + ("-9223372.036854775808e3", -9223372036854775808000000000); + ("-922337.2036854775808e4", -9223372036854775808000000000); + ("-92233.72036854775808e5", -9223372036854775808000000000); + ("-9223.372036854775808e6", -9223372036854775808000000000); + ("-922.3372036854775808e7", -9223372036854775808000000000); + ("-92.23372036854775808e8", -9223372036854775808000000000); + ("-9.223372036854775808e9", -9223372036854775808000000000); + ("-00.9223372036854775808e10", -9223372036854775808000000000); + ("-000.09223372036854775808e11", -9223372036854775808000000000); + + ("170141183460469231731687303715884105727000e-21", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410572700e-20", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841057270e-19", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884105727e-18", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410572.7e-17", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841057.27e-16", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884105.727e-15", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410.5727e-14", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841.05727e-13", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884.105727e-12", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588.4105727e-11", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158.84105727e-10", 170141183460469231731687303715884105727); + ("170141183460469231731687303715.884105727e-9", 170141183460469231731687303715884105727); + ("17014118346046923173168730371.5884105727e-8", 170141183460469231731687303715884105727); + ("1701411834604692317316873037.15884105727e-7", 170141183460469231731687303715884105727); + ("170141183460469231731687303.715884105727e-6", 170141183460469231731687303715884105727); + ("17014118346046923173168730.3715884105727e-5", 170141183460469231731687303715884105727); + ("1701411834604692317316873.03715884105727e-4", 170141183460469231731687303715884105727); + ("170141183460469231731687.303715884105727e-3", 170141183460469231731687303715884105727); + ("17014118346046923173168.7303715884105727e-2", 170141183460469231731687303715884105727); + ("1701411834604692317316.87303715884105727e-1", 170141183460469231731687303715884105727); + ("170141183460469231731.687303715884105727e0", 170141183460469231731687303715884105727); + ("17014118346046923173.1687303715884105727e1", 170141183460469231731687303715884105727); + ("1701411834604692317.31687303715884105727e2", 170141183460469231731687303715884105727); + ("170141183460469231.731687303715884105727e3", 170141183460469231731687303715884105727); + ("17014118346046923.1731687303715884105727e4", 170141183460469231731687303715884105727); + ("1701411834604692.31731687303715884105727e5", 170141183460469231731687303715884105727); + ("170141183460469.231731687303715884105727e6", 170141183460469231731687303715884105727); + ("17014118346046.9231731687303715884105727e7", 170141183460469231731687303715884105727); + ("1701411834604.69231731687303715884105727e8", 170141183460469231731687303715884105727); + ("170141183460.469231731687303715884105727e9", 170141183460469231731687303715884105727); + ("17014118346.0469231731687303715884105727e10", 170141183460469231731687303715884105727); + ("1701411834.60469231731687303715884105727e11", 170141183460469231731687303715884105727); + ("170141183.460469231731687303715884105727e12", 170141183460469231731687303715884105727); + ("17014118.3460469231731687303715884105727e13", 170141183460469231731687303715884105727); + ("1701411.83460469231731687303715884105727e14", 170141183460469231731687303715884105727); + ("170141.183460469231731687303715884105727e15", 170141183460469231731687303715884105727); + ("17014.1183460469231731687303715884105727e16", 170141183460469231731687303715884105727); + ("1701.41183460469231731687303715884105727e17", 170141183460469231731687303715884105727); + ("170.141183460469231731687303715884105727e18", 170141183460469231731687303715884105727); + ("17.0141183460469231731687303715884105727e19", 170141183460469231731687303715884105727); + ("1.70141183460469231731687303715884105727e20", 170141183460469231731687303715884105727); + ("0.170141183460469231731687303715884105727e21", 170141183460469231731687303715884105727); + ("0.0170141183460469231731687303715884105727e22", 170141183460469231731687303715884105727); + ("0.00170141183460469231731687303715884105727e23", 170141183460469231731687303715884105727); + ("0.000170141183460469231731687303715884105727e24", 170141183460469231731687303715884105727); + + ("-170141183460469231731687303715884105728000e-21", -170141183460469231731687303715884105728); + ("-17014118346046923173168730371588410572800e-20", -170141183460469231731687303715884105728); + ("-1701411834604692317316873037158841057280e-19", -170141183460469231731687303715884105728); + ("-170141183460469231731687303715884105728e-18", -170141183460469231731687303715884105728); + ("-17014118346046923173168730371588410572.8e-17", -170141183460469231731687303715884105728); + ("-1701411834604692317316873037158841057.28e-16", -170141183460469231731687303715884105728); + ("-170141183460469231731687303715884105.728e-15", -170141183460469231731687303715884105728); + ("-17014118346046923173168730371588410.5728e-14", -170141183460469231731687303715884105728); + ("-1701411834604692317316873037158841.05728e-13", -170141183460469231731687303715884105728); + ("-170141183460469231731687303715884.105728e-12", -170141183460469231731687303715884105728); + ("-17014118346046923173168730371588.4105728e-11", -170141183460469231731687303715884105728); + ("-1701411834604692317316873037158.84105728e-10", -170141183460469231731687303715884105728); + ("-170141183460469231731687303715.884105728e-9", -170141183460469231731687303715884105728); + ("-17014118346046923173168730371.5884105728e-8", -170141183460469231731687303715884105728); + ("-1701411834604692317316873037.15884105728e-7", -170141183460469231731687303715884105728); + ("-170141183460469231731687303.715884105728e-6", -170141183460469231731687303715884105728); + ("-17014118346046923173168730.3715884105728e-5", -170141183460469231731687303715884105728); + ("-1701411834604692317316873.03715884105728e-4", -170141183460469231731687303715884105728); + ("-170141183460469231731687.303715884105728e-3", -170141183460469231731687303715884105728); + ("-17014118346046923173168.7303715884105728e-2", -170141183460469231731687303715884105728); + ("-1701411834604692317316.87303715884105728e-1", -170141183460469231731687303715884105728); + ("-170141183460469231731.687303715884105728e0", -170141183460469231731687303715884105728); + ("-17014118346046923173.1687303715884105728e1", -170141183460469231731687303715884105728); + ("-1701411834604692317.31687303715884105728e2", -170141183460469231731687303715884105728); + ("-170141183460469231.731687303715884105728e3", -170141183460469231731687303715884105728); + ("-17014118346046923.1731687303715884105728e4", -170141183460469231731687303715884105728); + ("-1701411834604692.31731687303715884105728e5", -170141183460469231731687303715884105728); + ("-170141183460469.231731687303715884105728e6", -170141183460469231731687303715884105728); + ("-17014118346046.9231731687303715884105728e7", -170141183460469231731687303715884105728); + ("-1701411834604.69231731687303715884105728e8", -170141183460469231731687303715884105728); + ("-170141183460.469231731687303715884105728e9", -170141183460469231731687303715884105728); + ("-17014118346.0469231731687303715884105728e10", -170141183460469231731687303715884105728); + ("-1701411834.60469231731687303715884105728e11", -170141183460469231731687303715884105728); + ("-170141183.460469231731687303715884105728e12", -170141183460469231731687303715884105728); + ("-17014118.3460469231731687303715884105728e13", -170141183460469231731687303715884105728); + ("-1701411.83460469231731687303715884105728e14", -170141183460469231731687303715884105728); + ("-170141.183460469231731687303715884105728e15", -170141183460469231731687303715884105728); + ("-17014.1183460469231731687303715884105728e16", -170141183460469231731687303715884105728); + ("-1701.41183460469231731687303715884105728e17", -170141183460469231731687303715884105728); + ("-170.141183460469231731687303715884105728e18", -170141183460469231731687303715884105728); + ("-17.0141183460469231731687303715884105728e19", -170141183460469231731687303715884105728); + ("-1.70141183460469231731687303715884105728e20", -170141183460469231731687303715884105728); + ("-0.170141183460469231731687303715884105728e21", -170141183460469231731687303715884105728); + ("-0.0170141183460469231731687303715884105728e22", -170141183460469231731687303715884105728); + ("-0.00170141183460469231731687303715884105728e23", -170141183460469231731687303715884105728); + ("-0.000170141183460469231731687303715884105728e24", -170141183460469231731687303715884105728); + + ("10e-1", 1000000000000000000); + ("10000000000e-10", 1000000000000000000); + ("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", 1000000000000000000); + ("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", 1000000000000000000); + + ("0.1e1", 1000000000000000000); + ("0.0000000001e10", 1000000000000000000); + ("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", 1000000000000000000); + ("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", 1000000000000000000); + + ("-10e-1", -1000000000000000000); + ("-10000000000e-10", -1000000000000000000); + ("-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", -1000000000000000000); + ("-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-100", -1000000000000000000); + + ("-0.1e1", -1000000000000000000); + ("-0.0000000001e10", -1000000000000000000); + ("-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", -1000000000000000000); + ("-000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E100", -1000000000000000000); }, }; Ok(()) @@ -94,6 +462,251 @@ fn from_good_str_inexact() -> Result<()> { ("13.1000000009", 13100000001); ("13.9999999999999999999999999999999999999999999999999999999999999", 14000000000); ("9223372036.8547758071", 9223372036854775807); + + ("13000000000000000000100e-21", 13000000000); + ("1300000000000000000010e-20", 13000000000); + ("130000000000000000001e-19", 13000000000); + ("13000000000000000000.1e-18", 13000000000); + ("1300000000000000000.01e-17", 13000000000); + ("130000000000000000.001e-16", 13000000000); + ("13000000000000000.0001e-15", 13000000000); + ("1300000000000000.00001e-14", 13000000000); + ("130000000000000.000001e-13", 13000000000); + ("13000000000000.0000001e-12", 13000000000); + ("1300000000000.00000001e-11", 13000000000); + ("130000000000.000000001e-10", 13000000000); + ("13000000000.0000000001e-9", 13000000000); + ("1300000000.00000000001e-8", 13000000000); + ("130000000.000000000001e-7", 13000000000); + ("13000000.0000000000001e-6", 13000000000); + ("1300000.00000000000001e-5", 13000000000); + ("130000.000000000000001e-4", 13000000000); + ("13000.0000000000000001e-3", 13000000000); + ("1300.00000000000000001e-2", 13000000000); + ("130.000000000000000001e-1", 13000000000); + ("13.0000000000000000001e0", 13000000000); + ("1.30000000000000000001e1", 13000000000); + ("0.130000000000000000001e2", 13000000000); + ("0.0130000000000000000001e3", 13000000000); + ("0.00130000000000000000001e4", 13000000000); + ("0.000130000000000000000001e5", 13000000000); + + ("13000000000000000000500e-21", 13000000000); + ("1300000000000000000050e-20", 13000000000); + ("130000000000000000005e-19", 13000000000); + ("13000000000000000000.5e-18", 13000000000); + ("1300000000000000000.05e-17", 13000000000); + ("130000000000000000.005e-16", 13000000000); + ("13000000000000000.0005e-15", 13000000000); + ("1300000000000000.00005e-14", 13000000000); + ("130000000000000.000005e-13", 13000000000); + ("13000000000000.0000005e-12", 13000000000); + ("1300000000000.00000005e-11", 13000000000); + ("130000000000.000000005e-10", 13000000000); + ("13000000000.0000000005e-9", 13000000000); + ("1300000000.00000000005e-8", 13000000000); + ("130000000.000000000005e-7", 13000000000); + ("13000000.0000000000005e-6", 13000000000); + ("1300000.00000000000005e-5", 13000000000); + ("130000.000000000000005e-4", 13000000000); + ("13000.0000000000000005e-3", 13000000000); + ("1300.00000000000000005e-2", 13000000000); + ("130.000000000000000005e-1", 13000000000); + ("13.0000000000000000005e0", 13000000000); + ("1.30000000000000000005e1", 13000000000); + ("0.130000000000000000005e2", 13000000000); + ("0.0130000000000000000005e3", 13000000000); + ("0.00130000000000000000005e4", 13000000000); + ("0.000130000000000000000005e5", 13000000000); + + ("1300000000010e-11", 13000000000); + ("130000000001e-10", 13000000000); + ("13000000000.1e-9", 13000000000); + ("1300000000.01e-8", 13000000000); + ("130000000.001e-7", 13000000000); + ("13000000.0001e-6", 13000000000); + ("1300000.00001e-5", 13000000000); + ("130000.000001e-4", 13000000000); + ("13000.0000001e-3", 13000000000); + ("1300.00000001e-2", 13000000000); + ("130.000000001e-1", 13000000000); + ("13.0000000001e0", 13000000000); + ("1.30000000001e1", 13000000000); + ("0.130000000001e2", 13000000000); + ("0.0130000000001e3", 13000000000); + + ("1300000000050e-11", 13000000001); + ("130000000005e-10", 13000000001); + ("13000000000.5e-9", 13000000001); + ("1300000000.05e-8", 13000000001); + ("130000000.005e-7", 13000000001); + ("13000000.0005e-6", 13000000001); + ("1300000.00005e-5", 13000000001); + ("130000.000005e-4", 13000000001); + ("13000.0000005e-3", 13000000001); + ("1300.00000005e-2", 13000000001); + ("130.000000005e-1", 13000000001); + ("13.0000000005e0", 13000000001); + ("1.30000000005e1", 13000000001); + ("0.130000000005e2", 13000000001); + ("0.0130000000005e3", 13000000001); + + ("1300000000090e-11", 13000000001); + ("130000000009e-10", 13000000001); + ("13000000000.9e-9", 13000000001); + ("1300000000.09e-8", 13000000001); + ("130000000.009e-7", 13000000001); + ("13000000.0009e-6", 13000000001); + ("1300000.00009e-5", 13000000001); + ("130000.000009e-4", 13000000001); + ("13000.0000009e-3", 13000000001); + ("1300.00000009e-2", 13000000001); + ("130.000000009e-1", 13000000001); + ("13.0000000009e0", 13000000001); + ("1.30000000009e1", 13000000001); + ("0.130000000009e2", 13000000001); + ("0.0130000000009e3", 13000000001); + + ("1310000000010e-11", 13100000000); + ("131000000001e-10", 13100000000); + ("13100000000.1e-9", 13100000000); + ("1310000000.01e-8", 13100000000); + ("131000000.001e-7", 13100000000); + ("13100000.0001e-6", 13100000000); + ("1310000.00001e-5", 13100000000); + ("131000.000001e-4", 13100000000); + ("13100.0000001e-3", 13100000000); + ("1310.00000001e-2", 13100000000); + ("131.000000001e-1", 13100000000); + ("13.1000000001e0", 13100000000); + ("1.31000000001e1", 13100000000); + ("0.131000000001e2", 13100000000); + ("0.0131000000001e3", 13100000000); + + ("1310000000050e-11", 13100000001); + ("131000000005e-10", 13100000001); + ("13100000000.5e-9", 13100000001); + ("1310000000.05e-8", 13100000001); + ("131000000.005e-7", 13100000001); + ("13100000.0005e-6", 13100000001); + ("1310000.00005e-5", 13100000001); + ("131000.000005e-4", 13100000001); + ("13100.0000005e-3", 13100000001); + ("1310.00000005e-2", 13100000001); + ("131.000000005e-1", 13100000001); + ("13.1000000005e0", 13100000001); + ("1.31000000005e1", 13100000001); + ("0.131000000005e2", 13100000001); + ("0.0131000000005e3", 13100000001); + + ("1310000000090e-11", 13100000001); + ("131000000009e-10", 13100000001); + ("13100000000.9e-9", 13100000001); + ("1310000000.09e-8", 13100000001); + ("131000000.009e-7", 13100000001); + ("13100000.0009e-6", 13100000001); + ("1310000.00009e-5", 13100000001); + ("131000.000009e-4", 13100000001); + ("13100.0000009e-3", 13100000001); + ("1310.00000009e-2", 13100000001); + ("131.000000009e-1", 13100000001); + ("13.1000000009e0", 13100000001); + ("1.31000000009e1", 13100000001); + ("0.131000000009e2", 13100000001); + ("0.0131000000009e3", 13100000001); + + ("13999999999999999999999999999999999999999999999999999999999999900e-63", 14000000000); + ("1399999999999999999999999999999999999999999999999999999999999990e-62", 14000000000); + ("139999999999999999999999999999999999999999999999999999999999999e-61", 14000000000); + ("13999999999999999999999999999999999999999999999999999999999999.9e-60", 14000000000); + ("1399999999999999999999999999999999999999999999999999999999999.99e-59", 14000000000); + ("139999999999999999999999999999999999999999999999999999999999.999e-58", 14000000000); + ("13999999999999999999999999999999999999999999999999999999999.9999e-57", 14000000000); + ("1399999999999999999999999999999999999999999999999999999999.99999e-56", 14000000000); + ("139999999999999999999999999999999999999999999999999999999.999999e-55", 14000000000); + ("13999999999999999999999999999999999999999999999999999999.9999999e-54", 14000000000); + ("1399999999999999999999999999999999999999999999999999999.99999999e-53", 14000000000); + ("139999999999999999999999999999999999999999999999999999.999999999e-52", 14000000000); + ("13999999999999999999999999999999999999999999999999999.9999999999e-51", 14000000000); + ("1399999999999999999999999999999999999999999999999999.99999999999e-50", 14000000000); + ("139999999999999999999999999999999999999999999999999.999999999999e-49", 14000000000); + ("13999999999999999999999999999999999999999999999999.9999999999999e-48", 14000000000); + ("1399999999999999999999999999999999999999999999999.99999999999999e-47", 14000000000); + ("139999999999999999999999999999999999999999999999.999999999999999e-46", 14000000000); + ("13999999999999999999999999999999999999999999999.9999999999999999e-45", 14000000000); + ("1399999999999999999999999999999999999999999999.99999999999999999e-44", 14000000000); + ("139999999999999999999999999999999999999999999.999999999999999999e-43", 14000000000); + ("13999999999999999999999999999999999999999999.9999999999999999999e-42", 14000000000); + ("1399999999999999999999999999999999999999999.99999999999999999999e-41", 14000000000); + ("139999999999999999999999999999999999999999.999999999999999999999e-40", 14000000000); + ("13999999999999999999999999999999999999999.9999999999999999999999e-39", 14000000000); + ("1399999999999999999999999999999999999999.99999999999999999999999e-38", 14000000000); + ("139999999999999999999999999999999999999.999999999999999999999999e-37", 14000000000); + ("13999999999999999999999999999999999999.9999999999999999999999999e-36", 14000000000); + ("1399999999999999999999999999999999999.99999999999999999999999999e-35", 14000000000); + ("139999999999999999999999999999999999.999999999999999999999999999e-34", 14000000000); + ("13999999999999999999999999999999999.9999999999999999999999999999e-33", 14000000000); + ("1399999999999999999999999999999999.99999999999999999999999999999e-32", 14000000000); + ("139999999999999999999999999999999.999999999999999999999999999999e-31", 14000000000); + ("13999999999999999999999999999999.9999999999999999999999999999999e-30", 14000000000); + ("1399999999999999999999999999999.99999999999999999999999999999999e-29", 14000000000); + ("139999999999999999999999999999.999999999999999999999999999999999e-28", 14000000000); + ("13999999999999999999999999999.9999999999999999999999999999999999e-27", 14000000000); + ("1399999999999999999999999999.99999999999999999999999999999999999e-26", 14000000000); + ("139999999999999999999999999.999999999999999999999999999999999999e-25", 14000000000); + ("13999999999999999999999999.9999999999999999999999999999999999999e-24", 14000000000); + ("1399999999999999999999999.99999999999999999999999999999999999999e-23", 14000000000); + ("139999999999999999999999.999999999999999999999999999999999999999e-22", 14000000000); + ("13999999999999999999999.9999999999999999999999999999999999999999e-21", 14000000000); + ("1399999999999999999999.99999999999999999999999999999999999999999e-20", 14000000000); + ("139999999999999999999.999999999999999999999999999999999999999999e-19", 14000000000); + ("13999999999999999999.9999999999999999999999999999999999999999999e-18", 14000000000); + ("1399999999999999999.99999999999999999999999999999999999999999999e-17", 14000000000); + ("139999999999999999.999999999999999999999999999999999999999999999e-16", 14000000000); + ("13999999999999999.9999999999999999999999999999999999999999999999e-15", 14000000000); + ("1399999999999999.99999999999999999999999999999999999999999999999e-14", 14000000000); + ("139999999999999.999999999999999999999999999999999999999999999999e-13", 14000000000); + ("13999999999999.9999999999999999999999999999999999999999999999999e-12", 14000000000); + ("1399999999999.99999999999999999999999999999999999999999999999999e-11", 14000000000); + ("139999999999.999999999999999999999999999999999999999999999999999e-10", 14000000000); + ("13999999999.9999999999999999999999999999999999999999999999999999e-9", 14000000000); + ("1399999999.99999999999999999999999999999999999999999999999999999e-8", 14000000000); + ("139999999.999999999999999999999999999999999999999999999999999999e-7", 14000000000); + ("13999999.9999999999999999999999999999999999999999999999999999999e-6", 14000000000); + ("1399999.99999999999999999999999999999999999999999999999999999999e-5", 14000000000); + ("139999.999999999999999999999999999999999999999999999999999999999e-4", 14000000000); + ("13999.9999999999999999999999999999999999999999999999999999999999e-3", 14000000000); + ("1399.99999999999999999999999999999999999999999999999999999999999e-2", 14000000000); + ("139.999999999999999999999999999999999999999999999999999999999999e-1", 14000000000); + ("13.9999999999999999999999999999999999999999999999999999999999999e0", 14000000000); + ("1.39999999999999999999999999999999999999999999999999999999999999e1", 14000000000); + ("0.139999999999999999999999999999999999999999999999999999999999999e2", 14000000000); + ("0.0139999999999999999999999999999999999999999999999999999999999999e3", 14000000000); + + ("9223372036854775807100e-12", 9223372036854775807); + ("922337203685477580710e-11", 9223372036854775807); + ("92233720368547758071e-10", 9223372036854775807); + ("9223372036854775807.1e-9", 9223372036854775807); + ("922337203685477580.71e-8", 9223372036854775807); + ("92233720368547758.071e-7", 9223372036854775807); + ("9223372036854775.8071e-6", 9223372036854775807); + ("922337203685477.58071e-5", 9223372036854775807); + ("92233720368547.758071e-4", 9223372036854775807); + ("9223372036854.7758071e-3", 9223372036854775807); + ("922337203685.47758071e-2", 9223372036854775807); + ("92233720368.547758071e-1", 9223372036854775807); + ("9223372036.8547758071e0", 9223372036854775807); + ("922337203.68547758071e1", 9223372036854775807); + ("92233720.368547758071e2", 9223372036854775807); + ("9223372.0368547758071e3", 9223372036854775807); + ("922337.20368547758071e4", 9223372036854775807); + ("92233.720368547758071e5", 9223372036854775807); + ("9223.3720368547758071e6", 9223372036854775807); + ("922.33720368547758071e7", 9223372036854775807); + ("92.233720368547758071e8", 9223372036854775807); + ("9.2233720368547758071e9", 9223372036854775807); + ("0.92233720368547758071e10", 9223372036854775807); + ("0.092233720368547758071e11", 9223372036854775807); // Negative cases are also checked. }, fp128 { @@ -103,7 +716,205 @@ fn from_good_str_inexact() -> Result<()> { ("13.9999999999999999999999999999999999999999999999999999999999999", 14000000000000000000); ("170141183460469231731.6873037158841057271", - 170141183460469231731687303715884105727) + 170141183460469231731687303715884105727); + + ("13000000000000000000100e-21", 13000000000000000000); + ("1300000000000000000010e-20", 13000000000000000000); + ("130000000000000000001e-19", 13000000000000000000); + ("13000000000000000000.1e-18", 13000000000000000000); + ("1300000000000000000.01e-17", 13000000000000000000); + ("130000000000000000.001e-16", 13000000000000000000); + ("13000000000000000.0001e-15", 13000000000000000000); + ("1300000000000000.00001e-14", 13000000000000000000); + ("130000000000000.000001e-13", 13000000000000000000); + ("13000000000000.0000001e-12", 13000000000000000000); + ("1300000000000.00000001e-11", 13000000000000000000); + ("130000000000.000000001e-10", 13000000000000000000); + ("13000000000.0000000001e-9", 13000000000000000000); + ("1300000000.00000000001e-8", 13000000000000000000); + ("130000000.000000000001e-7", 13000000000000000000); + ("13000000.0000000000001e-6", 13000000000000000000); + ("1300000.00000000000001e-5", 13000000000000000000); + ("130000.000000000000001e-4", 13000000000000000000); + ("13000.0000000000000001e-3", 13000000000000000000); + ("1300.00000000000000001e-2", 13000000000000000000); + ("130.000000000000000001e-1", 13000000000000000000); + ("13.0000000000000000001e0", 13000000000000000000); + ("1.30000000000000000001e1", 13000000000000000000); + ("0.130000000000000000001e2", 13000000000000000000); + ("0.0130000000000000000001e3", 13000000000000000000); + ("0.00130000000000000000001e4", 13000000000000000000); + ("0.000130000000000000000001e5", 13000000000000000000); + + ("13000000000000000000500e-21", 13000000000000000001); + ("1300000000000000000050e-20", 13000000000000000001); + ("130000000000000000005e-19", 13000000000000000001); + ("13000000000000000000.5e-18", 13000000000000000001); + ("1300000000000000000.05e-17", 13000000000000000001); + ("130000000000000000.005e-16", 13000000000000000001); + ("13000000000000000.0005e-15", 13000000000000000001); + ("1300000000000000.00005e-14", 13000000000000000001); + ("130000000000000.000005e-13", 13000000000000000001); + ("13000000000000.0000005e-12", 13000000000000000001); + ("1300000000000.00000005e-11", 13000000000000000001); + ("130000000000.000000005e-10", 13000000000000000001); + ("13000000000.0000000005e-9", 13000000000000000001); + ("1300000000.00000000005e-8", 13000000000000000001); + ("130000000.000000000005e-7", 13000000000000000001); + ("13000000.0000000000005e-6", 13000000000000000001); + ("1300000.00000000000005e-5", 13000000000000000001); + ("130000.000000000000005e-4", 13000000000000000001); + ("13000.0000000000000005e-3", 13000000000000000001); + ("1300.00000000000000005e-2", 13000000000000000001); + ("130.000000000000000005e-1", 13000000000000000001); + ("13.0000000000000000005e0", 13000000000000000001); + ("1.30000000000000000005e1", 13000000000000000001); + ("0.130000000000000000005e2", 13000000000000000001); + ("0.0130000000000000000005e3", 13000000000000000001); + ("0.00130000000000000000005e4", 13000000000000000001); + ("0.000130000000000000000005e5", 13000000000000000001); + + ("13000000000000000000900e-21", 13000000000000000001); + ("1300000000000000000090e-20", 13000000000000000001); + ("130000000000000000009e-19", 13000000000000000001); + ("13000000000000000000.9e-18", 13000000000000000001); + ("1300000000000000000.09e-17", 13000000000000000001); + ("130000000000000000.009e-16", 13000000000000000001); + ("13000000000000000.0009e-15", 13000000000000000001); + ("1300000000000000.00009e-14", 13000000000000000001); + ("130000000000000.000009e-13", 13000000000000000001); + ("13000000000000.0000009e-12", 13000000000000000001); + ("1300000000000.00000009e-11", 13000000000000000001); + ("130000000000.000000009e-10", 13000000000000000001); + ("13000000000.0000000009e-9", 13000000000000000001); + ("1300000000.00000000009e-8", 13000000000000000001); + ("130000000.000000000009e-7", 13000000000000000001); + ("13000000.0000000000009e-6", 13000000000000000001); + ("1300000.00000000000009e-5", 13000000000000000001); + ("130000.000000000000009e-4", 13000000000000000001); + ("13000.0000000000000009e-3", 13000000000000000001); + ("1300.00000000000000009e-2", 13000000000000000001); + ("130.000000000000000009e-1", 13000000000000000001); + ("13.0000000000000000009e0", 13000000000000000001); + ("1.30000000000000000009e1", 13000000000000000001); + ("0.130000000000000000009e2", 13000000000000000001); + ("0.0130000000000000000009e3", 13000000000000000001); + ("0.00130000000000000000009e4", 13000000000000000001); + ("0.000130000000000000000009e5", 13000000000000000001); + + ("13999999999999999999999999999999999999999999999999999999999999900e-63", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999999999999999990e-62", 14000000000000000000); + ("139999999999999999999999999999999999999999999999999999999999999e-61", 14000000000000000000); + ("13999999999999999999999999999999999999999999999999999999999999.9e-60", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999999999999999.99e-59", 14000000000000000000); + ("139999999999999999999999999999999999999999999999999999999999.999e-58", 14000000000000000000); + ("13999999999999999999999999999999999999999999999999999999999.9999e-57", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999999999999.99999e-56", 14000000000000000000); + ("139999999999999999999999999999999999999999999999999999999.999999e-55", 14000000000000000000); + ("13999999999999999999999999999999999999999999999999999999.9999999e-54", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999999999.99999999e-53", 14000000000000000000); + ("139999999999999999999999999999999999999999999999999999.999999999e-52", 14000000000000000000); + ("13999999999999999999999999999999999999999999999999999.9999999999e-51", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999999.99999999999e-50", 14000000000000000000); + ("139999999999999999999999999999999999999999999999999.999999999999e-49", 14000000000000000000); + ("13999999999999999999999999999999999999999999999999.9999999999999e-48", 14000000000000000000); + ("1399999999999999999999999999999999999999999999999.99999999999999e-47", 14000000000000000000); + ("139999999999999999999999999999999999999999999999.999999999999999e-46", 14000000000000000000); + ("13999999999999999999999999999999999999999999999.9999999999999999e-45", 14000000000000000000); + ("1399999999999999999999999999999999999999999999.99999999999999999e-44", 14000000000000000000); + ("139999999999999999999999999999999999999999999.999999999999999999e-43", 14000000000000000000); + ("13999999999999999999999999999999999999999999.9999999999999999999e-42", 14000000000000000000); + ("1399999999999999999999999999999999999999999.99999999999999999999e-41", 14000000000000000000); + ("139999999999999999999999999999999999999999.999999999999999999999e-40", 14000000000000000000); + ("13999999999999999999999999999999999999999.9999999999999999999999e-39", 14000000000000000000); + ("1399999999999999999999999999999999999999.99999999999999999999999e-38", 14000000000000000000); + ("139999999999999999999999999999999999999.999999999999999999999999e-37", 14000000000000000000); + ("13999999999999999999999999999999999999.9999999999999999999999999e-36", 14000000000000000000); + ("1399999999999999999999999999999999999.99999999999999999999999999e-35", 14000000000000000000); + ("139999999999999999999999999999999999.999999999999999999999999999e-34", 14000000000000000000); + ("13999999999999999999999999999999999.9999999999999999999999999999e-33", 14000000000000000000); + ("1399999999999999999999999999999999.99999999999999999999999999999e-32", 14000000000000000000); + ("139999999999999999999999999999999.999999999999999999999999999999e-31", 14000000000000000000); + ("13999999999999999999999999999999.9999999999999999999999999999999e-30", 14000000000000000000); + ("1399999999999999999999999999999.99999999999999999999999999999999e-29", 14000000000000000000); + ("139999999999999999999999999999.999999999999999999999999999999999e-28", 14000000000000000000); + ("13999999999999999999999999999.9999999999999999999999999999999999e-27", 14000000000000000000); + ("1399999999999999999999999999.99999999999999999999999999999999999e-26", 14000000000000000000); + ("139999999999999999999999999.999999999999999999999999999999999999e-25", 14000000000000000000); + ("13999999999999999999999999.9999999999999999999999999999999999999e-24", 14000000000000000000); + ("1399999999999999999999999.99999999999999999999999999999999999999e-23", 14000000000000000000); + ("139999999999999999999999.999999999999999999999999999999999999999e-22", 14000000000000000000); + ("13999999999999999999999.9999999999999999999999999999999999999999e-21", 14000000000000000000); + ("1399999999999999999999.99999999999999999999999999999999999999999e-20", 14000000000000000000); + ("139999999999999999999.999999999999999999999999999999999999999999e-19", 14000000000000000000); + ("13999999999999999999.9999999999999999999999999999999999999999999e-18", 14000000000000000000); + ("1399999999999999999.99999999999999999999999999999999999999999999e-17", 14000000000000000000); + ("139999999999999999.999999999999999999999999999999999999999999999e-16", 14000000000000000000); + ("13999999999999999.9999999999999999999999999999999999999999999999e-15", 14000000000000000000); + ("1399999999999999.99999999999999999999999999999999999999999999999e-14", 14000000000000000000); + ("139999999999999.999999999999999999999999999999999999999999999999e-13", 14000000000000000000); + ("13999999999999.9999999999999999999999999999999999999999999999999e-12", 14000000000000000000); + ("1399999999999.99999999999999999999999999999999999999999999999999e-11", 14000000000000000000); + ("139999999999.999999999999999999999999999999999999999999999999999e-10", 14000000000000000000); + ("13999999999.9999999999999999999999999999999999999999999999999999e-9", 14000000000000000000); + ("1399999999.99999999999999999999999999999999999999999999999999999e-8", 14000000000000000000); + ("139999999.999999999999999999999999999999999999999999999999999999e-7", 14000000000000000000); + ("13999999.9999999999999999999999999999999999999999999999999999999e-6", 14000000000000000000); + ("1399999.99999999999999999999999999999999999999999999999999999999e-5", 14000000000000000000); + ("139999.999999999999999999999999999999999999999999999999999999999e-4", 14000000000000000000); + ("13999.9999999999999999999999999999999999999999999999999999999999e-3", 14000000000000000000); + ("1399.99999999999999999999999999999999999999999999999999999999999e-2", 14000000000000000000); + ("139.999999999999999999999999999999999999999999999999999999999999e-1", 14000000000000000000); + ("13.9999999999999999999999999999999999999999999999999999999999999e0", 14000000000000000000); + ("1.39999999999999999999999999999999999999999999999999999999999999e1", 14000000000000000000); + ("0.139999999999999999999999999999999999999999999999999999999999999e2", 14000000000000000000); + ("0.0139999999999999999999999999999999999999999999999999999999999999e3", 14000000000000000000); + + ("170141183460469231731687303715884105727100e-21", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410572710e-20", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841057271e-19", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884105727.1e-18", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410572.71e-17", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841057.271e-16", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884105.7271e-15", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588410.57271e-14", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158841.057271e-13", 170141183460469231731687303715884105727); + ("170141183460469231731687303715884.1057271e-12", 170141183460469231731687303715884105727); + ("17014118346046923173168730371588.41057271e-11", 170141183460469231731687303715884105727); + ("1701411834604692317316873037158.841057271e-10", 170141183460469231731687303715884105727); + ("170141183460469231731687303715.8841057271e-9", 170141183460469231731687303715884105727); + ("17014118346046923173168730371.58841057271e-8", 170141183460469231731687303715884105727); + ("1701411834604692317316873037.158841057271e-7", 170141183460469231731687303715884105727); + ("170141183460469231731687303.7158841057271e-6", 170141183460469231731687303715884105727); + ("17014118346046923173168730.37158841057271e-5", 170141183460469231731687303715884105727); + ("1701411834604692317316873.037158841057271e-4", 170141183460469231731687303715884105727); + ("170141183460469231731687.3037158841057271e-3", 170141183460469231731687303715884105727); + ("17014118346046923173168.73037158841057271e-2", 170141183460469231731687303715884105727); + ("1701411834604692317316.873037158841057271e-1", 170141183460469231731687303715884105727); + ("170141183460469231731.6873037158841057271e0", 170141183460469231731687303715884105727); + ("17014118346046923173.16873037158841057271e1", 170141183460469231731687303715884105727); + ("1701411834604692317.316873037158841057271e2", 170141183460469231731687303715884105727); + ("170141183460469231.7316873037158841057271e3", 170141183460469231731687303715884105727); + ("17014118346046923.17316873037158841057271e4", 170141183460469231731687303715884105727); + ("1701411834604692.317316873037158841057271e5", 170141183460469231731687303715884105727); + ("170141183460469.2317316873037158841057271e6", 170141183460469231731687303715884105727); + ("17014118346046.92317316873037158841057271e7", 170141183460469231731687303715884105727); + ("1701411834604.692317316873037158841057271e8", 170141183460469231731687303715884105727); + ("170141183460.4692317316873037158841057271e9", 170141183460469231731687303715884105727); + ("17014118346.04692317316873037158841057271e10", 170141183460469231731687303715884105727); + ("1701411834.604692317316873037158841057271e11", 170141183460469231731687303715884105727); + ("170141183.4604692317316873037158841057271e12", 170141183460469231731687303715884105727); + ("17014118.34604692317316873037158841057271e13", 170141183460469231731687303715884105727); + ("1701411.834604692317316873037158841057271e14", 170141183460469231731687303715884105727); + ("170141.1834604692317316873037158841057271e15", 170141183460469231731687303715884105727); + ("17014.11834604692317316873037158841057271e16", 170141183460469231731687303715884105727); + ("1701.411834604692317316873037158841057271e17", 170141183460469231731687303715884105727); + ("170.1411834604692317316873037158841057271e18", 170141183460469231731687303715884105727); + ("17.01411834604692317316873037158841057271e19", 170141183460469231731687303715884105727); + ("1.701411834604692317316873037158841057271e20", 170141183460469231731687303715884105727); + ("0.1701411834604692317316873037158841057271e21", 170141183460469231731687303715884105727); + ("0.01701411834604692317316873037158841057271e22", 170141183460469231731687303715884105727); + ("0.001701411834604692317316873037158841057271e23", 170141183460469231731687303715884105727); // Negative cases are also checked. }, }; @@ -124,7 +935,9 @@ fn from_bad_str() -> Result<()> { }, all { (""); - ("7.02e5"); + ("7.02ee5"); + ("7.02eE5"); + ("7.-02eE5"); ("a.12"); ("12.a"); ("100000000000000000000000"); @@ -133,12 +946,24 @@ fn from_bad_str() -> Result<()> { ("170141183460469231731.6873037158841057275"); ("-170141183460469231731.687303715884105729"); ("-170141183460469231731.6873037158841057285"); + + ("100000000000000000000000e0"); + ("170141183460469231731687303715.884105728e0"); + ("170141183460469231731.687303715884105728e0"); + ("170141183460469231731.6873037158841057275e0"); + ("-170141183460469231731.687303715884105729e0"); + ("-170141183460469231731.6873037158841057285e0"); }, fp64 { ("9223372036.854775808"); ("9223372036.8547758075"); ("-9223372036.854775809"); ("-9223372036.8547758085"); + + ("9223372036.854775808e0"); + ("9223372036.8547758075e0"); + ("-9223372036.854775809e0"); + ("-9223372036.8547758085e0"); }, }; Ok(())