The difference between:

int miles (int32_t a, int32_t b) {
    return (((long)a * (long)b) + 0x8000) >> 16;
}

and:

int another (long a, long b) {
    long r = a * b;
    long s = r >> SIZEOF_LONG_LESS_ONE;
    return (r + s + 0x8000) >> 16;
}

only shows up for products which are negative and which overflow 32 bits.

Either one could replace FT's current C version of mulfix, but only on
platforms where sizeof(FT_Long) > sizeof(FT_Int32).  Neither works when
sizeof(long)*CHAR_BITS == 32.

Werner:  Miles' version is shorter, is only wrong by one ulp and only
         when the product overflows and is negative.  My variation,
         called another() above, fixes that slight difference.
         Which would you prefer, if anything?  I can write a patch
         which uses it only when it works (64 bit sizeof(long)).

-JimC
-- 
James Cloos <cl...@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6

_______________________________________________
Freetype-devel mailing list
Freetype-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to