Is this the proper way to get the fractional part of a floating point number in GLBasic or is there already a function to do this which might be faster?
frac_x = x - INTEGER(x)
:-[
I'm not sure if it's faster, but this does what you want too:
frac_x = FMOD(x, 1) // Return the remainder of 'x / 1.0'
Quote from: Slydog on 2012-Mar-29
I'm not sure if it's faster, but this does what you want too:
frac_x = FMOD(x, 1) // Return the remainder of 'x / 1.0'
I noticed (a long while back) that MOD had a terrible impact on the FPS when using quite a lot on GP2X and Wiz (and I would guess that FMOD would be the same), so if you plan to do a lot of them, perhaps it would be wise to rethink your strategy. Obviously this will depend on platform and number of calls per loop.
Yeah Mod is one of the slowest ways to do it. I would do it retrotechs way.
Maybe there is a inline bit manipulation way to do it (faster), but i dont know it, sorry.^^
I would benchmark both techniques.
But I'd be surprised if FMOD() (or any other method) is faster than the simple 'x - INTEGER(x)' method.
I just thought it was 'tidier'!
Of course you could wrap it in a neat function:
FUNCTION GetDecimal: value#
RETURN value - INTEGER(value)
ENDFUNCTION
But then you have the overhead of calling a function every time. You could benchmark that too!
converting floats to integers is also pretty slow. fmod might be even faster.