Re: [xml] XPath mod operator problems



Geert Kloosterman wrote:

There's one other thing.  Isn't the real problem the comparison of the
floats?  Comparing floats is a tricky thing.

Indeed. Because of the inexact representation of floating-point number
we must use an inexact comparison like this

  A - epsilon < B < A + epsilon

where A and B are the floating-point numbers we want to compare, and
epsilon is the (positive) tolerance.

In C, using a macro as syntactical sugar, this translates into (caveat:
untested code)

  #define DBL_EQUAL(a,b) ((((a) - DBL_EPSILON) < (b)) && ((b) < ((a) +
DBL_EPSILON)))

  if (DBL_EQUAL(A, B))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]