Last active
September 10, 2018 12:28
-
-
Save zziz/e521e4ee03cd50b119ea702afee61f2e to your computer and use it in GitHub Desktop.
C++ floor and ceil one-liner
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
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