Re: a very naive question...

2008-05-28 Thread Steven Fillingham
Surely this is enough .. ULong sum, a, b; sum = a + b; if ((sum a) || (sum b)) overflow Jeremy Evans [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Lots of neat ideas here!! Might as well offer mine: convert a,b to their % of 0xF, add the two

Re: a very naive question...

2008-05-28 Thread Dave Carrigan
M. Edward Wilborne III [EMAIL PROTECTED] writes: The real question, is, IMHO, Is there an overflow carry when A+B get added? So, if you right shift by 1 bit a and b, (i.e. divide each by 2) and then add those divided numbers together, then the resulting answer will have the high order bit

a very naive question...

2008-05-28 Thread Paul Nevai
Suppose I use C in CW and I have UInt32 a, b; How can I determine if a and b are huge then (a + b) is not beyond 0xF [max UInt32]? Is there a standard way of doing it? E.g, can I check if (a + b a || a + b b)? Does this make sense? Does my question make sense? Best regards, Paul

Re: a very naive question...

2000-11-29 Thread Aaron Ardiri
Wait a minute... this is an interesting problem :)) the CPU integrates an overflow check internally, so you can tap into this using assembler - but not so easially using C/C++ :) for an obfuscated example, check out the following code: in gcc (PRC-Tools), it would look like this:

Re: a very naive question...

2000-11-29 Thread Jeremy Evans
Lots of neat ideas here!! Might as well offer mine: convert a,b to their % of 0xF, add the two together, if the result is greater than 100% then error. Give 20 programmers 1 problem and you'll have 20 different solutions :) Suppose I use C in CW and I have UInt32 a, b; How can I

Re: a very naive question...

2000-11-29 Thread Aaron Ardiri
Lots of neat ideas here!! Might as well offer mine: :)) convert a,b to their % of 0xF, add the two together, if the result is greater than 100% then error. using '%' may be confused with modulus, but essentially, it ends up being something similar to another technique i

Re: a very naive question...

2000-11-29 Thread Steven Fillingham
Surely this is enough .. ULong sum, a, b; sum = a + b; if ((sum a) || (sum b)) overflow "Jeremy Evans" [EMAIL PROTECTED] wrote in message news:31607@palm-dev-forum... Lots of neat ideas here!! Might as well offer mine: convert a,b to their % of 0xF, add the

a very naive question...

2000-11-28 Thread Paul Nevai
Suppose I use C in CW and I have UInt32 a, b; How can I determine if "a" and "b" are "huge" then (a + b) is not beyond 0xF [max UInt32]? Is there a standard way of doing it? E.g, can I check if (a + b a || a + b b)? Does this make sense? Does my question make sense? Best regards,

Re: a very naive question...

2000-11-28 Thread Tim Charron
How about: if ( a ( (UInt32)(0x-b) ) ) { //Overflow } else { //OK } -- Tim Paul Nevai wrote: Suppose I use C in CW and I have UInt32 a, b; How can I determine if "a" and "b" are "huge" then (a + b) is not beyond 0xF [max UInt32]? Is there a

Re: a very naive question...

2000-11-28 Thread Dave Johnson
At 2:40 PM -0500 11/28/00, Paul Nevai wrote: Suppose I use C in CW and I have UInt32 a, b; How can I determine if "a" and "b" are "huge" then (a + b) is not beyond 0xF [max UInt32]? You could add them together and check that the result is larger than both a and b individually. If it's

Re: a very naive question...

2000-11-28 Thread Danny Epstein
"Paul Nevai" [EMAIL PROTECTED] wrote in message news:31423@palm-dev-forum... E.g, can I check if (a + b a || a + b b)? Or just: if (a + b a) or: if (a + b b) Both of these conditions will be true if the addition wraps around. -- Danny Epstein OS Engineer, Palm Inc. -- For

Re: a very naive question...

2000-11-28 Thread M. Edward Wilborne III
sday, November 28, 2000 10:22 PM Subject: Re: a very naive question... Try using a unsigned long long type (64 bit arithmetic). - Original Message - From: "Paul Nevai" [EMAIL PROTECTED] To: "Palm Developer Forum" [EMAIL PROTECTED] Sent: Tuesday, November 28, 200

Re: a very naive question...

2000-11-28 Thread M. Edward Wilborne III
That's it! My method was much too complex. Ed - Original Message - From: "Philip Sheard" [EMAIL PROTECTED] To: "Palm Developer Forum" [EMAIL PROTECTED] Sent: Tuesday, November 28, 2000 10:32 PM Subject: Re: a very naive question... if (a b 0x8000){... --

Re: a very naive question...

2000-11-28 Thread M. Edward Wilborne III
of a and b would still result in a carry (overflow). Maybe I'm just too tired to see straight. Ed - Original Message - From: "Philip Sheard" [EMAIL PROTECTED] To: "Palm Developer Forum" [EMAIL PROTECTED] Sent: Tuesday, November 28, 2000 10:32 PM Subject: Re: a very naive que

Re: a very naive question...

2000-11-28 Thread Dave Carrigan
"M. Edward Wilborne III" [EMAIL PROTECTED] writes: The real question, is, IMHO, "Is there an overflow carry when A+B get added?" So, if you right shift by 1 bit a and b, (i.e. divide each by 2) and then add those divided numbers together, then the resulting answer will have the high order