Skip to content

Commit

Permalink
use standard library for float from_str_radix with radix 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tspiteri committed Feb 5, 2021
1 parent e8da6fe commit e003ff4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Expand Up @@ -224,6 +224,13 @@ macro_rules! float_trait_impl {
use self::FloatErrorKind::*;
use self::ParseFloatError as PFE;

// Special case radix 10 to use more accurate standard library implementation
if radix == 10 {
return src.parse().map_err(|_| PFE {
kind: if src.is_empty() { Empty } else { Invalid },
});
}

// Special values
match src {
"inf" => return Ok(core::$t::INFINITY),
Expand Down

0 comments on commit e003ff4

Please sign in to comment.