Created
September 9, 2010 16:46
-
-
Save markwatson/572149 to your computer and use it in GitHub Desktop.
ceiling function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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