Skip to content

Commit

Permalink
Merge #201
Browse files Browse the repository at this point in the history
201: Use standard library for float from_str_radix with radix 10 r=cuviper a=tspiteri

Fixes #198.

While at it, also make parsing of the `"-NaN"` string match the standard library.

Co-authored-by: Trevor Spiteri <tspiteri@ieee.org>
  • Loading branch information
bors[bot] and tspiteri committed Mar 1, 2021
2 parents e8da6fe + e71d7a9 commit 9c8f20e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -224,11 +224,19 @@ 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),
"-inf" => return Ok(core::$t::NEG_INFINITY),
"NaN" => return Ok(core::$t::NAN),
"-NaN" => return Ok(-core::$t::NAN),
_ => {},
}

Expand Down

0 comments on commit 9c8f20e

Please sign in to comment.