don't capitalize the first letter of each word in math.text.english

db4
Doug Coleman 2009-08-11 15:34:11 -05:00
parent f8405e9c55
commit 7a1837b15a
2 changed files with 35 additions and 26 deletions

View File

@ -1,15 +1,15 @@
USING: math.functions math.text.english tools.test ; USING: math.functions math.text.english tools.test ;
IN: math.text.english.tests IN: math.text.english.tests
[ "Zero" ] [ 0 number>text ] unit-test [ "zero" ] [ 0 number>text ] unit-test
[ "Twenty-One" ] [ 21 number>text ] unit-test [ "twenty-one" ] [ 21 number>text ] unit-test
[ "One Hundred" ] [ 100 number>text ] unit-test [ "one hundred" ] [ 100 number>text ] unit-test
[ "One Hundred and One" ] [ 101 number>text ] unit-test [ "one hundred and one" ] [ 101 number>text ] unit-test
[ "One Thousand and One" ] [ 1001 number>text ] unit-test [ "one thousand and one" ] [ 1001 number>text ] unit-test
[ "One Thousand, One Hundred and One" ] [ 1101 number>text ] unit-test [ "one thousand, one hundred and one" ] [ 1101 number>text ] unit-test
[ "One Million, One Thousand and One" ] [ 1001001 number>text ] unit-test [ "one million, one thousand and one" ] [ 1001001 number>text ] unit-test
[ "One Million, One Thousand, One Hundred and One" ] [ 1001101 number>text ] unit-test [ "one million, one thousand, one hundred and one" ] [ 1001101 number>text ] unit-test
[ "One Million, One Hundred and Eleven Thousand, One Hundred and Eleven" ] [ 1111111 number>text ] unit-test [ "one million, one hundred and eleven thousand, one hundred and eleven" ] [ 1111111 number>text ] unit-test
[ "One Duotrigintillion" ] [ 10 99 ^ number>text ] unit-test [ "one duotrigintillion" ] [ 10 99 ^ number>text ] unit-test
[ "Negative One Hundred and Twenty-Three" ] [ -123 number>text ] unit-test [ "negative one hundred and twenty-three" ] [ -123 number>text ] unit-test

View File

@ -7,35 +7,44 @@ IN: math.text.english
<PRIVATE <PRIVATE
: small-numbers ( n -- str ) : small-numbers ( n -- str )
{ "Zero" "One" "Two" "Three" "Four" "Five" "Six" "Seven" "Eight" "Nine" {
"Ten" "Eleven" "Twelve" "Thirteen" "Fourteen" "Fifteen" "Sixteen" "zero" "one" "two" "three" "four" "five" "six"
"Seventeen" "Eighteen" "Nineteen" } nth ; "seven" "eight" "nine" "ten" "eleven" "twelve"
"thirteen" "fourteen" "fifteen" "sixteen" "seventeen"
"eighteen" "nineteen"
} nth ;
: tens ( n -- str ) : tens ( n -- str )
{ f f "Twenty" "Thirty" "Forty" "Fifty" "Sixty" "Seventy" "Eighty" "Ninety" } nth ; {
f f "twenty" "thirty" "forty" "fifty" "sixty"
"seventy" "eighty" "ninety"
} nth ;
: scale-numbers ( n -- str ) ! up to 10^99 : scale-numbers ( n -- str ) ! up to 10^99
{ f "Thousand" "Million" "Billion" "Trillion" "Quadrillion" "Quintillion" {
"Sextillion" "Septillion" "Octillion" "Nonillion" "Decillion" "Undecillion" f "thousand" "million" "billion" "trillion" "quadrillion"
"Duodecillion" "Tredecillion" "Quattuordecillion" "Quindecillion" "quintillion" "sextillion" "septillion" "octillion"
"Sexdecillion" "Septendecillion" "Octodecillion" "Novemdecillion" "nonillion" "decillion" "undecillion" "duodecillion"
"Vigintillion" "Unvigintillion" "Duovigintillion" "Trevigintillion" "tredecillion" "quattuordecillion" "quindecillion"
"Quattuorvigintillion" "Quinvigintillion" "Sexvigintillion" "sexdecillion" "septendecillion" "octodecillion" "novemdecillion"
"Septvigintillion" "Octovigintillion" "Novemvigintillion" "Trigintillion" "vigintillion" "unvigintillion" "duovigintillion" "trevigintillion"
"Untrigintillion" "Duotrigintillion" } nth ; "quattuorvigintillion" "quinvigintillion" "sexvigintillion"
"septvigintillion" "octovigintillion" "novemvigintillion"
"trigintillion" "untrigintillion" "duotrigintillion"
} nth ;
SYMBOL: and-needed? SYMBOL: and-needed?
: set-conjunction ( seq -- ) : set-conjunction ( seq -- )
first { [ 100 < ] [ 0 > ] } 1&& and-needed? set ; first { [ 100 < ] [ 0 > ] } 1&& and-needed? set ;
: negative-text ( n -- str ) : negative-text ( n -- str )
0 < "Negative " "" ? ; 0 < "negative " "" ? ;
: hundreds-place ( n -- str ) : hundreds-place ( n -- str )
100 /mod over 0 = [ 100 /mod over 0 = [
2drop "" 2drop ""
] [ ] [
[ small-numbers " Hundred" append ] dip [ small-numbers " hundred" append ] dip
0 = [ " and " append ] unless 0 = [ " and " append ] unless
] if ; ] if ;