Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.401 :

Posted: Mon Jul 07, 2014 3:22 am
by kannattaa
The following code snippet will print 'true'.

Code: Select all

        float f = Integer.MIN_VALUE;
        int i = (int) f;
        System.out.println( i == Integer.MIN_VALUE);
seems to be a better question.

The fact of the matter is that Integer.MIN_VALUE = (-1) * 2 ^ 31.
So it can be converted to binary, normalized and loss-free represented in IEEE-754 binary32 format as 11001111000000000000000000000000

The problem of Integer.MAX_VALUE is that it requires not obvious loosly convertion and normalization to (1)*2^31 = (Integer.MAX_VALUE + 1) and vice versa.

Is the original question(with Integer.MAX_VALUE) really captured from exam and focused on the details of loosly conversion?
(f.e. the trick won't come out with Integer.MAX_VALUE / 2)

Re: About Question com.enthuware.ets.scjp.v6.2.401 :

Posted: Mon Jul 07, 2014 7:48 am
by admin
Well, the objective of the question is to sensitize the reader about the implications of using a float. You may not get the exact question on the exam but you may get question that depends on you knowing that float doesn't store precise integers.

HTH,
Paul.