• Advertisement

Archived

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

ceil replacement

This topic is 6044 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
Advertisement
This is a simple way of rounding up:

int ceil(float f){
int i;
f+=1.0;
i=f;
return i;
}

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

Jamie--wings656@hotmail.com

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

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