Write a function to fine the ceiling of a double value and write a function to fine its floor. The ceiling of a number is the smallest integer greater than or equal to that number .the floor of a a number is the largest integer bless than or equal to that integer. For example the ceiling of 5.4 is 6 and the floor of 5.4 is 5.
// the floor function
int fastFloor(double x) {
int xi = (int)x;
return x < xi ? xi - 1 : xi;
}
// the ceil function
int ceil(float num) {
int inum = (int)num;
if (num == (float)inum) {
return inum;
}
return inum + 1;
}
Comments
Leave a comment