Strange results with float subtraction

Hello! Recently, I was writing a small game in SFML when I ran into a strange problem involving the subtraction of floats. Here's a small snippet of the code I'm talking about:

std::cout << << ", " << position_.y << ", " << - position_.y << std::endl

Which produced the following output:

512.679, 511.679, 0.999969

Even stranger, subtracting 1 from this results in -3.05176e-005?
Stranger still, try as I may, I can't seem to be able to reproduce this result; if I load up a new console application and do this very subtraction the output is correct - 1.

I've been trying to debug this for upwards of a week, what in the world is going on here?

Last edited on
Quick explanation:

Involved explanation:

There's nothing to "debug" there.
If you want more precise floating point numbers make a "BigInt" class.
Topic archived. No new replies allowed.