mdbtxt1
mdbtxt2
Proceed to Safety

Hypercalc — The Calculator That Doesn't Overflow    

Hypercalc is an open-source interpreted calculator program designed to calculate extremely large numbers (such as your phone number raised to the power of the factorial of the Gross world product) without overflowing.

It stores and manipulates numbers using a level-index format; as such it can go far beyond the limits of bc, dc, MACSYMA/maxima, Mathematica and Maple, all of which use a bigint library. For example, Hypercalc can tell you whether 128481024 is larger than 888888.

get perl source code here

or

use HyperCalc from your browser

Contents

Overview: Versions and Features

Background: Avoiding Overflow

Perl Hypercalc

HyperCalc JavaScript by Kenny TM~ Chan

Non-Intuitive Results When Working With Huge Numbers


Overview: Versions and Features

There have been three manifestations of Hypercalc:

All versions of Hypercalc use an internal representation similar to level-index.

The Perl and JavaScript versions provide command history (input and result substitution, as in Maxima). Other features vary as follows:

Features Perl Hypercalc HyperCalc JavaScript
User-defined variables YES YES
User-defined functions (use BASIC) YES
Re-use input and output expressions (command history) YES YES
Compatible with all hardware no YES (use a web browser)
Maximum precision 300 digits 16 digits
Fully programmable YES no
Uncertainty (example: 100(4)+20(3) = 120(7) ) YES no
Base-60 input and output (example: 1:20:32 + 5:39 = 1:26:11) YES no

The Perl and JavaScript versions are made available under a free (libre) GPL license, but with no warranty or support.


Background: Avoiding Overflow

The primary advantage of Hypercalc is that it does not "overflow": for large numbers, its range is far greater than hand-held calculators, calculator apps for phones, numeric libraries like gmp, or maths software like Mathematica. Here is a brief comparison (more on my floating-point formats page):

name year maximum value
Early scientific calculators (e.g. TI SR-50) 1974 9.99×1099
IEEE 754 binary64 1985 1.80×10308
High-end scientific calculators (e.g. TI-89) 1990s 9.99×10999
PARI/GP 1985 4.3×102525222
Mathematica 1988 1.44×10323228010
Maple 1980 1.0×102147483646
GMP library (assuming 'long' is 64 bits) 1991 101.777×1020
Maxima 1982 ≈ 101010000000000 = 10↑↑4
Hypercalc 1998 10↑↑(1010)

I began exploring very large numbers such as 265536 in the early 1970's using a Texas Instruments SR-50 calculator, and had to manually take logarithms, extract fractional parts and compute mantissas, etc. I made my own BIGNUM library in assembly language for the Apple II, and again on later machines. Such an approach is limited by computer memory (on my Large Numbers page I refer to this as the class-2 limit).

I always wanted a portable calculator that could do my huge-numbers problems, and the Palm Pilot was the first device that really made this possible. I created the Palm OS HyperCalc in October 1998, and got it working within about a week.

The screen on my Pilot cracked, and I could see that the platform wouldn't last too long. More importantly, I wanted to be able to copy and paste numbers and results to other files while working on my web pages. So I created the vastly more powerful Perl version in the summer of 1999. I have maintained and expanded it greatly over the years, adding extended precision (up to 295 digits) later in 1999, the BASIC interpreter late in 2005, base-60 formatting in late 2007, uncertainty calculation in 2011, and so on.

In 2004, Kenny TM~ Chan, at the time a member of the maths club at Yuen Long Merchants Association secondary school (元朗商會中學) in Hong Kong, found Hypercalc and implemented the JavaScript version. This version is described briefly in its own section below.


Hypercalc Perl

The Perl version is the latest and most capable version. The source code is here.

Here is a sample interaction session:

Hypercalc is distributed under the terms and conditions of the GNU General Public License, version 2, June 1991. Type 'help gpl' at the Hypercalc prompt for details.    Go ahead -- just TRY to make me overflow! _ _ |_| . . ._ _ ._ _ ._ | _ | | | | | ) (-` | ( ,-| | ( ~ ~ 7 |~ ~' ~ ~ `~` ~ ~ -' mrob.com/hypercalc    Enter expressions, or type 'help' for help.       C1 = 27^86!    R1 = 10 ^ ( 3.4677786443013 x 10 ^ 130 )    C2 = scale=50 Note: For all values less than 23, factorial will give only 31 digits of accuracy; and for values less than 136.032, it will give fewer than the requested 50 digits.    C2 = c1 C1: 27^86! C2: (27^86!)    R2 = 10 ^ ( 3.4677786443012627135848832197820460548430862081954 x 10 ^ 130 )    C3 =

There is extensive built-in help, accessed by typing help at the Hypercalc prompt. After an initial introductory help page, just hit enter repeatedly to see help on ten specific topics.


HyperCalc JavaScript by Kenny TM~ Chan

To use HyperCalc from your web browser, go here: HyperCalc JavaScript. There is a detailed manual in PDF format: HyperCalc JavaScript manual


Non-Intuitive Results When Working With Huge Numbers

If you spend a while exploring the ranges of huge numbers HyperCalc can handle, you will probably start noticing some paradoxical results and might even start to think the calculator is giving wrong answers.

For example, try calculating 27 to the power of googolplex (a googolplex is 10 to the power of googol and a googol is 10100). Try:

27^(10^(10^100))

and Hypercalc gives:

10^(10^(1 x 10^100))

It appears that it thinks that

27^(10^(10^100)) = 10^(10^(10^100))

This is clearly wrong — and it doesn't even seem to be a good approximation. What's going on?

Let's try calculating the correct answer ourselves. We need to express the answer as 10 to the power of 10 to the power of something, because that's the standard format the calculator is using, and we're going to see how much of an error it made. So, we want to compute

271010100

as a "tower" of powers of 10. The first step is express the power of 27 as a power of 10 with a product in the exponent, using the formula xy = 10(log(x) . y) :

271010100 = 10(log1027 . 1010100)

log1027 is about 1.43, so we have

271010100 = 101.43 . 1010100

Now we have a base of 10 but the exponent still needs work. The next step is to express the product as a sum in the next-higher exponent; this time the formula we use is x . y = 10(log(x) + log(y)) :

101.43 . 1010100 = 1010(log101.43 + 10100)

log101.43 is about 0.155, and if we add this to 10100 we get

1010(0.155 + 10100) = 10101000...000.155
           = 1010(1.000...000155 . 10100)

where there are 94 more 0's in place of each of the "...". So our final answer is:

271010100 = 1010(1.000...000155 . 10100)

Now that we've expressed the value of 27^googolplex precisely enough to see the calculator's error — and look how small the error is! The calculator would need to have at least 104 digits of precision to be able to handle the value "1.000...000155" — but it only has 16 digits of precision. Those 16 digits are taken up by the 1 and the first fifteen 0's — so when the calculator gets to the step where we're adding 0.155 to 1.0.10100, it just rounds off the answer to 1.0×10100 — and produces the answer we saw when we performed the calculation:

10^(10^(1.00 x 10^100)) = 10101.00 × 10100

The original Palm version of Hypercalc had a calculator-like display, a short, wide rectangle giving enough room to show one line of text with about 30 or 40 characters. Given this limited display area, even if it did have the necessary 104 digits of precision, it wouldn't have room to print the whole 104 digits on the screen, so the answer displayed would still look the same.

More to the point, no matter how many digits we try to display, there's always going to be another even bigger number that we won't be able to handle. For example, Hypercalc would need slightly over a million digits of precision to distinguish

2710101000000    from    1010101000000

and if we just add one more 10 to that tower of exponents, all hope of avoiding roundoff is lost!

For more on this issue, see my discussion of the "power tower paradox", and the Class-3 Numbers and Class-4 Numbers sections of my large numbers pages.


Robert Munafo's home pages on AWS    © 1996-2024 Robert P. Munafo.    about    contact
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Details here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2020 Nov 12. s.27