how to test value's overflow without comparison

S

starffly

In my program, the calculated value is supposed to be no more than the
constants named MAXINT,otherwise, the overflow error will be reported,
however, I cannot test if the value exceeds MAXINT within the integer
scope smaller than MAXINT, so I want to seek a solution to test the
excess without comparing the value with MAXINT. Please let me know if
you have a good idea.
THX.
 
S

Schraalhans Keukenmeester

In my program, the calculated value is supposed to be no more than the
constants named MAXINT,otherwise, the overflow error will be reported,
however, I cannot test if the value exceeds MAXINT within the integer
scope smaller than MAXINT, so I want to seek a solution to test the
excess without comparing the value with MAXINT. Please let me know if
you have a good idea.
THX.
Quote: "I cannot test if the value exceeds MAXINT within the integer
scope smaller than MAXINT [...]"

Do you mean to say the scope you use in your program is
MININT <= SCOPE_MIN <= YOUR_DATA <= SCOPE_MAX <= MAXINT ?

If so, why can't you test this? And what's the big difference between
testing for a set overflow flag (I am not sure the standard even demands
compilers to set such a flag on integer overflow) and testing against
SCOPE_MAX?

Maybe if you include a relevant portion of the code involved we might be
able to be of more help.

Sh.

PS Please don't post same stuff twice under different titles. We got the
point the first time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top