
I wrote the first version of this code in 1994 as an exercise in using lex
and yacc. It included a -k option that involved a recursive number
terminology invented by Donald Knuth that lets you name incredibly large
numbers, at the expense of being incompresible to humans (except possibly
Knuth himself). The original version can be found in the knuth directory. 
The build produces many complaints from bison because the knuth part (-k)
probably should have been implemented as a recursive descent parser rather
than a yacc parser. 

I revisited this code in 2025, mainly as an exercise in Latin number 
terminology. The -k option has been replaced with a -l option that does
Latin numeration, as in 365 --> trecenti sexaginta quinque. To build
just say

>make

at the shell prompt (>). To practise your Latin numbers, do

>num_to_name -l

and then type whatever natural number you like and hit return. It will print
the Latin words that are equivalent to the number you typed and then wait
for you to type another. Type ^D (the unix end of file) to quit. You could
also type (^C), the unix kill character to quit. 

Contents of this folder

README
knuth
makefile
num_to_name.l
num_to_name.lex.c
num_to_name.tab.h
num_to_name.y
test.txt

The file test.txt can be used to
produce a large set of Latin examples. To create the set of examples in a
file named foo, give the command ./num_to_name -l < test.txt > foo at
the shell prompt in this folder. The remaining files contain source code.  
Building the package will generate additional files that can be cleaned up
with the command make clean. (Save the executable num_to_name to some folder
on your $PATH before cleaning up, as it will be removed.)

In English mode the program handles numbers less than 1 undecillion, or 
1 followed by 36 zeros in the American nomenclature. Since the mid 1800s 
standard English nomenclature continues on to the centillions. 1 centillion
is 1 followed by 303 zeros in the American nomenclature. (Europeans 
understand these very large numbers somewhat differently.) 

In Latin mode the program handles numbers less than or equal to 40,000,000,000.
The reason is that I was told by a reader of Reddit r/latin that the
indicated number is the largest ever to appear in classical Latin. (He said
it appears in the writings of the Roman historian Suetonius, who was born
around 69 C.E. It would be misleading for the program to claim to "translate"
numbers that never actually existed in classical Latin. 

My Latin translation is based on the text by Allyn and Greenough (1903).  

Here is the paradigm I am assuming for the latin translation. Let x be
the number to be translated and use integer arithmetic:

x = 0: name(x) is empty since the Romans had no number 0.

0 < x < 1000:  name(x) is well-known and standard. See, e.g., Allen
and Greenough. 

1000<= x < 2000:  name(x) = mille name(x - 1000)

2000 <= x < 100,000: name(x) = name(x/1000) milia name(x%1000)

x = 100,000: name(x) = centum milia ("One hundred thousands, so the noun 
form of 100 is used here)

100,000 < x < 199,999: name(x) = centena milia name(x-100,000). In this
range we switch to the adjective form of 100.

200,000 <= x < 1,000,000: name(x) = name(x/100,000) centena milia 
name(x % 100,000).

Numbers 1 million and above were rarely needed and almost always referred
to amounts of money. Allen and Greenough say that they switched to a 
"multiplier" system, using an initial numerical adverb or adverbial phrase.
Thus, for example, 1 million could be expressed as deciens centena milia, 
since deciens (an adverb) literally means "ten times." They provide only
two additional examples to illustrate the possibilities (see page 123):

3,300,000 = ter et triciens centena milia, or literally "three and thirty times
100,000.) 

2,700,000,000 = vicies ac septies milies centena milia. 
 
(The final n in these adjectives is optional).

In the first example, the et appears to be essential. ter triciens centena 
milia would mean 3 times 30 times 100,000, or 9,000,000.  As for the
second example, ac is short for atque, which is essentially identical in 
meaning to et. Milies is defined on the list of adverbs on page 122 as 
meaning "one thousand times", so the latin literally means 27x1000x100000. 

Since 9,000,000 could also be expressed as nonagiens centena milia, it seems
that the nomenclature for these larger numbers is not unique. For this 
reason, we have decided to abandon our project at the end of the millions,
and to freely use et. Thus, for example, 356,000,235 would be
trecentiens et quinquagiens et sexiens centena milia ducenti trigenta quinque.

Vale! 

