fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4. #include <cstdint>
  5. using std::cout;
  6.  
  7. int main()
  8. {
  9. typedef std::uint_fast64_t uint_type;
  10.  
  11. double a, b, c;
  12. uint_type ta, tb, tc, ic;
  13.  
  14. a = 45'035'996'273'704'952ULL; // (2**53 - 2) * 5 + 2;
  15. b = 9'007'199'254'740'991ULL; // 2**53 - 1;
  16. c = a / b;
  17.  
  18. ta = static_cast<uint_type>(a);
  19. tb = static_cast<uint_type>(b);
  20. tc = static_cast<uint_type>(c);
  21. ic = ta / tb;
  22.  
  23. cout << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << std::boolalpha;
  24.  
  25. cout << "a == " << a << "\n";
  26. cout << "ta == " << ta << "\n\n";
  27.  
  28. cout << "b == " << b << "\n";
  29. cout << "tb == " << tb << "\n\n";
  30.  
  31. cout << "c = " << c << "\n";
  32. cout << "tc == " << tc << "\n";
  33. cout << "ic == " << ic << "\n";
  34.  
  35. cout << "tc == ic: " << (tc == ic) << "\n\n";
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
a  == 4.50359962737049520e+16
ta ==  45035996273704952

b  == 9.00719925474099100e+15
tb ==  9007199254740991

c  = 5.00000000000000000e+00
tc ==  5
ic ==  4
tc == ic: false