[cairo] Some other bits...

Bill Spitzak spitzak at d2.com
Wed Aug 17 10:32:45 PDT 2005



Behdad Esfahbod wrote:

int
  _cairo_fixed_integer_part (cairo_fixed_t f)
  {
-    return f >> 16;
+    return f >> CAIRO_FIXED_FLOAT_BITS;
  }

  int
  _cairo_fixed_integer_floor (cairo_fixed_t f)
  {
      if (f >= 0)
-	return f >> 16;
+	return f >> CAIRO_FIXED_FLOAT_BITS;
      else
-	return -((-f - 1) >> 16) - 1;
+	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.

Test program that exits with zero:

int main() {
   int f; for (f = -1; f > -0x7fffffff; f--) {
     int a,b;
     a = f>>16;
     b = -((-f-1)>>16)-1;
     if (a != b) {printf("%x %x %x\n", f, a,b); return 1;}
   }
   return 0;
}

I recommend you make the functions identical.

Rounding toward zero is complicated, but of absolutly no interest for 
graphics programs, so there is no reason to implement it.


More information about the cairo mailing list