From: Boris Punk on
long l = 9999999999999L;
double f = 0.11111111111D;
double fl = f+l;
System.out.println(fl);

=9.999999999999111E12


Where's the rest of the 0.1111111's ?


From: Lew on
Boris Punk wrote:
> long l =   9999999999999L;
> double f = 0.11111111111D;
> double fl = f+l;
> System.out.println(fl);
>
> =9.999999999999111E12
>
> Where's the rest of the 0.1111111's ?
>

This is a FAQ. Don't they teach numerical analysis at university any
more? What's with the education system these days anyway?

Your answer is here:
<http://docs.sun.com/source/806-3568/ncg_goldberg.html>

--
Lew

From: Joshua Cranmer on
On 07/07/2010 12:37 PM, Boris Punk wrote:
> long l = 9999999999999L;
> double f = 0.11111111111D;
> double fl = f+l;
> System.out.println(fl);
>
> =9.999999999999111E12
>
>
> Where's the rest of the 0.1111111's ?

Double has a 53-bit mantissa, which corresponds to around 15 decimal
digits of precision.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
From: Eric Sosman on
On 7/7/2010 12:37 PM, Boris Punk wrote:
> long l = 9999999999999L;
> double f = 0.11111111111D;
> double fl = f+l;
> System.out.println(fl);
>
> =9.999999999999111E12
>
>
> Where's the rest of the 0.1111111's ?


double f1 = 1;
double f9 = 9;
double fq = f1 / f9;
System.out.println(fq);

0.1111111111111111

Where's the rest of the 0.1111111's ?

(Answer: They went where your missing 1's went.)

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Mayeul on
Lew wrote:
> Boris Punk wrote:
>> long l = 9999999999999L;
>> double f = 0.11111111111D;
>> double fl = f+l;
>> System.out.println(fl);
>>
>> =9.999999999999111E12
>>
>> Where's the rest of the 0.1111111's ?
>>
>
> This is a FAQ. Don't they teach numerical analysis at university any
> more? What's with the education system these days anyway?
>
> Your answer is here:
> <http://docs.sun.com/source/806-3568/ncg_goldberg.html>

Come on, if that did not lead to horribly broken code out in production,
it would be a great IT achievement that you can produce new programs
that work, without understanding what you're programming.

--
Mayeul