Trying to "Normalize Double" but it returns the same precision as the original value - page 2

 
Alexander Martinez:

Like I mentioned earlier, I'm not outputting to to Print(), unless the Debugger window is the same as Print()? Also, if I compare 64.6 to 64.5999999999999943, will they be the same?

Edit: just tried it out, they are equal.

Be careful with testing doubles for equality. You need an epsilon for that. For example:

double a;

double b;

if ( a == b ) . . . 

can give you a nightmare.

Instead, use

if ( a - b < epsilon ) . . . 

where epsilon is a small number, like 1E-10.

I seem to recall @nicholi shen's class CDouble does a comparison test for you. There are also rounding functions.

 
Anthony Garot:

Be careful with testing doubles for equality. You need an epsilon for that. For example:

double a;

double b;

can give you a nightmare.

Instead, use

where epsilon is a small number, like 1E-10.

I seem to recall @nicholi shen's class CDouble does a comparison test for you. There are also rounding functions.

Thanks for the plug ;)... One minor suggestion... 


if(fabs(a - b) < epsilon)
 
nicholi shen:

Thanks for the plug ;)... One minor suggestion... 


Yup. Need absolute value bars to be correct.
Reason: