Game Development Community

Variable value trouble.

by Sebastiaan Keek · in Torque Game Engine · 04/19/2003 (5:02 am) · 0 replies

This might not be an real bug, but it's still odd.

Inside the engine code.

I've taken an F32 'i', that ranges between 0 and 1.
And any int 'd'.
Now to make sure 'i''s value is such that 'i'*'d' is also an integer (no numbers behind the comma) I used the following code.

i *= d;
i = floor(i)/d;

Now what the computation really does or how it does it is not that imporant, but I've tried typecasts, defining an special floor() functions based of fModF() and even rewriting whole computation, using different steps, a number of times but that doesn't prevent it from being wrong at specific instances.
For example i=0.7 d=20 returns 0.65 even when 0.7*20 = 14 wich should not be corrected since it's an integer.

Now for the bug part, when I put Con::warnf(ConsoleLogEntry::General, "i1 = %f",i); before and after each line of code to check up on the value of i, the error magically disapears.
Somehow the warnf keeps the i from going wrong.

Does anyone have any idea how to counter this error from slipping into the variable values?
What could be the problem? and how can it somehow solve itself when echoing the values?
I can't afford putting an echo in this function as it get's called way too often.