Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created September 5, 2012 18:21
Show Gist options
  • Save springmeyer/3641860 to your computer and use it in GitHub Desktop.
Save springmeyer/3641860 to your computer and use it in GitHub Desktop.
compare cmath::rint and std::ceil
#include <cmath>
#include <iostream>
/*
clang++ -o rint-ceil rint-ceil.cpp;./rint-ceil
rint(1.11111): 1
ceil(1.11111): 2
rint(1.44444): 1
ceil(1.44444): 2
rint(1.5): 2
ceil(1.5): 2
*/
void print_result(float val) {
std::clog << "rint(" << val << "): " << rint(val) << "\n";
std::clog << "ceil(" << val << "): " << std::ceil(val) << "\n";
}
int main() {
print_result(1.111111111);
print_result(1.444444444445);
print_result(1.5000000000000000000);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment