fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. enum { FACTOR = 3 };
  9. double d = 1.0 / FACTOR;
  10. double d_i = int(d * FACTOR);
  11. int i_t = std::trunc(d * FACTOR);
  12. double d_r = std::round(d * FACTOR);
  13. cout << d_i << " vs " << i_t << " vs " << d_r << endl;
  14. return 0;
  15. }
  16.  
Success #stdin #stdout 0s 4576KB
stdin
Standard input is empty
stdout
1 vs 1 vs 1