Results 1 to 20 of 22
Thread: Double subtraction
- 04-21-2011, 02:39 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
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."
Help please!
- 04-21-2011, 02:53 AM #2
- 04-21-2011, 02:58 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
Thanks, but I'm in intro the programming and could use a little simpler explanation.
- 04-21-2011, 03:01 AM #4
2 / 3
Write the answer to that EXACTLY in decimal.
- 04-21-2011, 03:04 AM #5
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
OK, I'm not trying to be difficult here, but I still don't get it!
- 04-21-2011, 03:11 AM #6
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 #7
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
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 #8
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 #9
Member
- Join Date
- Apr 2011
- Posts
- 5
- Rep Power
- 0
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 #10
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 #11
Short answer: Since all numbers are represented in binary, some rounding errors occur when you use floating point arithmetic.
Long answer: Read the article!
- 04-21-2011, 03:55 AM #12
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
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 #13
- 04-21-2011, 04:16 AM #14
*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 #15
Don't waste your time. OP has moved on to pollute another forum.
Addition of doubles (newbie question)
- 04-21-2011, 04:38 AM #16
Well he did get mad that you were treating him as if he understood this.
- 04-21-2011, 04:42 AM #17
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 #18
But most likely he didn't understand the article because of some potentially confusing words.
Thanks, but I'm in intro the programming and could use a little simpler explanation.
- 04-21-2011, 04:51 AM #19
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 #20
Grrrrrr...
I just felt a little pity for the guy, as he is a n00b, ignoring the offensive language part.Last edited by ra4king; 04-21-2011 at 04:56 AM.
Similar Threads
-
unexpected type on a subtraction sign?
By JanieRae in forum New To JavaReplies: 5Last Post: 04-22-2010, 04:09 AM -
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
date subtraction
By silversurfer2in in forum New To JavaReplies: 6Last Post: 02-12-2010, 02:51 PM -
non-static method add(double,double) cannot be referenced from a static context
By cravi85 in forum Java SoftwareReplies: 5Last Post: 03-21-2009, 09:32 PM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM


LinkBack URL
About LinkBacks


Bookmarks