J
Jukka Lehtonen
Hi all,
I was watching g++ to spurt out warnings during compilation,
and if you enable most warning flags as I have occasionally
done that means a lot of text, most of it from library code.
Nothing special, but then I started thinking about the
occasional 'comparing floats for equality' lines.
I admit that those warnings are an indicator of my own
lazyness. The technical reasons for a call
float A = ...; float B = ...; if ( A == B ) ...
to be suspicious are a FAQ, as is the solution
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.
JVL
I was watching g++ to spurt out warnings during compilation,
and if you enable most warning flags as I have occasionally
done that means a lot of text, most of it from library code.
Nothing special, but then I started thinking about the
occasional 'comparing floats for equality' lines.
I admit that those warnings are an indicator of my own
lazyness. The technical reasons for a call
float A = ...; float B = ...; if ( A == B ) ...
to be suspicious are a FAQ, as is the solution
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.
JVL