about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2020-10-31 12:30:22 -0700
committerJubilee Young <workingjubilee@gmail.com>2021-03-22 17:02:08 -0700
commit588cc644ad6d6d6419dcd48651ae451557cdc100 (patch)
tree1070f14aab1896d53f069192b0189b3e7a0be52c
parentfc9b234928c1d64cc45686d9e61bb5993d8747fa (diff)
downloadrust-588cc644ad6d6d6419dcd48651ae451557cdc100.tar.gz
rust-588cc644ad6d6d6419dcd48651ae451557cdc100.zip
Add ability to read NaN/Infinity
-rw-r--r--library/core/src/num/dec2flt/mod.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/library/core/src/num/dec2flt/mod.rs b/library/core/src/num/dec2flt/mod.rs
index 20ac165c6c7..f008a64ffe6 100644
--- a/library/core/src/num/dec2flt/mod.rs
+++ b/library/core/src/num/dec2flt/mod.rs
@@ -239,13 +239,15 @@ fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
         ParseResult::Valid(decimal) => convert(decimal)?,
         ParseResult::ShortcutToInf => T::INFINITY,
         ParseResult::ShortcutToZero => T::ZERO,
-        ParseResult::Invalid => match s {
-            "inf" => T::INFINITY,
-            "NaN" => T::NAN,
-            _ => {
+        ParseResult::Invalid => {
+            if s.eq_ignore_ascii_case("nan") {
+                T::NAN
+            } else if s.eq_ignore_ascii_case("inf") || s.eq_ignore_ascii_case("infinity") {
+                T::INFINITY
+            } else {
                 return Err(pfe_invalid());
             }
-        },
+        }
     };
 
     match sign {