Jukka Lehtonen wrote:

if ( fabs( A - B ) < epsilon ) ...

The question that formed in my mind was:

Why do I have to do that?

What is the purpose of operator== (float, float)

within the standard if it does not perform the action

that my intuition expects? Granted, the epsilon would have

to be specified somewhere.

The problem is, that epsilon varies..It depends on A and B *and* the

rounding error you are ready to expect at a certain state of

computation. Refer to numeric_limits<T>::epsilon(). This returns the

smallest number, such that 1.0 + epsilon == 1.0. But this also means

(usually...), that for any other number r, epsilon is r*epsilon!

Now consider something like x*x. if x has an epsilon eps(x), then x*x

has a maximal error of something like[1]:

error(x*x)=|(x+eps(x))^2-x^2|=|2*x*eps(x)+eps(x)^2|

and for (x*x)/x it's |error(x^2)/(x+eps)-error(x^2)/x|

So therefore you need an idea for you epsilon or make a good guess.

Marco

[1] Disclaimer: These formulas a incorrect and irrelevant and are meant

to give nothing than a rough idea of the magnitude of expectable

trouble.