Is it possible that x == x – 1?

This happened in my real product when clients’ balance changed as little as 1 Japanese cent.

void GeneralTest()
 float x = 1e30; //big number, 30 zeros following 1
 if(x == x - 1)
  printf("x == x - 1");

I try to avoid floating point numbers because not only they are slow, but also they’re not accurate.

Comments are closed.
%d bloggers like this: