nptclのブログ

Common Lisp処理系nptの開発メモです。https://github.com/nptcl/npt

整数を英語で表現する4(序数と負数)

最後に、序数と負数について説明します。

序数

数が0~19までの序数はすでに表に出しています。
例えば13は下記の通り。

* (format t "~:R" 13)
thirteenth

20以上の場合、例えば43は次のようになる。

* (format t "~:R" 43)
forty-third

40であるfortyは通常の表記ですが、最後の単語である3が序数となります。 単語がいくつあっても、最後だけが序数表記となります。 数が50であった場合は、十の位が最後の単語になるため、 fiftyの序数が表記されます。

* (format t "~:R" 50)
fiftieth

複数の単語の例を挙げます。

* (format t "~:R" 1234)
one thousand two hundred thirty-fourth

hundredの場合は単純にthをつけます。

* (format t "~:R" 100)
one hundredth

それ以外のもの、も例えばthousandmillion、 あるいは巨大な単位milliquattuortrigintaducentillionなども、 単純に最後のthをつけるだけです。

例を挙げます。

thousand → thousandth
million → millionth
milliquattuortrigintaducentillion → milliquattuortrigintaducentillionth

実行例をあげます。

* (format t "~:R" 1000)
one thousandth

* (format t "~:R" 10000000000)
ten billionth

負数

負数については、単純に最初にminusnegativeをつけます。

例を示します。

[sbcl]

* (format t "~R" -100)
negative one hundred

* (format t "~:R" -100)
negative one hundredth

[ccl]

? (format t "~R" -100)
negative one hundred

? (format t "~:R" -100)
negative one hundredth

[clisp]

> (format t "~R" -100)
minus one hundred

> (format t "~:R" -100)
minus one hundredth

なお、cltl2では序数で負数の場合は、 最後にpreviousを印字するものもあるとのこと。 例えば次の通り。

* (format t "~:R" -4)
fourth previous

以上で整数を英語で表現する説明は終わりです。