Skip to content

Instantly share code, notes, and snippets.

@markwatson
Created September 9, 2010 16:46
Show Gist options
  • Save markwatson/572149 to your computer and use it in GitHub Desktop.
Save markwatson/572149 to your computer and use it in GitHub Desktop.
ceiling function
#include <stdio.h>
double my_ceil(double x) {
double y = (double) ((long long) x);
if (x - y == 0) {
return x;
} else {
if (x > 0) {
return y + 1;
} else {
return y;
}
}
}
int main(void) {
printf ("ceil of 2.0 is %.1lf\n", my_ceil(2.0) );
printf ("ceil of 3.8 is %.1lf\n", my_ceil(3.8) );
printf ("ceil of -2.3 is %.1lf\n", my_ceil(-2.3) );
printf ("ceil of -3.0 is %.1lf\n", my_ceil(-3.0) );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment