[cairo] Re: Some other bits...

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Wed Aug 17 11:07:31 PDT 2005


On 8/17/05, Bill Spitzak <spitzak at d2.com> wrote:
> int
>   _cairo_fixed_integer_part (cairo_fixed_t f)
>   {
>       return f >> CAIRO_FIXED_FLOAT_BITS;
>   }
>
>   int
>   _cairo_fixed_integer_floor (cairo_fixed_t f)
>   {
>       if (f >= 0)
>           return f >> CAIRO_FIXED_FLOAT_BITS;
>       else
>           return -((-f - 1) >> CAIRO_FIXED_FLOAT_BITS) - 1;
>   }
>
> These functions return identical values! I.e. integer_part() is
> returning floor(), in a much more efficient way.

A problem here is that the C standard does not define the
result of >> when applied to negative numbers, making this
optimization unportable. It's certainly a good optimization
when it works though.

[snip]

Bertram


More information about the cairo mailing list