[Bf-committers] Floating point compares
Kester Maddock
bf-committers@blender.org
Thu, 30 Oct 2003 00:25:11 +1300
Hi guys,
I've just noticed that there are a lot of floating point compares in the
code, ie:
if(tex->cropxmin==0.0) ret++;
if(tex->cropymin==0.0) ret++;
if(tex->cropxmax==1.0) ret++;
if(tex->cropymax==1.0) ret++;
Isn't this bad? (because of the finite floating point precision.)
#define FPRECISION 1e-10
static inline int fzero(float x)
{
return fabs(x) < FPRECISION;
}
static inline int fequal(float x, float y)
{
return fzero(x - y);
}
if(fzero(tex->cropxmin)) ret++;
if(fzero(tex->cropymin)) ret++;
if(fequal(tex->cropxmax, 1.0)) ret++;
if(fequal(tex->cropymax, 1.0)) ret++;
GCC will catch this with -Wfloat-equal.
Should I start fixing this or is there a valid reason to do it this way?
Kester