Created
May 13, 2015 15:54
-
-
Save edmccard/a7fe5726a25961104068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkOverflow(result, op1, op2 uint8) bool { | |
// (op1 ^ op2) & 0x80: zero if both operands had the same sign bit | |
// (op1 ^ result) & 0x80: non-zero if the result is a different sign | |
// from the operands | |
// So it returns true if either: | |
// both operands are positive but the result is negative | |
// or vice-versa | |
return (((op1 ^ op2) & 0x80) == 0) && (((op1 ^ result) & 0x80) != 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment