! 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
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 ;