How to keep max_value maximum value equal to 2 ^ 31 - 1?
This is actually not the case. The value of f is 2147483648 .
However, narrowing down the primitive conversion from float to int clamps the value. He gets to this part:
This can be easily seen by making the number even larger:
float f = Integer.MAX_VALUE; f = f * 1000; System.out.println(Integer.MAX_VALUE);
Or by clicking on long instead, which obviously does not need to be clamped at the same point:
float f = Integer.MAX_VALUE; System.out.println(Integer.MAX_VALUE);
source share