ceil replacement
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?
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
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
That''s slow... Converting from float to int and back... There must be another solution
> 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.
> 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.
John BlackburneProgrammer, The Pitbull Syndicate
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement