Skip to content

Commit 9c8f20e

Browse files
bors[bot]tspiteri
andauthored
Merge #201
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 <[email protected]>
2 parents e8da6fe + e71d7a9 commit 9c8f20e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,19 @@ macro_rules! float_trait_impl {
224224
use self::FloatErrorKind::*;
225225
use self::ParseFloatError as PFE;
226226

227+
// Special case radix 10 to use more accurate standard library implementation
228+
if radix == 10 {
229+
return src.parse().map_err(|_| PFE {
230+
kind: if src.is_empty() { Empty } else { Invalid },
231+
});
232+
}
233+
227234
// Special values
228235
match src {
229236
"inf" => return Ok(core::$t::INFINITY),
230237
"-inf" => return Ok(core::$t::NEG_INFINITY),
231238
"NaN" => return Ok(core::$t::NAN),
239+
"-NaN" => return Ok(-core::$t::NAN),
232240
_ => {},
233241
}
234242

0 commit comments

Comments
 (0)