I agree.  I would probably use a macro:

#define LCMS_EQ(a,b) (fabs((double)(a) - (double)(b)) <= DBL_EPSILON)

if (LCMS_EQ(xyz->X, 0) && LCMS_EQ(xyz->Y, 0) && LCMS_EQ(xyz->Z, 0))
  { ... }

if (LCMS_EQ(L, 0.0)) { ... }

or, if the test is always against 0:

#define LCMS_EQ_ZERO(a) (fabs((double(a)) <= DBL_EPSILON)

If (LCMS_EQ_ZERO(xyz->X) &&
    LCMS_EQ_ZERO(xyz->Y) &&
    LCMS_EQ_ZERO(xyz->Z))
  { ... }

if (LCMS_EQ_ZERO(L) { ... }

Glenn

On Sat, Oct 17, 2009 at 1:39 AM, Ethan Hansen <ehan...@drycreekphoto.com> wrote:
> Several of the conversion routines in cmspcs.c perform explicit comparisons
> of double values to 0. Depending on the compiler used and the optimization
> parameters, these comparisons can be unreliable. A floating point number may
> not be *exactly* 0 - or any other specific number for that matter - although
> that was the intent of the program and/or programmer.
>
>
>
> Suggested changes:
>
> 26a27,28
>> #include <float.h>
>>
>
> 183c185
> <        if (xyz -> X == 0 && xyz -> Y == 0 && xyz -> Z == 0)
> ---
>>        if (fabs(xyz -> X) <= DBL_EPSILON && fabs(xyz -> Y) <= DBL_EPSILON
> && fabs(xyz -> Z) <= DBL_EPSILON)
>
> 296c298
> <        if (L==0.0) {
> ---
>>        if (fabs(L) <= DBL_EPSILON) {

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Lcms-user mailing list
Lcms-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user

Reply via email to