Use of identity matrix?

Started by
10 comments, last by Muzzafarath 23 years, 10 months ago
quote:Original post by MadKeithV

Eh eh, try this one, an error I had in my engine just the other day:
float x = 1.0f;
int y = x/0.1f;
y = .... 9!!!!!!!!!




It''s all down to discrete mathematics. When you create a floating point value of 0.1, the compiler creates the closest floating point value to 0.1 , which in this case is slightly more than 0.1

So, when you divide 1 by slighly more than 0.1, you get slightly less than 10 - and when you cast this to an int it gets truncated to 9.

This is an inherent limitation of converting from decimal to binary and vice-versa . You can improve the accuracy of your engine by:

a) Adding 0.5f before casting to int , ie. y = (int) (0.5f + x/0.1f);
b) Changing y to be floating point (if possible)
c) Switching from single- to double-precision floating point (but this will cost you speed, and will still have some problems)


Advertisement
I solved it by adding EPSILON, which is my standard deviation within which two floats are still considered equal.

The PROBLEM with the bug was, that in the "watch" window, it reported the expression as being 10, and since I was lazy to look at the "variables" window, it took me half an hour before I saw it WASN''T ten at all...
So now I ask, why the *BLEEP* can an expression have different values in watch, and in the code??
( bloody microsoft, different levels of precision )


Give me one more medicated peaceful moment..
~ (V)^|) |<é!t|-| ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.

This topic is closed to new replies.

Advertisement