Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


ceil replacement

This topic is 6187 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''m working on a total math.h library replacement for my engine. I have almost all functions very nicely except for ceil. It doesn''t seem to work always correctly. Does anybody know where can I get additional info about it? Or just a piece of code?

Share this post

Link to post
Share on other sites
This is a simple way of rounding up:

int ceil(float f){
int i;
return i;

I haven''t tried it out, but it should work


Share this post

Link to post
Share on other sites
> That''s slow... Converting from float to int and back... There
> must be another solution

I think Jamie''s solution is the quickest on most processors. The only caveat is if you code it in C you are letting the compiler choose how to convert to float to int, and it may substiture it''s own lib call or other inefficient code. If you know the processor well you can often do better if you code it in assembly yourself. For maximum speed look at using inline assembly, though this is very processor/compiler dependent.

Share this post

Link to post
Share on other sites

  • 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!