Merge branch 'master' of git://factorcode.org/git/factor
commit
cb1dca3da7
|
@ -4,4 +4,4 @@ IN: math.text.english
|
|||
HELP: number>text
|
||||
{ $values { "n" integer } { "str" string } }
|
||||
{ $description "Converts an integer to a text string representation in English, including appropriate punctuation and conjunctions." }
|
||||
{ $examples { $example "USING: math.text.english prettyprint ;" "12345 number>text ." "\"Twelve Thousand, Three Hundred and Forty-Five\"" } } ;
|
||||
{ $examples { $example "USING: math.text.english prettyprint ;" "12345 number>text ." "\"twelve thousand, three hundred and forty-five\"" } } ;
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
USING: math.functions math.text.english tools.test ;
|
||||
IN: math.text.english.tests
|
||||
|
||||
[ "Zero" ] [ 0 number>text ] unit-test
|
||||
[ "Twenty-One" ] [ 21 number>text ] unit-test
|
||||
[ "One Hundred" ] [ 100 number>text ] unit-test
|
||||
[ "One Hundred and One" ] [ 101 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 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 Hundred and Eleven Thousand, One Hundred and Eleven" ] [ 1111111 number>text ] unit-test
|
||||
[ "One Duotrigintillion" ] [ 10 99 ^ number>text ] unit-test
|
||||
[ "zero" ] [ 0 number>text ] unit-test
|
||||
[ "twenty-one" ] [ 21 number>text ] unit-test
|
||||
[ "one hundred" ] [ 100 number>text ] unit-test
|
||||
[ "one hundred and one" ] [ 101 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 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 hundred and eleven thousand, one hundred and eleven" ] [ 1111111 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
|
||||
|
|
|
@ -7,35 +7,44 @@ IN: math.text.english
|
|||
<PRIVATE
|
||||
|
||||
: small-numbers ( n -- str )
|
||||
{ "Zero" "One" "Two" "Three" "Four" "Five" "Six" "Seven" "Eight" "Nine"
|
||||
"Ten" "Eleven" "Twelve" "Thirteen" "Fourteen" "Fifteen" "Sixteen"
|
||||
"Seventeen" "Eighteen" "Nineteen" } nth ;
|
||||
{
|
||||
"zero" "one" "two" "three" "four" "five" "six"
|
||||
"seven" "eight" "nine" "ten" "eleven" "twelve"
|
||||
"thirteen" "fourteen" "fifteen" "sixteen" "seventeen"
|
||||
"eighteen" "nineteen"
|
||||
} nth ;
|
||||
|
||||
: 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
|
||||
{ f "Thousand" "Million" "Billion" "Trillion" "Quadrillion" "Quintillion"
|
||||
"Sextillion" "Septillion" "Octillion" "Nonillion" "Decillion" "Undecillion"
|
||||
"Duodecillion" "Tredecillion" "Quattuordecillion" "Quindecillion"
|
||||
"Sexdecillion" "Septendecillion" "Octodecillion" "Novemdecillion"
|
||||
"Vigintillion" "Unvigintillion" "Duovigintillion" "Trevigintillion"
|
||||
"Quattuorvigintillion" "Quinvigintillion" "Sexvigintillion"
|
||||
"Septvigintillion" "Octovigintillion" "Novemvigintillion" "Trigintillion"
|
||||
"Untrigintillion" "Duotrigintillion" } nth ;
|
||||
{
|
||||
f "thousand" "million" "billion" "trillion" "quadrillion"
|
||||
"quintillion" "sextillion" "septillion" "octillion"
|
||||
"nonillion" "decillion" "undecillion" "duodecillion"
|
||||
"tredecillion" "quattuordecillion" "quindecillion"
|
||||
"sexdecillion" "septendecillion" "octodecillion" "novemdecillion"
|
||||
"vigintillion" "unvigintillion" "duovigintillion" "trevigintillion"
|
||||
"quattuorvigintillion" "quinvigintillion" "sexvigintillion"
|
||||
"septvigintillion" "octovigintillion" "novemvigintillion"
|
||||
"trigintillion" "untrigintillion" "duotrigintillion"
|
||||
} nth ;
|
||||
|
||||
SYMBOL: and-needed?
|
||||
: set-conjunction ( seq -- )
|
||||
first { [ 100 < ] [ 0 > ] } 1&& and-needed? set ;
|
||||
|
||||
: negative-text ( n -- str )
|
||||
0 < "Negative " "" ? ;
|
||||
0 < "negative " "" ? ;
|
||||
|
||||
: hundreds-place ( n -- str )
|
||||
100 /mod over 0 = [
|
||||
2drop ""
|
||||
] [
|
||||
[ small-numbers " Hundred" append ] dip
|
||||
[ small-numbers " hundred" append ] dip
|
||||
0 = [ " and " append ] unless
|
||||
] if ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue