Skip to content

Commit 588cc64

Browse files
Add ability to read NaN/Infinity
1 parent fc9b234 commit 588cc64

File tree

1 file changed

+7
-5
lines changed
  • library/core/src/num/dec2flt

1 file changed

+7
-5
lines changed

library/core/src/num/dec2flt/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,15 @@ fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
239239
ParseResult::Valid(decimal) => convert(decimal)?,
240240
ParseResult::ShortcutToInf => T::INFINITY,
241241
ParseResult::ShortcutToZero => T::ZERO,
242-
ParseResult::Invalid => match s {
243-
"inf" => T::INFINITY,
244-
"NaN" => T::NAN,
245-
_ => {
242+
ParseResult::Invalid => {
243+
if s.eq_ignore_ascii_case("nan") {
244+
T::NAN
245+
} else if s.eq_ignore_ascii_case("inf") || s.eq_ignore_ascii_case("infinity") {
246+
T::INFINITY
247+
} else {
246248
return Err(pfe_invalid());
247249
}
248-
},
250+
}
249251
};
250252

251253
match sign {

0 commit comments

Comments
 (0)