How to multiply two ints and check overflow
Tim McDaniel
mcdaniel at uicsrd.csrd.uiuc.edu
Fri May 19 10:19:27 AEST 1989
The INT_MIN and INT_MAX #defines are there for non-pANS C sites;
they're inherently unportable. If INT_MIN is #defined as
(-2147483648)
it may not work (it may get the wrong type, according to Chris Torek).
INT_MIN may have to be #defined as
(-2147483647 - 1)
or
(0x80000000)
or even just
(-2147483647)
if your compiler won't let you input -(2**32) and you're willing to
sacrifice the smallest int. (INT_MIN and INT_MAX don't have to be
exact, or even close, for my safemul code to work.)
--
"6:20 O Timothy, keep that which is committed to thy trust, avoiding
profane and vain babblings, and oppositions of science falsely so
called: 6:21 Which some professing have erred concerning the faith."
Tim, the Bizarre and Oddly-Dressed Enchanter | mcdaniel at uicsrd.csrd.uiuc.edu
{uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
mcdaniel%uicsrd@{uxc.cso.uiuc.edu,uiuc.csnet}
More information about the Comp.lang.c
mailing list