mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
reorganize namespacing
specify eng-us region and make room for future ordinal conversion
This commit is contained in:
parent
1ae891bbb0
commit
638afd8995
@ -30,120 +30,121 @@
|
||||
++ one-vigintillion (pow 10 63)
|
||||
++ max (pow 10 66)
|
||||
--
|
||||
:: +eng:number-to-words: convert @u to english
|
||||
::
|
||||
++ eng
|
||||
|= num=@u
|
||||
^- (unit tape)
|
||||
=+ numbers
|
||||
?: (gte num max)
|
||||
~
|
||||
:- ~
|
||||
|-
|
||||
^- tape
|
||||
:: 0-19
|
||||
?: =(num 0) "zero"
|
||||
?: =(num 1) "one"
|
||||
?: =(num 2) "two"
|
||||
?: =(num 3) "three"
|
||||
?: =(num 4) "four"
|
||||
?: =(num 5) "five"
|
||||
?: =(num 6) "six"
|
||||
?: =(num 7) "seven"
|
||||
?: =(num 8) "eight"
|
||||
?: =(num 9) "nine"
|
||||
?: =(num 10) "ten"
|
||||
?: =(num 11) "eleven"
|
||||
?: =(num 12) "twelve"
|
||||
?: =(num 13) "thirteen"
|
||||
?: =(num 14) "fourteen"
|
||||
?: =(num 15) "fifteen"
|
||||
?: =(num 16) "sixteen"
|
||||
?: =(num 17) "seventeen"
|
||||
?: =(num 18) "eighteen"
|
||||
?: =(num 19) "nineteen"
|
||||
:: 20-99
|
||||
::
|
||||
:: tpl: tens place
|
||||
:: rem: ones place
|
||||
:: sfx: suffix
|
||||
::
|
||||
=/ tpl (div num ten)
|
||||
=/ rem (mod num ten)
|
||||
=/ sfx
|
||||
?: |(=(rem 0) (gte tpl 10))
|
||||
++ eng-us
|
||||
|%
|
||||
++ to-words
|
||||
|= num=@u
|
||||
^- (unit tape)
|
||||
=+ numbers
|
||||
?: (gte num max)
|
||||
~
|
||||
['-' $(num rem)]
|
||||
?: =(tpl 2) (weld "twenty" sfx)
|
||||
?: =(tpl 3) (weld "thirty" sfx)
|
||||
?: =(tpl 4) (weld "forty" sfx)
|
||||
?: =(tpl 5) (weld "fifty" sfx)
|
||||
?: =(tpl 6) (weld "sixty" sfx)
|
||||
?: =(tpl 7) (weld "seventy" sfx)
|
||||
?: =(tpl 8) (weld "eighty" sfx)
|
||||
?: =(tpl 9) (weld "ninety" sfx)
|
||||
:: 100-max
|
||||
::
|
||||
:: num-break: repeated pattern from 100 on
|
||||
::
|
||||
=/ num-break
|
||||
:- ~
|
||||
|-
|
||||
^- tape
|
||||
:: 0-19
|
||||
?: =(num 0) "zero"
|
||||
?: =(num 1) "one"
|
||||
?: =(num 2) "two"
|
||||
?: =(num 3) "three"
|
||||
?: =(num 4) "four"
|
||||
?: =(num 5) "five"
|
||||
?: =(num 6) "six"
|
||||
?: =(num 7) "seven"
|
||||
?: =(num 8) "eight"
|
||||
?: =(num 9) "nine"
|
||||
?: =(num 10) "ten"
|
||||
?: =(num 11) "eleven"
|
||||
?: =(num 12) "twelve"
|
||||
?: =(num 13) "thirteen"
|
||||
?: =(num 14) "fourteen"
|
||||
?: =(num 15) "fifteen"
|
||||
?: =(num 16) "sixteen"
|
||||
?: =(num 17) "seventeen"
|
||||
?: =(num 18) "eighteen"
|
||||
?: =(num 19) "nineteen"
|
||||
:: 20-99
|
||||
::
|
||||
:: min: minimum to qualify for this break
|
||||
:: str: english word for this break
|
||||
:: tpl: tens place
|
||||
:: rem: ones place
|
||||
:: sfx: suffix
|
||||
::
|
||||
|= [min=@u str=tape]
|
||||
=/ rem (mod num min)
|
||||
;: weld
|
||||
^$(num (div num min))
|
||||
[' ' str]
|
||||
?: =(rem 0)
|
||||
=/ tpl (div num ten)
|
||||
=/ rem (mod num ten)
|
||||
=/ sfx
|
||||
?: |(=(rem 0) (gte tpl 10))
|
||||
~
|
||||
%+ weld
|
||||
?:((lth rem one-hundred) " and " ", ")
|
||||
^$(num rem)
|
||||
==
|
||||
::
|
||||
?: (lth num one-thousand)
|
||||
(num-break one-hundred "hundred")
|
||||
?: (lth num one-million)
|
||||
(num-break one-thousand "thousand")
|
||||
?: (lth num one-billion)
|
||||
(num-break one-million "million")
|
||||
?: (lth num one-trillion)
|
||||
(num-break one-billion "billion")
|
||||
?: (lth num one-quadrillion)
|
||||
(num-break one-trillion "trillion")
|
||||
?: (lth num one-quintillion)
|
||||
(num-break one-quadrillion "quadrillion")
|
||||
?: (lth num one-sextillion)
|
||||
(num-break one-quintillion "quintillion")
|
||||
?: (lth num one-septillion)
|
||||
(num-break one-sextillion "sextillion")
|
||||
?: (lth num one-octillion)
|
||||
(num-break one-septillion "septillion")
|
||||
?: (lth num one-nonillion)
|
||||
(num-break one-octillion "octillion")
|
||||
?: (lth num one-decillion)
|
||||
(num-break one-nonillion "nonillion")
|
||||
?: (lth num one-undecillion)
|
||||
(num-break one-decillion "decillion")
|
||||
?: (lth num one-duodecillion)
|
||||
(num-break one-undecillion "undecillion")
|
||||
?: (lth num one-tredecillion)
|
||||
(num-break one-duodecillion "duodecillion")
|
||||
?: (lth num one-quattuordecillion)
|
||||
(num-break one-tredecillion "tredecillion")
|
||||
?: (lth num one-quindecillion)
|
||||
(num-break one-quattuordecillion "quattuordecillion")
|
||||
?: (lth num one-sexdecillion)
|
||||
(num-break one-quindecillion "quindecillion")
|
||||
?: (lth num one-septendecillion)
|
||||
(num-break one-sexdecillion "sexdecillion")
|
||||
?: (lth num one-octodecillion)
|
||||
(num-break one-septendecillion "septendecillion")
|
||||
?: (lth num one-novemdecillion)
|
||||
(num-break one-octodecillion "octodecillion")
|
||||
?: (lth num one-vigintillion)
|
||||
(num-break one-novemdecillion "novemdecillion")
|
||||
(num-break one-vigintillion "vigintillion")
|
||||
['-' $(num rem)]
|
||||
?: =(tpl 2) (weld "twenty" sfx)
|
||||
?: =(tpl 3) (weld "thirty" sfx)
|
||||
?: =(tpl 4) (weld "forty" sfx)
|
||||
?: =(tpl 5) (weld "fifty" sfx)
|
||||
?: =(tpl 6) (weld "sixty" sfx)
|
||||
?: =(tpl 7) (weld "seventy" sfx)
|
||||
?: =(tpl 8) (weld "eighty" sfx)
|
||||
?: =(tpl 9) (weld "ninety" sfx)
|
||||
:: 100-max
|
||||
::
|
||||
:: num-break: repeated pattern from 100 on
|
||||
::
|
||||
=/ num-break
|
||||
::
|
||||
:: min: minimum to qualify for this break
|
||||
:: str: english word for this break
|
||||
::
|
||||
|= [min=@u str=tape]
|
||||
=/ rem (mod num min)
|
||||
;: weld
|
||||
^$(num (div num min))
|
||||
[' ' str]
|
||||
?: =(rem 0)
|
||||
~
|
||||
%+ weld
|
||||
?:((lth rem one-hundred) " and " ", ")
|
||||
^$(num rem)
|
||||
==
|
||||
::
|
||||
?: (lth num one-thousand)
|
||||
(num-break one-hundred "hundred")
|
||||
?: (lth num one-million)
|
||||
(num-break one-thousand "thousand")
|
||||
?: (lth num one-billion)
|
||||
(num-break one-million "million")
|
||||
?: (lth num one-trillion)
|
||||
(num-break one-billion "billion")
|
||||
?: (lth num one-quadrillion)
|
||||
(num-break one-trillion "trillion")
|
||||
?: (lth num one-quintillion)
|
||||
(num-break one-quadrillion "quadrillion")
|
||||
?: (lth num one-sextillion)
|
||||
(num-break one-quintillion "quintillion")
|
||||
?: (lth num one-septillion)
|
||||
(num-break one-sextillion "sextillion")
|
||||
?: (lth num one-octillion)
|
||||
(num-break one-septillion "septillion")
|
||||
?: (lth num one-nonillion)
|
||||
(num-break one-octillion "octillion")
|
||||
?: (lth num one-decillion)
|
||||
(num-break one-nonillion "nonillion")
|
||||
?: (lth num one-undecillion)
|
||||
(num-break one-decillion "decillion")
|
||||
?: (lth num one-duodecillion)
|
||||
(num-break one-undecillion "undecillion")
|
||||
?: (lth num one-tredecillion)
|
||||
(num-break one-duodecillion "duodecillion")
|
||||
?: (lth num one-quattuordecillion)
|
||||
(num-break one-tredecillion "tredecillion")
|
||||
?: (lth num one-quindecillion)
|
||||
(num-break one-quattuordecillion "quattuordecillion")
|
||||
?: (lth num one-sexdecillion)
|
||||
(num-break one-quindecillion "quindecillion")
|
||||
?: (lth num one-septendecillion)
|
||||
(num-break one-sexdecillion "sexdecillion")
|
||||
?: (lth num one-octodecillion)
|
||||
(num-break one-septendecillion "septendecillion")
|
||||
?: (lth num one-novemdecillion)
|
||||
(num-break one-octodecillion "octodecillion")
|
||||
?: (lth num one-vigintillion)
|
||||
(num-break one-novemdecillion "novemdecillion")
|
||||
(num-break one-vigintillion "vigintillion")
|
||||
--
|
||||
--
|
||||
|
@ -3,51 +3,52 @@
|
||||
/+ number-to-words, *test
|
||||
::
|
||||
|%
|
||||
++ test-eng
|
||||
++ test-eng-us
|
||||
=+ eng-us:number-to-words
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"zero"
|
||||
!> (eng:number-to-words 0)
|
||||
!> (to-words 0)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one"
|
||||
!> (eng:number-to-words 1)
|
||||
!> (to-words 1)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"twelve"
|
||||
!> (eng:number-to-words 12)
|
||||
!> (to-words 12)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"twenty"
|
||||
!> (eng:number-to-words 20)
|
||||
!> (to-words 20)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"ninety-nine"
|
||||
!> (eng:number-to-words 99)
|
||||
!> (to-words 99)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one hundred"
|
||||
!> (eng:number-to-words 100)
|
||||
!> (to-words 100)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one hundred and eleven"
|
||||
!> (eng:number-to-words 111)
|
||||
!> (to-words 111)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one thousand"
|
||||
!> (eng:number-to-words 1.000)
|
||||
!> (to-words 1.000)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one thousand, one hundred and eleven"
|
||||
!> (eng:number-to-words 1.111)
|
||||
!> (to-words 1.111)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one million and one"
|
||||
!> (eng:number-to-words 1.000.001)
|
||||
!> (to-words 1.000.001)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one trillion"
|
||||
!> (eng:number-to-words (pow 10 12))
|
||||
!> (to-words (pow 10 12))
|
||||
::
|
||||
%+ expect-eq
|
||||
!>
|
||||
@ -59,10 +60,10 @@
|
||||
"hundred and nine million, five hundred and fifty-one thousand, six "
|
||||
"hundred and sixteen"
|
||||
==
|
||||
!> (eng:number-to-words 18.446.744.073.709.551.616)
|
||||
!> (to-words 18.446.744.073.709.551.616)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> `(unit tape)``"one vigintillion"
|
||||
!> (eng:number-to-words (pow 10 63))
|
||||
!> (to-words (pow 10 63))
|
||||
==
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user