Testing, coding, in that order.

Know your (large) numbers

Spread the love

As a child, I was fascinated by large numbers. I recall being unbelievably excited when my dad gave me a clipping of a newspaper trivia column which listed the names of numbers from a million up to decillion. While most of us had some practical knowledge of millions, billions, and trillions, the numbers beyond that were far more obscure. It felt good to be privy to even a small part of the arcana of numerical nomenclature.

Not long after that, I stumbled upon a list of large numbers up to vigintillion in the phone book-sized dictionary in my elementary school classroom. This was incredible! Now I could give precise names to any number up to about 1065. Still, knowing that there were numbers even bigger than that, I was not satisfied.

Much later, I was able to turn to the internet to resolve many previous research roadblocks. There I found references to far larger numbers using extensions to the established Latin-based conventions — trigintillion, quadragintillion, and so on. By then, the early magic had faded, yet my idle curiosity about large numbers never quite went away. In fact, one of the first programs I wrote while learning C# was a “numbers to words” converter which supported thousands of digits.

Since I’m feeling nostalgic, let’s recreate that program now! First the boilerplate to read the number (as a string — since we will quickly shoot past the limit of a primitive integral type) and handle cases like negative and zero:

We’ve laid the groundwork here to separate the number into groups of digits and then name each group. Right now, though, it simply calls every number “zero.” Let’s extend this to name every number up to 999,999 — what I’ll call the “small numbers.”

To name small numbers in English, we need to know only a few dozen unique words and a few rules, to be applied in digit groupings of three. So, we end up with the single digits, the numbers for the multiples of 10 up to 90, the special cases for 11-19, and the suffixes for 100 and 1000. We combine names of 1000s, 100s, 10s and digits to build up the word in groups, omitting any portion if it is zero (since we don’t say “two thousand zero hundred” for 2000). Add to that the one orthographical peculiarity where we hyphenate 10s names like “twenty-one” and we have a complete algorithm:

This is a start, but remember that we’re talking about large numbers here! The program so far will name every grouping “thousand” so we need to teach it the rules of big numbers. Above I summarized what are sometimes called “dictionary numbers” containing the names from million up to vigintillion. The extension to this system by Conway and Guy is explained fairly well by Sbiis.ExE (whose large numbers journey bears more than a passing similarity to my own). But basically, it uses the dictionary numbers as a starting point, and extrapolates Latin names for the units, tens, and hundreds places of ever larger number groups. For example, 1039 = 103N+3 where N=12, which gives us duodecillion — the ones portion is duo = 2 and the tens portion is deci = 10. Similarly, for 101002, N=333, or tre (3) + triginti (30) + trecent(i) (300) + illion (note that we drop the last vowel before adding the -illion suffix).

Now for the changes to make the program observe these rules. First, we need to edit the Group function to handle the big suffixes: