java - Any trap which we should beware of Integer.MIN_VALUE == -Integer.MIN_VALUE == Math.abs(Integer.MIN_VALUE) -
i realize below code holds true
integer.min_value == -integer.min_value == math.abs(integer.min_value)
this because when negate -2147483648
, should become +2147483648
. since maximum positive integer can represented in java +2147483647
, integer overflow occur. when overflow occur, becomes -2147483648
again.
i wondering, is there trap should keep eye on it, above situation?
the biggest trap slient overflow of example.
similar examples.
long.min_value == -long.min_value; 0.0d == -0.0d 0.0f == -0.0f double.nan != double.nan float.nan != float.nan double.compare(double.nan, 0) == 1 double.nan > 0 false float.compare(float.nan, 0) == 1 float.nan > 0 false
fyi
byte.min_value != -byte.min_value; short.min_value != -short.min_value; character.min_value == -character.min_value;
Comments
Post a Comment