Home static Java Programming [Archive] - FP value
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - FP value
 This topic has 11 replies on 1 page.

Posts:236
Registered: 5/11/04
FP value
Aug 5, 2004 7:14 PM

double has 15-17 decimal digit precision..

how can I know then the number of precision of a specified double value?

say, 1.23e21 or 1.0

thanks.

Posts:37,103
Registered: 3/30/99
Re: FP value
Aug 5, 2004 7:27 PM (reply 1 of 11)

Huh?

Posts:236
Registered: 5/11/04
Re: FP value
Aug 5, 2004 7:36 PM (reply 2 of 11)

sorry, i've confused even myself :-(

thanks.

Posts:236
Registered: 5/11/04
Re: FP value
Aug 5, 2004 8:55 PM (reply 3 of 11)

any or explanation or good link explaining how double can go upto 17digits of precision only?

thanks

Posts:37,103
Registered: 3/30/99
Re: FP value
Aug 5, 2004 9:54 PM (reply 4 of 11)

any or explanation or good link explaining how double
can go upto 17digits of precision only?

thanks

Not sure exactly how it works in Java/IEEE land, but in a general (albeit imprecisely explained) mathematical sense...

A double has 64 bits--64 binary digits--of precision. 2 raised to the power 3.something is 10, so divide 64 by 3.something to tell you how many base-10 digits will represent the same range of numbers as 64 base-2 digits (bits).

Back in the Java/IEEE world, it may not come out to exactly 17, and I can only assume the missing digit or two is some byproduct of the details of the conversion rules.

Posts:37,103
Registered: 3/30/99
Re: FP value
Aug 5, 2004 10:00 PM (reply 5 of 11)

In other words, you've got 64 binary digits, and you can only hold so much information in those digits. When you convert that to base-10, each base-10 digit contains about 3 times as much information as a binary digit, so you only need about a thrid as many digits to represent that same information. Adding more ase-10 digits wouldn't change anything, because you only have whatever information you started with in the 64 bits.

Posts:236
Registered: 5/11/04
Re: FP value
Aug 5, 2004 10:24 PM (reply 6 of 11)

In other words, you've got 64 binary digits, and you can only hold so much information in those digits.
When you convert that to base-10, each base-10 digit contains about 3 times as much information as a
binary digit, so you only need about a thrid as many digits to represent that same information. Adding ]
more ase-10 digits wouldn't change anything, because you only have whatever information you started
with in the 64 bits.

so, because of this...
when we assign value to a double with more than 17 decimal digits, it will be rounded off?

say, a value of 0.09999999999999999999; becomes "0.1"?

thank you so much.

Posts:10,967
Registered: 4/7/01
Re: FP value
Aug 5, 2004 11:48 PM (reply 7 of 11)

A double consists of 64 bits, numbered 63..62....1..0. The format of a Java double is per the IEEE 754 double precision format, which allows for a sign, a mantissa, and an exponent - a number like +/- mmmm**eeeee (where ** means exponent)

bit 63 is the sign bit
bits 62 - 52 (11) are the exponent
bits 51 - 0 (52) are the mantissa (which is the "significant digits" portion

The maximum value that the mantissa can have is therefore 2**52, or 4.503599627... times 10**15. (which is between 15 and 16 significant digits)

In addition, there is stuff done internally that eventually results in 15.95 decimal digit precision (I had to look this number up!) Search for IEEE 754 precision for all of the dirty details - it is somewhat interesting, and not too obtuse.

Posts:236
Registered: 5/11/04
Re: FP value
Aug 6, 2004 12:13 AM (reply 8 of 11)

A double consists of 64 bits, numbered 63..62....1..0. The format of a Java double is per the IEEE 754
double precision format, which allows for a sign, a mantissa, and an exponent - a number like +/-
mmmm**eeeee (where ** means exponent)

bit 63 is the sign bit
bits 62 - 52 (11) are the exponent
bits 51 - 0 (52) are the mantissa (which is the "significant digits" portion

The maximum value that the mantissa can have is therefore 2**52, or 4.503599627... times 10**15.
(which is between 15 and 16 significant digits)

thank you.

In addition, there is stuff done internally that eventually results in 15.95 decimal digit precision (I had to
look this number up!)

sorry, i made you look it up :-)

Search for IEEE 754 precision for all of the dirty details - it is somewhat >>interesting, and not too >>obtuse.
yes, really not that simple.

so, because of that number of decimal digit precision limitation, this code: (which i posted so couple of times already)

double d1 = 0.09999999999999999999999;
System.out.println(d1);

results into "0.1" string and not the actual "0.09999999999999999999999"?

thanks

Posts:668
Registered: 9/2/03
Re: FP value
Aug 6, 2004 1:51 AM (reply 9 of 11)

sorry, i've confused even myself :-(
never mind. i'll try to ask when i can ask what i

Posts:236
Registered: 5/11/04
Re: FP value
Aug 6, 2004 1:54 AM (reply 10 of 11)

Posts:37,103
Registered: 3/30/99
Re: FP value
Aug 6, 2004 7:08 AM (reply 11 of 11)

so, because of that number of decimal digit precision
limitation, this code: (which i posted so couple of

double d1 = 0.09999999999999999999999;
System.out.println(d1);

results into "0.1" string and not the actual
"0.09999999999999999999999"?

Are you asking if it becomes 0.1, or are you asking if the precision limits are why it becomes 0.1?

If it's "if" then just write the code and try it. I would assume it either becomes 0.1, or the compiler will complain about you trying to use more digits than the language can handle.

If it does in fact become 0.1, then, yes, obviously the reason why must be that you're asking it to store more digits than it's capable of, so it has to round.

 This topic has 11 replies on 1 page.