math.text.english: support ratio, float, complex.

db4
John Benediktsson 2013-11-26 10:19:15 -08:00
parent 2370ed3918
commit c1bb600335
1 changed files with 22 additions and 2 deletions

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