jdk 소스에서 정수의 parseInt (String str, int radix) 알고리즘에 대한 몇 가지 질문이 있습니다. 아래 코드 소스를 참조하십시오.왜 Integer.paseInt() 알고리즘이 결국 sun에서 부정적인 결과를 산출합니까 jdk
multmin = limit/radix;
while (i < len) {
// Accumulating negatively avoids surprises near MAX_VALUE
digit = Character.digit(s.charAt(i++),radix);
if (digit < 0) {
throw NumberFormatException.forInputString(s);
}
if (result < multmin) {
throw NumberFormatException.forInputString(s);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forInputString(s);
}
result -= digit;
}
이 결과 이유 - = 자리보다는 결과 + = 자리? 나는 혼란 스럽다.
'네거티브를 반환합니까? 결과 : -result;'인용 한 스 니펫 아래 두 줄 정도? –
'누적 적으로 누적되면 MAX_VALUE 부근에서 놀라움을 피할 수 있으십니까?' – EJP
그래서 num이 음수 일 때, limitable은 Integer.MIN_VALUE이고 num은 양수이고, varaiable은 -Integer.MAX_VALUE입니다. 왜? 혼란 스럽습니다. 알고리즘 또는 일부 기사의 링크를 지정할 수 있습니까? –