Re: Is it possible to catch overflow in long long multiply ?

2005-06-03 Thread Bradley Lucier
This is the wrong list to ask such a question, but I'll answer it anyway since the answer might be of general interest. There is a wonderful book Hacker's Delight by Henry S. Warren Jr., http://www.awprofessional.com/bookstore/product.asp? isbn=0201914654redir=1rl=1 In some ways it can be

Re: Is it possible to catch overflow in long long multiply ?

2005-06-03 Thread Geert Bosch
On May 30, 2005, at 02:57, Victor STINNER wrote: I'm using gcc long long type for my calculator. I have to check integer overflow. I'm using sign compare to check overflow, but it doesn't work for 10^16 * 10^4 : 1 * 1 I see your question went unanswered, however I do

Re: Is it possible to catch overflow in long long multiply ?

2005-06-03 Thread Robert Dewar
I definitely think that -fwrapv should be the default for Ada.

Re: Is it possible to catch overflow in long long multiply ?

2005-06-03 Thread Joe Buck
On Fri, Jun 03, 2005 at 03:26:19PM -0400, Bradley Lucier wrote: Assuming that overflow of signed integer arithmetic wraps (and what gcc flag do I have to set to assume this?) then here is the algorithm to multiply x and y with overflow detection. Cast to unsigned; we are guaranteed that

Is it possible to catch overflow in long long multiply ?

2005-05-30 Thread Victor STINNER
Hi, I'm using gcc long long type for my calculator. I have to check integer overflow. I'm using sign compare to check overflow, but it doesn't work for 10^16 * 10^4 : 1 * 1 Here you have my code to check overflow : long long produit = a * b; // a,b: long long bool ok;