Bear Bibeault wrote:http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Bear Bibeault wrote:BigDecimal
Jay Orsaw wrote:
I have a program that I need to convert a VB single into a Java Float, but the VB uses a different EET??? Standard than Java does... :'(
Jay Orsaw wrote:Why even use them if they have an extreme possibility of messing up... Especially with a JOKE example like this.....
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Henry Wong wrote:
Jay Orsaw wrote:
I have a program that I need to convert a VB single into a Java Float, but the VB uses a different EET??? Standard than Java does... :'(
I thought that Visual Basic uses the same floating point standard as Java -- that is, IEEE 754.
Henry
fred rosenberger wrote:
Jay Orsaw wrote:Why even use them if they have an extreme possibility of messing up... Especially with a JOKE example like this.....
This is a limitation of the hardware - how computers store numbers. It is impossible to accurately store most decimal numbers EXACTLY. For most applications, floats are 'close enough'.
When they are not, you have the option of using a BigDecimal, but that has other limitations.
As with just about everything in programming, there are tradeoffs you make.
Bear Bibeault wrote:Calling it a "joke" is just naive. That's just the nature of fixed-register arithmetic.
Jay Orsaw wrote:
Bear Bibeault wrote:Calling it a "joke" is just naive. That's just the nature of fixed-register arithmetic.
I don't know why it would create an error like that for such an easy problem, but hey if that's how we have to live our float lives....
Henry Wong wrote:
Jay Orsaw wrote:
Bear Bibeault wrote:Calling it a "joke" is just naive. That's just the nature of fixed-register arithmetic.
I don't know why it would create an error like that for such an easy problem, but hey if that's how we have to live our float lives....
That depends on what you would call "an easy problem". For example, can you give us an exact answer to what is one divided by three? After all, 0.333333333 isn't very accurate is it? Why can't do give an exact answer for something as easy as one divided by three?
The problem is that you judge everything from your world of base 10 arithmetic. For floating point, your decimals are base ten, and times TEN, to an exponent that is also base ten. For the computer (and the IEEE definition), it is based two, and times TWO, to an exponent that is also base two. What seems easy to you, and what seems like it will need to be rounded off, are not necessarily the same as what seems easy and needs to be rounded off to the IEEE standard.
Also, while 32 bits sounds like lots of storage -- remember that a floating point number contains two numbers, a mantissa and an exponent, which must share the 32 bit space. A 32 bit floating point number has much less precision than a 32 bit integer.
Henry
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |