Java Integer.MAX_VALUE and Integer.MIN_VALUE

Following code

BigInteger number=new BigInteger("2154789654785210095153123254756845");
boolean b=number.longValue()>Long.MIN_VALUE;
boolean c=number.longValue()<Long.MAX_VALUE;
boolean d=number.longValue()>=Integer.MIN_VALUE;
boolean e=number.longValue()<=Integer.MAX_VALUE;
System.out.println(""+b);
System.out.println(""+c);
System.out.println(""+d);
System.out.println(""+e);

generates output

true
true
false
true

Remembering that after reaching MAX_VALUEInteger, the value returns to MIN_VALUEand again the loop, if the value <=Integer.MAX_VALUE, then it should be >=Integer.MIN_VALUE, then why does the boolean dreturn false?

+4
source share
3 answers

This can be explained when we understand what is returning longValue().

BigInteger . long int, 5.1.3 Java β„’: BigInteger , , 64 . , BigInteger, .

-4694333933485660691 , , , long, , Integer.MIN_VALUE ( long), false d.

b c true, -4694333933485660691 , Long.MIN_VALUE, -4694333933485660691 Long.MAX_VALUE. , false b c, BigInteger, Long.MIN_VALUE AND Long.MAX_VALUE, longValue().

+12

,

number.longValue()[-4694333933485660691]>Long.MIN_VALUE[-9223372036854775808  =  true
number.longValue()[-4694333933485660691]<Long.MAX_VALUE[9223372036854775807  =  true
number.longValue()[-4694333933485660691]>=Integer.MIN_VALUE[-9223372036854775808  =  false
number.longValue()[-4694333933485660691]<=Integer.MAX_VALUE[9223372036854775807  =  true

,

0

Java 1.8 BigInteger.longValueExact(), ArithmeticException, BigInteger .

0

All Articles