Use APInt arithmetic, fixed typo. Thanks to Benjamin Kramer for noticing that.