, s
, [Integer.MIN_VALUE, Integer.MAX_VALUE]
i.e. [-2147483648, 2147483647]
.
, . , .
, result + digit
, :
if (result > limit - digit) // result, limit and digit are positive
, result * radix
, - :
if (result > limit / radix) // result, limit and radix are positive
, , limit = Integer.MAX...
multmin = limit / radix
.
" "?
( ). , , - -2147483648
; 2147483648
, Integer
.
-2147483648
. , "", , :
if (result < limit + digit) // result and limit are negative
if (result < limit / radix) // result and limit are negative
, :
// parseInt("123", 10)
limit: -2147483647 (-Integer.MAX_VALUE)
multmin: -214748364
result: -1
result: -12
result: -123
// parseInt("2147483648", 10)
limit: -2147483647 (-Integer.MAX_VALUE)
multmin: -214748364
result: -2
result: -21
result: -214
result: -2147
result: -21474
result: -214748
result: -2147483
result: -21474836
result: -214748364
result: Overflow (after multiplication, before subtraction)