I often use a calculator at work. Mostly, I add or subtract lists of simple numbers so I can go back to the calculator tape and quickly compare numbers. (Yes, my job is fulfilling.) Sometimes the calculator’s paper tape shows a much more complex equation than what I put in.
e.g.: 39.49 - 31.99 = 7.500000000000004
FWIW, I am talking about the calculator on the computer.
Why is a simple subtraction problem handled this way?
It’s because the computer represents numbers internally in binary. The only rationals that have a finite-length representation are of the form p/2[sup]n[/sup]; everything else is repeating. Because computers can’t store an infinite number of bits, they have to make an approximation.
Now, you can write a calculator that operates exactly on rational numbers. There is a bit of a difference in speed, but for something like the Windows calculator, it wouldn’t be noticeable. Why did they do it that way? Who knows?
It is just handling the number of significant digits differently than you would like. I doubt it happens when you just add or subtract numbers. That is simple. However, if you mix some multiplication or division in, the program might end up with a long string of digits and just try to keep using them. Instead of wronging numbers to the Nth decimal place, it just keeps that result and that tiny fraction can pop up later when you do another operation.
You may be able to set the caluculator (what program is it) so that it rounds numbers automatically and you don’t have to worry about it. It is really just a display problem. The fact that the extra digits are there should not have an adverse impact on your results.
Actually, I don’t mix multiplication and Division in with the addition and subtraction. Here’s another example I just put in all by itself.
118.1 - 116.75 = 1.349999999999994
There is obviously a fractional part of each number…
There is no real problem, just curiosity. In fact, the “display,” just the part you would normally look at if you used a calculator to figure a problem, shows the correct number with the correct number of significant digits. I use the list of numbers so I have a “paper tape” which is a seperate window that prints out each calculation like an adding machine would.
I’ll risk my ego here a little and ask a stupid question; why doesn’t this happen with the actual adding machine I have or the calculator that sits beside the computer?
To expand on what ultrafilter said, the floating point format that most computers use is incapable of representing a lot of numbers. An n bit binary string is capable of representing 2^n different numbers, but the number of real numbers in any interval is infinite so approximations are needed.
This becomes a problem for some kinds of applications, and comparing floating point numbers must therefore be done indirectly, through use of an epsilon value.
A good basic explanation of what is going on can be found here.
The calculator is probably programmed to be more intelligent about rounding, or at least to swallow the extra digits. The adding machine operates internally in decimal, so it’s not an issue.
I’m far too tired to even attempt the technical descriptions in this thread, floating points, etc. However, I have an idea. To calculate 118.1 - 116.75, type 11810 - 11675, then divide the answer by 100 (or “move the decimal point back to the left”). Would that give you an accurate answer?
Quite honestly, because whoever programmed your calculator program didn’t do a very good job.
The way calculators and good programs work is they store numbers as a certain number of digits (some store more digits than others), and possibly may have an expontent multiplier as well. Simple addition and subtraction ends up corresponding to a bunch of integer calculations inside the cpu (calculators and computers both have cpu’s). Storing numbers as a floating point value limits you to the precision of a floating point in the computer, which isn’t all that great and also leads to more weird rounding errors like what you are seeing.
The reason the programmer used floating point was just so he/she could take advantage of the processor’s natural floating point ability. This saved them the effort of writing arithmetic processing routines, which they were either too lazy to do themselves or didn’t know how to do. Or maybe their boss gave them too tight of a deadline and they decided to cut corners. Who knows.
Are you using a calculator or an adding machine. Eitherway, check to see what the decimal is set at. If you’re dealing with money, it should be set to 2, you might have it on F.
Just to help confuse things further you need to pay attention to how the calculator does its order of operations. For instance, with Microsoft’s built-in calculator if you enter:
1+2*3=9
If you use the Scientific version of Microsoft’s calculator you get:
1+2*3=7
The Scientific calculator’s answer is the correct one as it waits for the whole equation to be input before generating an answer. The “basic” calculator does the calculation on the string just input each time a function key is hit (so 1+23 becomes 1+2=3, 33=9). The Scientific calculator sees the whole 1+2*3 and correctly applies the order of operations.
I’ve noticed this too, and it bugs the crap outta me.
I have to use four different calculators and each one is different.
On one it’s 4 + 2 - to get 4 - 2 = 2
On another it’s 4 [enter] 2 -
On another it’s the basic 4 - 2 with no = an finally, just 4 - 2 = 2.
Then you bring in the fact that on some, if you don’t hit total or equal or sum or whatever between steps it’s interpreted one way and on others if you do hit some button or another, the damn machine prints out the answer then clears the [buffer so you can’t do other calculations! AARRRGHHH!
I just checked a calculator on Solaris (CDE) and on my cellphone, and they both came out right. Either your calculator program is buggy, or you have some settings screwed up.
Or else you’re running on a Pentium with the FDIV bug. (Sorry, cheap joke.)