Jump to content
  • Advertisement
Sign in to follow this  
timw

rounding down

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
wow guys thanks for the quick replies. I wouldn't call it premature tho. because its something we've all done millions of time lol. just wondering. I'm not concerned with negative numbers, but thanks for clearing it up.

thanks

Tim

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!