At 08:34 PM 3/8/2001 +0000, Nicholas Clark wrote:
>On Thu, Mar 08, 2001 at 01:55:57PM -0500, Dan Sugalski wrote:
> > At 06:49 PM 3/8/2001 +0000, Nicholas Clark wrote:
> > >On Thu, Mar 08, 2001 at 11:43:31AM -0500, Dan Sugalski wrote:
> > > > I was thinking maybe (length/4)*31-bit 2s complement to make portable
> > > > overflow detection easier, but that would be only if there wasn't a 
> good C
> > > > library for this available to snag.
> > >
> > >The only portable integer overflow in ANSI C is unsigned integers.
> > >signed integer overflow does not always do what you might expect, even
> > >on a 2s complement machine.
> >
> > That's what the 32nd bit of each word is for. If we do addition on a
> > word-by-word basis and the high bit of the result is set, we know we've
> > overflowed, and we can set it as a carry bit for subtraction.
>
>pp_add and pp_subtract in perl5 currently do it OK on 32 bits.
>You can detect overflow in unsigned 32 bits because your result
>(a+b) is smaller than a (or b for that matter)

You can do better than that on some hardware--overflows and underflows can 
set status bits that C compilers generally ignore but we can check. Not 
everywhere, granted, but enough places to make it worthwhile.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to