Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of ceil function in C

Tags:

c

ceil

I have two questions regarding ceil() function..

  1. The ceil() function is implemented in C. If I use ceil(3/2), it works fine. But when I use ceil(count/2), if value of count is 3, then it gives compile time error.

    /tmp/ccA4Yj7p.o(.text+0x364): In function FrontBackSplit': : undefined reference toceil' collect2: ld returned 1 exit status

    How to use the ceil function in second case? Please suggest.

  2. How can I implement my own ceil function in C. Please give some basic guidelines.

Thanks.

like image 988
AGeek Avatar asked Dec 29 '22 17:12

AGeek


1 Answers

Try this out:

#define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X))
#define CEILING_NEG(X) ((X-(int)(X)) < 0 ? (int)(X-1) : (int)(X))
#define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) )

Check out the link for comments, proof and discussion: http://www.linuxquestions.org/questions/programming-9/ceiling-function-c-programming-637404/

like image 123
nintendo Avatar answered Jan 12 '23 06:01

nintendo