bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 1.4.9: wrong results in signed division


From: Eric Blake
Subject: Re: 1.4.9: wrong results in signed division
Date: Mon, 23 Apr 2007 06:37:51 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.5.666

According to Cesar Strauss on 4/21/2007 5:30 PM:
> Hi,
> 
> The eval macro in m4-1.4.9 gives wrong results in signed division:
> 
> $ ./m4
> eval(-100/10)
> 429496719
> (expected: -10)

Indeed, this is a regression.  Thanks for the report.

> This comment near the code seems relevant:
> 
>      /* Minimize undefined C behavior on overflow.  This code assumes
>      that the implementation-defined overflow when casting
>      unsigned to signed is a silent twos-complement
>      wrap-around.  */
> 
> I don't think any overflow handling is needed here, because the
> quotient is always smaller than the dividend, in signed integer
> division.

No, consider INT_MIN/-1.  With 2's complement, it is undefined according
to C (there is no way to represent -INT_MIN in an int).  It turns out that
many 2's complement architectures do wraparound and come up with the
answer INT_MIN, while Intel causes SIGFPE.  So special handling IS needed,
just not what I wrote, nor your reversion.  I'll come up with something
shortly.

-- 
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]