Exactly, overflow int multiplication. Even when you are using a double
variable.

On Sat, Jan 2, 2010 at 1:57 PM, Rory O'Conor <[email protected]>wrote:

> sorted
>
> public class MathsBug {
>
>    public static void main(String[] args) {
>        double b = 0.0;
>        b = 1000 * 1000 * 1000;
>        System.out.println("1000 * 1000 * 1000 = "+b);
>        b = b * b;
>        System.out.println("above squared = "+b);
>        b =  1000 * 1000 * 1000 * 1000;
>        System.out.println("1000 * 1000 * 1000 * 1000 = "+b);
>        System.out.println("Surely some mistake!");
>        b =  1000.0 * 1000 * 1000 * 1000;
>        System.out.println("1000.0 * 1000 * 1000 * 1000 = "+b);
>        b =  (double) 1000 * 1000 * 1000 * 1000;
>        System.out.println("(double) 1000 * 1000 * 1000 * 1000 = "+b);
>     }
> }
>
> --
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]<javaprogrammingwithpassion%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to