Ver código fonte

use standard library for float from_str_radix with radix 10

Trevor Spiteri 4 anos atrás
pai
commit
e003ff4d65
1 arquivos alterados com 7 adições e 0 exclusões
  1. 7 0
      src/lib.rs

+ 7 - 0
src/lib.rs

@@ -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),