소스 검색

math: fix a signed integer overflow issue in the fast factorial

computation function.
legacy
Sam Hocevar sam 13 년 전
부모
커밋
4678b4cb75
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. +3
    -3
      src/math/real.cpp

+ 3
- 3
src/math/real.cpp 파일 보기

@@ -763,10 +763,10 @@ template<> real pow(real const &x, real const &y)
} }
} }


static real fast_fact(int x)
static real fast_fact(unsigned int x)
{ {
real ret = real::R_1(); real ret = real::R_1();
int i = 1, multiplier = 1, exponent = 0;
unsigned int i = 1, multiplier = 1, exponent = 0;


for (;;) for (;;)
{ {
@@ -774,7 +774,7 @@ static real fast_fact(int x)
/* Multiplication is a no-op if multiplier == 1 */ /* Multiplication is a no-op if multiplier == 1 */
return ldexp(ret * multiplier, exponent); return ldexp(ret * multiplier, exponent);


int tmp = i;
unsigned int tmp = i;
while ((tmp & 1) == 0) while ((tmp & 1) == 0)
{ {
tmp >>= 1; tmp >>= 1;


불러오는 중...
취소
저장