CALC: The Calculator That Keeps Its Working
A number on its own is not much use. What anybody is actually stuck on is how the number was arrived at, and a calculator that shows one digit and forgets the rest cannot help with that. This is a tape: every line stays, every line can be edited, and everything below it works itself out again. The arithmetic is done in decimal rather than in binary floating point, so a column of pennies adds up to pennies.
The tape
Every line is an expression you can go back to. Change one and everything below it works itself out again. Enter starts a new line, the up and down arrows move between them, and backspace on an empty line takes it away.
- Running total
- 0
What it understands
Every one of these puts itself on the tape if you press it.
Money that does not drift
Addition and subtraction keep the decimal places you typed, so a column of pennies adds up to pennies.
Percentages the way people say them
A percentage after a plus or a minus is a percentage of the thing on the left. On its own it is the fraction it stands for.
Lines with names
Give a line a name and use the name below it. A named line stays out of the running total, so intermediate working does not get counted twice.
Units
Length, mass, volume, temperature, data and time. The word to converts whatever the line has worked out so far.
The units it knows
Length mm cm m km in ft yd mi nmi um nm
Mass mg g kg t oz lb st ton longton
Volume ml cl dl l m3 cm3 tsp tbsp floz cup pt qt gal impfloz imppt impgal
Temperature C F K
Data bit B kB MB GB TB PB KiB MiB GiB TiB kbit Mbit Gbit
Time ms s min h d wk mo yr
Long spellings work too: inches, kilograms, minutes. A line beginning with # is a note and is not worked out.
A figure can be written 1,234.50 or 1.2345e3, and a minus sign, a multiplication sign or a space pasted out of a document is read as the one you meant. A comma has to group in threes: 1,5 is refused rather than read as fifteen.
What this is, and what it is not
The arithmetic is decimal, not binary. 0.1 + 0.2 is 0.30000000000000004 in the floating point every browser calculates in, because neither 0.1 nor 0.2 can be written exactly in binary. Every figure here is instead a string of digits and a count of decimal places, added, multiplied and divided the way it is done on paper. A hundred lines of 0.01 come to 1.00, not to 0.9999999999999999, and the coefficient can be any length, so a year of transactions in pence does not run out of precision at the sixteenth digit.
Addition keeps your decimal places; multiplication does not. Add 0.10 to 0.20 and the answer is 0.30, because a column of pennies should stay a column of pennies. Multiply 120 by 1.5 and the answer is 180, not 180.0, because the trailing zero is arithmetic noise rather than a penny. Division is worked to twelve decimal places and rounded half up, the rounding every tax table is written in, with the trailing zeros taken off.
A name that does not exist stops the line. Write subtotal + vat with no line called vat above it and that line says so instead of quietly treating the missing name as zero. An answer that looks like an answer and is not one is the only failure a calculator can have that nobody catches.
The unit factors are the legal definitions, not approximations. The inch is exactly 25.4 mm and the pound exactly 0.45359237 kg, both from the international yard and pound agreement of 1959. The US gallon is exactly 231 cubic inches and the imperial gallon exactly 4.54609 litres. Because those are exact decimals and the arithmetic is decimal, 12 in to cm is 30.48 and not 30.479999999999997. Where a conversion genuinely does not come out exactly, such as kilograms to pounds, it is rounded at the twelfth decimal place and the source of every constant is written in the comments of the page's own script.
GB means a thousand million bytes here. kB, MB and GB are powers of a thousand and KiB, MiB and GiB are powers of 1024, which is IEC 80000-13. A drive is sold in the first and reported by most operating systems in the second, and the gap between them is the whole of the space that seems to go missing on a new disk. Convert between the two families and you can see exactly how much.
There is no currency conversion, and there will not be. A rate has to come from somewhere, and asking for one would mean telling a server what you are converting and when. Everything on this page is worked out in your own browser with the network off, which is only possible because nothing here needs a number it does not already have.
It is not a spreadsheet and it is not a programming language. There are no functions, no square roots and no trigonometry, because those cannot be done exactly in decimal and a calculator that is exact everywhere except in the places it quietly is not would be worse than one that says no. Powers are whole numbers only. If you need a grid, SHEETS is next door.
Questions people ask
Why does 0.1 + 0.2 come out wrong everywhere else?
Because computers hold fractions in binary, and 0.1 in binary is a recurring fraction in the same way a third is in decimal. It gets cut off at 53 bits, so the stored number is very slightly more than a tenth, and adding two of those shows the error at the seventeenth digit. Money arithmetic done that way drifts by a penny over enough lines and nobody can see where the penny went. This page never converts your figures to binary at all.
How do I use one line's answer in another?
Name it. Write subtotal = 120 * 3 and then use subtotal anywhere below that line. Names are one word of letters, digits and underscores. There is also prev, which is whatever the line directly above worked out, for when naming it would be more ceremony than it is worth. A name is allowed to be the same word as a unit, because a line called days or hours is a far more ordinary thing to want than the word days spelled out as a unit; the name wins from that line down, and any line that then tries to use it as a unit says so.
What goes into the running total?
Every line that is a plain number and has not been given a name. That is the rule that makes a tape usable: your working lines get names and stay out of the total, and the lines you actually want added up are the bare ones. A line with a unit on it is left out too, since adding kilograms to gigabytes would be a nonsense.
What does 120 + 15% actually do?
It gives 138. The percentage is taken of the number on the left, which is what a person means when they say add fifteen percent, and what a pocket calculator with a % key does. 120 - 15% is 102 for the same reason. On its own, 15% is 0.15.
Why will it not add 20 C to 30 C?
Because a temperature in Celsius or Fahrenheit is a point on a scale rather than an amount of something, so adding two of them is meaningless in a way that adding two lengths is not. Twenty degrees plus thirty degrees is not fifty degrees of anything. Conversion between the three scales works normally.
Is anything sent anywhere?
No. The page loads its own script and nothing else, works with the network switched off, and keeps the tape in this browser's local storage under one key. Clear the tape, or clear the site's data in your browser, and it is gone.
Can I keep a tape for each job?
Not in one page: there is one tape, kept where you left it. Copy a finished tape out with the copy button and paste it wherever the working belongs, which is usually the thing you were going to have to do anyway.