]> gitweb.factorcode.org Git - factor.git/commitdiff
math.text.english: support ratio, float, complex.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 26 Nov 2013 18:19:15 +0000 (10:19 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 26 Nov 2013 18:19:15 +0000 (10:19 -0800)
extra/math/text/english/english.factor

index 7f5387cb2ce1d4aba45e43961d9341989830dc02..b0a9404b6511f78705ea37f80b5ef375a9e2a5ec 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit grouping kernel math math.parser
-math.text.utils namespaces sequences ;
+USING: combinators.short-circuit grouping kernel math
+math.functions math.parser math.text.utils namespaces sequences
+splitting ;
 IN: math.text.english
 
 <PRIVATE
@@ -96,3 +97,22 @@ GENERIC: number>text ( n -- str )
 M: integer number>text
     [ "zero" ] [ [ (number>text) ] with-scope ] if-zero ;
 
+M: ratio number>text
+    >fraction [ number>text ] bi@ " divided by " glue ;
+
+M: float number>text
+    number>string "." split1 [
+        "-" ?head
+        [ string>number number>text ]
+        [ [ "negative " prepend ] when ] bi*
+    ] [
+        [ CHAR: 0 - small-numbers ] { } map-as " " join
+    ] bi* " point " glue ;
+
+M: complex number>text
+    >rect
+    [ number>text " i" append ]
+    [
+        [ 0 < " minus " " plus " ? ]
+        [ abs number>text " j" append ] bi
+    ] bi* 3append ;