\ generic words.
: <range
> ( nnn
-) swap within
abort" range" ; : only ( n-n1|0) ?dup 0<> ;
: except ( n-n0|1) ?dup 0= ;
: c@+ ( a-ca) dup c@ swap 1+ ;
\ fixed string arrays with offset indexing.
\ c1 item width, c2 starting index.
0 Value ds-width
: Digits ( cc-) create c, dup to ds-width 1+ c,
does> ( u-) c@+ >r - r> c@+ >r * r> + count type ;
: ds" ( "-) '"' parse ds-width min dup c,
here swap ds-width allot move ;
cr .( decimal number names: )
5 1 Digits th-unit
ds" one" ds" two" ds" three"
ds" four" ds" five" ds" six"
ds" seven" ds" eight" ds" nine"
9 10 Digits th-teen
ds" ten" ds" eleven" ds" twelve"
ds" thirteen" ds" fourteen" ds" fifteen"
ds" sixteen" ds" seventeen" ds" eighteen"
ds" nineteen"
7 2 Digits th-ten
ds" twenty" ds" thirty" ds" forty"
ds" fifty" ds" sixty" ds" seventy"
ds" eighty" ds" ninety"
\ example: types "forty".
cr 4 th-ten
: zero ." zero " ;
: hundred ." hundred " ;
: thousand ." thousand " ;
: dash ( u-u) dup IF '-' emit ELSE space THEN ;
: triple
( u
-) except IF
exit THEN
100 /mod only IF th-unit space hundred THEN
dup
10 20 within IF th
-teen space
exit THEN
10 /mod only IF th-ten dash THEN
only IF th-unit space THEN ;
: say-deci ( u-) dup 0 1000000 <range>
1000 /mod only IF triple thousand THEN
triple ;
cr 12 say-deci
cr 69 say-deci
cr 420 say-deci
cr 105 say-deci
cr 100010 say-deci
cr
cr .( seximal number names: )
#6 base !
10 1 Digits th-unit
ds" one" ds" two" ds" three"
ds" four" ds" five" ds" six"
ds" seven" ds" eight" ds" nine"
ds" ten" ds" eleven" ds" twelve"
10 2 Digits th-six
ds" dozen" ds" thirsy"
ds" forsy" ds" fifsy"
: nif ." nif " ;
: unexian ." unexian " ;
: pair
( u
-) except IF
exit THEN
dup
21 < IF th
-unit space
exit THEN
10 /mod only IF th-six dash THEN
only IF th-unit THEN ;
: nifs
( u
-) except IF
exit THEN
dup 1 = IF drop ELSE pair THEN nif ;
: quad
( u
-) except IF
exit THEN
100 /mod nifs pair ;
: say-sexi ( u-) dup 0 1000000 <range>
10000 /mod only IF quad unexian THEN quad ;
cr 12 say-sexi
cr 153 say-sexi \ equals sixty-nine.
cr 420 say-sexi
cr 105 say-sexi
cr 1540 say-sexi \ equals four hundred twenty.
cr 101425 say-sexi
cr