Version: 5.2.1
cardinal: get the cardinal string representation of a number
Danny Yoo <dyoo@hashcollision.org>
(require (planet dyoo/cardinal:1:=0)) |
This library provides the function number->cardinal to get the english
cardinal string representation of a number.
> (require (planet dyoo/cardinal))
> (number->cardinal 0) "zero"
> (number->cardinal 1) "one"
> (number->cardinal 2) "two"
> (number->cardinal 31415926) "thirty-one million four hundred fifteen thousand nine hundred twenty-six"
The main function provided by the library is:
(number->cardinal n) → string n : exact-nonnegative-integer
Given n, produces the cardinal string representation
of the number.
> (number->cardinal 0) "zero"
> (number->cardinal 1) "one"
> (number->cardinal 1024) "one thousand twenty-four"
> (number->cardinal 2048) "two thousand forty-eight"
> (number->cardinal 4096) "four thousand ninety-six"
> (number->cardinal (expt 2 10)) "one thousand twenty-four"
Note that this function is contracted to work only on nonnegative
integers up to maximum-countable-cardinal-number.
> (number->cardinal 1) "one"
> (number->cardinal 2) "two"
> (number->cardinal +inf.0) number->cardinal: contract violation, expected:
countable-number?, given: +inf.0
contract from:
/gpfs/main/home/dyoo/work/cardinal/cardinal.rkt
blaming: top-level
contract:
(-> countable-number? string?)
at: /gpfs/main/home/dyoo/work/cardinal/cardinal.rkt:13.3
1 Miscellaneous functions and values
(number->cardinal/uncontracted n) → string n : number
The uncontracted version of number->cardinal. This function
still produces a runtime error if given a number greater than
maximum-countable-cardinal-number.
maximum-countable-cardinal-number : number
The maximum number that this library can convert to a cardinal string representation.
As of this writing, this value is:
> maximum-countable-cardinal-number 999999999999999999999999999999999999999999999999999999999999999999