Hey All,
Hoping someone might be able to shed some light on this
function main() f float = 0.97; i int = f * 16; j int = 0.97 * 16; Syslib.writeStdout(i::","::j); end
Can anyone explain why i=16 and j=15? I would have expected both to be 15. I even wrote the following java code just to make sure I wasn't going crazy
public static void main(String [] args) { float f = 0.97f; int i = (int)(f * 16); int j = (int)(0.97f * 16); System.out.println(i+","+j); }
And sure enough, both are 15. Changing from 0.97 to 0.96 in the EGL example makes both come out to 15, which leads me to believe that EGL is automatically rounding the result (rather than truncating) before casting from floating-point to int. But why? And why wouldn't it round in both cases? Is there something about a variable vs inline floats that EGL treats the float-to-int conversion operation differently?
Sorry if this is a stupid question, I tried searching google and the forums for information about what EGL is doing in the background for these conversions, but wasn't really able to find very much.
Cheers,
D.R.
dras