fix a subtle bug of integer truncation