# Double subtraction

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 04-21-2011, 02:39 AM
bmbishop
Double subtraction
In subtracting one double from another, namely 45.32 - 45.31, I get a result of 0.00999999999999801. According to all the math I've ever learned, the answer should be .01.

I asked my professor about this, and his response was that "45.31 may be a repeating decimal." To which I responded, "I have no idea what that means."

• 04-21-2011, 02:53 AM
DarrylBurke
• 04-21-2011, 02:58 AM
bmbishop
Thanks, but I'm in intro the programming and could use a little simpler explanation.
• 04-21-2011, 03:01 AM
Junky
2 / 3

Write the answer to that EXACTLY in decimal.
• 04-21-2011, 03:04 AM
bmbishop
OK, I'm not trying to be difficult here, but I still don't get it!
• 04-21-2011, 03:11 AM
Junky
the answer is 0.666666666666666666666666666666666666666666666666 66666666666666666666666666666666666666666666666666 66666666666666666666666666666666666666666666666666 6666666666666666666666666666666666666666666

You cannot represent that value accurately in decimal. Guess what happens to some values in binary?
• 04-21-2011, 03:14 AM
bmbishop
I understand that analogy. But 4.11 - 4.10 is .01. The damn calculator says it's so. Can you explain it to me like I'm a complete idiot, which I'm not, but I am just not following you.
• 04-21-2011, 03:21 AM
Junky
The damn calculator cheats. Since not all decimal values can be represented exactly in binary some inaccuracy creeps in. It is a known artifact of floating point arithmetic. All of which is explained in the article linked above if you had bothered to read it. If you did read it and didn't understand then read it again and again and again until you do understand because quite frankly anything I say here is just repeating what that article says. So why should I waste my time?
• 04-21-2011, 03:24 AM
bmbishop
Wow. You are an asshole. I am a new programmer seeking an answer that I can understand. Would anyone else like to help?
• 04-21-2011, 03:27 AM
Junky
Good luck with getting anyone else to explain it.

You have been provided a link
I have given you an explanation
You used offensive language against me which violates the conditions you agreed to when joining this forum.

I doubt very much anyone will waste their time helping an ungrateful idiot like you!
• 04-21-2011, 03:43 AM
OutputStream
Short answer: Since all numbers are represented in binary, some rounding errors occur when you use floating point arithmetic.

• 04-21-2011, 03:55 AM
RichersooN
Your noob programmer cause you easily get angry, many problems still comes along the way if your going to continue to be as programmer.
• 04-21-2011, 04:02 AM
DarrylBurke
Quote:

Originally Posted by bmbishop
Wow. You are an asshole. I am a new programmer seeking an answer that I can understand. Would anyone else like to help?

Abuse reported.

db
• 04-21-2011, 04:16 AM
ra4king
*sigh*
Come on people, let's help him out here. He's still new and probably doesn't even know what binary means or how it works. Why turn him off to programming now?

@bmbishop
As you probably know, computers use a binary system (1's and 0's) to store data, such as values and instructions. Humans use a decimal system. So like 2/3 in decimal is an irrational number, 45.31 is an irrational number in binary, aka, there is no exact representation of 45.31 as 1's and 0's.

Hope that helps :)

(but really, please do not use offensive language, even if you are angry)
• 04-21-2011, 04:34 AM
Junky
Don't waste your time. OP has moved on to pollute another forum.

• 04-21-2011, 04:38 AM
ra4king
Well he did get mad that you were treating him as if he understood this.
• 04-21-2011, 04:42 AM
Junky
No I treated him as a lazy person who expected us to spoonfeed him the answer instead of reading the article. I also didn't apreciate his attitude that because he didn't understand then somehow that was my fault. If I attended a lecture on Quantum Mechanics by Stephen Hawking it would all go over my head. That is my fault not Stephen's.
• 04-21-2011, 04:46 AM
ra4king
But most likely he didn't understand the article because of some potentially confusing words.
Quote:

Thanks, but I'm in intro the programming and could use a little simpler explanation.
• 04-21-2011, 04:51 AM
Junky
I did provide a simpler explanation and the idiot still not understand nor appreciate it.

I'm also done arguing with you!
• 04-21-2011, 04:54 AM
ra4king
Grrrrrr...

I just felt a little pity for the guy, as he is a n00b, ignoring the offensive language part.
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last