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
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
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
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:
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
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
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
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,
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
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
"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
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
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){...
--
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
"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
15 matches
Mail list logo