]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: fix ``"-.5" dec>``.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Jul 2015 03:16:34 +0000 (20:16 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Jul 2015 03:16:34 +0000 (20:16 -0700)
core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index 909c630265faca3eccedfabf21d26616cd1bc179..df9abe79246f43eb99ad8554d84bb131040c6bab 100644 (file)
@@ -361,5 +361,9 @@ unit-test
 { f } [ "0o0" bin> ] unit-test
 { f } [ "0x0" bin> ] unit-test
 
+! #1229, float parsing bug
+{ -0.5 } [ "-.5" dec> ] unit-test
+
 { t } [ most-positive-fixnum number>string string>number fixnum? ] unit-test
 { t } [ most-negative-fixnum number>string string>number fixnum? ] unit-test
+
index 8502e6ae5f5f24467f7b92b30fab8adeb08a4833..3f1edd5a3a07c2410b151acafc205ec9acc1d834 100644 (file)
@@ -279,13 +279,37 @@ DEFER: @neg-digit
         [ @pos-first-digit ]
     } case ; inline
 
-: @first-char-no-radix ( i number-parse n char -- n/f )
+: with-no-radix ( i number-parse n quot -- n/f )
+    [
+        swap {
+            { CHAR: b [ pick radix>> 16 = [ CHAR: b swap call ] [ @abort ] if ] }
+            { CHAR: o [ @abort ] }
+            { CHAR: x [ @abort ] }
+            [ swap call ]
+        } case
+    ] curry require-next-digit ; inline
+
+: @neg-first-digit-no-radix ( i number-parse n char -- n/f )
+    {
+        { CHAR: . [ ->required-mantissa ] }
+        { CHAR: 0 [ [ @neg-digit ] with-no-radix ] }
+        [ @neg-digit ]
+    } case ; inline
+
+: @pos-first-digit-no-radix ( i number-parse n char -- n/f )
     {
-        { CHAR: - [ [ @neg-digit ] require-next-digit ?neg ] }
-        { CHAR: + [ [ @pos-digit ] require-next-digit ] }
+        { CHAR: . [ ->required-mantissa ] }
+        { CHAR: 0 [ [ @pos-digit ] with-no-radix ] }
         [ @pos-digit ]
     } case ; inline
 
+: @first-char-no-radix ( i number-parse n char -- n/f )
+    {
+        { CHAR: - [ [ @neg-first-digit-no-radix ] require-next-digit ?neg ] }
+        { CHAR: + [ [ @pos-first-digit-no-radix ] require-next-digit ] }
+        [ @pos-first-digit-no-radix ]
+    } case ; inline
+
 PRIVATE>
 
 : string>number ( str -- n/f )