You need compare the result with one summand to detect overflow.

See here: https://play.golang.org/p/3Uh0eFSbQW

Programming languages usually don't provide access to machine level flags, 
because they support combining multiple operations in one expression. For 
example what should the carry flag represent in an expression y = a + b + 
c. There are several strategies to deal with this shortcoming one approach 
is to calculate with 63-bit words and check use the highest bit as carry or 
do additional operations as you are doing.

I recommend to look into Harry S. Warren's book "Hacker's Delight" which 
contains numerous examples how to deal with such issues in a higher level 
language. Here is the web page for the book: http://www.hackersdelight.org/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to