Re: [AD] Borland C++ compilation errors

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, Nov 05, 2001 at 10:12:42PM +0100, Eric Botcazou wrote:
> > Hmm... but this still doesn't work for negative inputs (they'll
> > always cast to unsigned longs greater than the test value).
> 
> That's a bug of the original C version of fceil() I didn't detect (the x86
> asm is ok)... Never trust the existing code ;-)
> 
> Do I have your approval for the following version ?

Looks fine, yes, apart from:

> I have a little concern though about the portability of this C version of
> fceil() (and of fixtoi() too): it relies on x>>16 being an arithmetical
> shift, isn't it ? According to my book on the C language: "The ANSI standard
> does not specify whether a compiler should perform a logical or arithmetic
> shift for signed objects".

True, I wonder whether it's worth fixing.  I can't think of
anything more efficient than testing the sign of the number:

    if (x >= 0)
        return (x >> 16);
    else
        return -(-x >> 16);

George



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/