rounding down
I was thinking, what would be faster for taking the floor of a float
float f = bla;
f = (float)((int)f);
or
float f = bla;
f = floor(f);
never thought much of it, but it's such a common slow operation, I was wondering what people thought. no fixed point suggestions either lol.
thanks,
Tim
One would make the assumption that the floor() function will be as-fast or faster than the casting method (because if the casting method was the fastest - that would be what the floor function would implement).
Also, another reason to use the floor() function it is much eaiser to read what is tring to be done.
Finally - this is premature optimisation. You probably shouldn't be worrying about it.
Also, another reason to use the floor() function it is much eaiser to read what is tring to be done.
Finally - this is premature optimisation. You probably shouldn't be worrying about it.
you might not be able to convert your float to an int, even if it is a single precision
also, floor is different from truncating [conversion to an int], for negative [non-integer] numbers floor will give you a lower number, truncating will give you a more positive number.
also, floor is different from truncating [conversion to an int], for negative [non-integer] numbers floor will give you a lower number, truncating will give you a more positive number.
Also, on some compilers, floor() is implemented as a compiler intrinsic, which means that it will take calls to floor() and replace it with the assembly necessary to perform the rounding without the overhead of a function call.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement