Update math.english with faster algorithm and new combinators

db4
Aaron Schaefer 2008-12-15 21:49:31 -05:00
parent e6802a4d24
commit c9e10e7b4a
1 changed files with 10 additions and 11 deletions

View File

@ -32,23 +32,22 @@ SYMBOL: and-needed?
0 < "Negative " "" ? ;
: 3digit-groups ( n -- seq )
number>string <reversed> 3 <groups>
[ reverse string>number ] map ;
[ dup 0 > ] [ 1000 /mod ] [ ] produce nip ;
: hundreds-place ( n -- str )
100 /mod swap dup zero? [
100 /mod over 0 = [
2drop ""
] [
small-numbers " Hundred" append
swap zero? [ " and " append ] unless
[ small-numbers " Hundred" append ] dip
0 = [ " and " append ] unless
] if ;
: tens-place ( n -- str )
100 mod dup 20 >= [
10 /mod [ tens ] dip
dup zero? [ drop ] [ "-" swap small-numbers 3append ] if
dup 0 = [ drop ] [ small-numbers "-" glue ] if
] [
dup zero? [ drop "" ] [ small-numbers ] if
dup 0 = [ drop "" ] [ small-numbers ] if
] if ;
: 3digits>text ( n -- str )
@ -59,15 +58,15 @@ SYMBOL: and-needed?
[ " " glue ] unless-empty ;
: append-with-conjunction ( str1 str2 -- newstr )
over length zero? [
over length 0 = [
nip
] [
and-needed? get " and " ", " ? rot 3append
and-needed? off
swap and-needed? get " and " ", " ?
glue and-needed? off
] if ;
: (recombine) ( str index seq -- newstr )
2dup nth zero? [
2dup nth 0 = [
2drop
] [
text-with-scale append-with-conjunction