Archived

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

digiman

ceil replacement

Recommended Posts

digiman    122
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
wings656    122
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
johnb    351
> 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