0

Check this code:

    public static void checkBug() {
        int a = 16763383;
        int b = 16763383;

        float myFloat = 222778.0f;
        int myInt = 222778;

        a += myInt;
        b += myFloat;
        System.out.println("A is : " + a + " and B is: " + b);
    }

The result is A is : 16986161 and B is: 16986160

Why this discrepancy? I have been testing with many values of a, b, myFloat and myInt but I could no find any proper explanation why it happens with these particular values. Also, I can execute/compile b += myFloat; but I cannot do it with b = b + myFloat;.

ernirulez
  • 671
  • 1
  • 9
  • 20

0 Answers0