Hi,
I know that you must keep some advice about comparing 2 floating-points values for equality,
but why I cannot use this method ?
//
#include <stdio.h>
#include <stdbool.h>
//
#define PREC double
//
inline bool IsFloatEqual(const PREC a, const PREC b)
{
if ( a < b )
{
return false;
}
else if ( a > b )
{
return false;
}
return true;
}
//
int main(void)
{
PREC a = 0.0000001239995;
PREC b = 0.0000001239996;
printf("a = %f, b = %f\n", a, b); // wrong, you can see it equal
printf("This numbers are%s equal!\n", IsFloatEqual(a, b) ? "": " not");
return 0;
}
Thanks, Alessio.