Prev: Possible easy diagnostic outputting from multiple threads tothe one text frame
Next: JDK 1.6.0_21 released
From: Boris Punk on 7 Jul 2010 12:37 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 7 Jul 2010 12:58 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 7 Jul 2010 13:06 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 7 Jul 2010 13:31 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 7 Jul 2010 13:48
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 |