[cairo] _cairo_color_compute_shorts fails with FPU set to single precision

Bill Spitzak spitzak at d2.com
Thu Aug 31 13:10:55 PDT 2006


Fabien Costantini wrote:

> Well epsilon seems useful this time because it will bug otherwise if 
> values are between [1.0-1.e-20,1.0[
> i.e: the following example:
>     int v = (int) ((1.0-1.e-20)*65536);
>     printf("val = %d\n",v);
 > returns 65536

In 64-bit doubles, 1-1e-20 is not any different from 1.0. This prints 0 
on my machine:

double f = 1.0-1e-20;
printf("%d\n", f<1);

So the code that says "if (f<1) return 65536*f; else return 65535;" 
works because it takes the second case.

In fact any numbers closer than 5.55111512313e-17 (2^-54) to 1.0 are 1.0 
in IEEE 64-bit floats.


More information about the cairo mailing list