"Richard Herring" wrote, regarding equality-checking doubles:
True [that it's a bad idea]. OTOH it's often exactly what's
required.
I've been burned by that before. Just what does "equal" mean
with doubles? "Equal" to +- 10^-5? "Equal" to +- 10^-10?
Often two variables that should be "equal" will compare
as inequal due to tiny round-off errors in the ninth or tenth
decimal places.
Idea:
#include <cmath>
bool MostlyEqual(double A, double B, int Precision)
{
if (Precision< 1) Precision= 1;
if (Precision>10) Precision=10;
double Max = A;
if (B > A) {Max = B;}
double Divisor = pow(10.0, (double)Precision);
double Difference = A - B;
if (B > A) {Difference = B - A;}
return (Difference < Max / Divisor)
}
--
Robbie Hatley
Tustin, CA, USA
lone wolf intj at pac bell dot net
home dot pac bell dot net slant earnur slant