]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: allow '1+1/3.' for symmetry with '1/3.'
authorJon Harper <jon.harper87@gmail.com>
Mon, 15 Jun 2015 13:26:24 +0000 (15:26 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 25 Feb 2021 23:10:17 +0000 (17:10 -0600)
core/math/parser/parser.factor
core/syntax/syntax-docs.factor

index 30537bf6f1a4d426c7586c1c6173b8e663642ae7..0d23c5bbd8b1e129b0014307bd8e980964eef95c 100644 (file)
@@ -176,8 +176,11 @@ CONSTANT: min-magnitude-2 -1074
         ] [ neg ] if
     ] [ f ] if* ; inline
 
+: add-ratio? ( n/f -- ? )
+    dup real? [ dup >integer number= not ] [ drop f ] if ;
+
 : ?add-ratio ( m n/f -- m+n/f )
-    dup ratio? [ + ] [ 2drop f ] if ; inline
+    dup add-ratio? [ + ] [ 2drop f ] if ; inline
 
 : @abort ( i number-parse n x -- f )
     4drop f ; inline
index 39b57b32b0101e3a4ae425bd467366359ee3de13..6788acf7b59a7dd2e383f0429e7bcdbe01005d29 100644 (file)
@@ -91,6 +91,22 @@ ARTICLE: "syntax-floats" "Float syntax"
     "1/3. ."
     "0.3333333333333333"
 }
+{ $example
+    "1/0.5 ."
+    "2.0"
+}
+{ $example
+    "1/2.5 ."
+    "0.4"
+}
+{ $example
+    "1+1/2. ."
+    "1.5"
+}
+{ $example
+    "1+1/2.5 ."
+    "1.4"
+}
 "The special float values have their own syntax:"
 { $table
 { "Positive infinity" { $snippet "1/0." } }