Skip to content

Instantly share code, notes, and snippets.

@zziz
Last active September 10, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zziz/e521e4ee03cd50b119ea702afee61f2e to your computer and use it in GitHub Desktop.
Save zziz/e521e4ee03cd50b119ea702afee61f2e to your computer and use it in GitHub Desktop.
C++ floor and ceil one-liner
double floor(double x){
return (x >= 0) ? (int) x : (x == (int) x ? x : (int) x - 1);
}
double ceil(double x){
return (x >= 0) ? ((x == (int) x) ? (int) x : (int) x + 1) : ((x == (int) x) ? (int) x + 1 : (int) x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment