fork download
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. const auto ui64max = numeric_limits<uint64_t>::max();
  8. const auto foo = ui64max - 1;
  9. const auto bar = static_cast<long double>(foo) / ui64max;
  10.  
  11. cout << "Max Digits For Roundtrip Guarantee: " << numeric_limits<long double>::digits << "\nMax Digits In uint64_t: " << numeric_limits<uint64_t>::digits << "\nConverting: " << foo << "\nTo long double Mantissa: " << bar << "\nRoundtrip Back To uint64_t: " << static_cast<uint64_t>(bar * ui64max) << endl;
  12. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Max Digits For Roundtrip Guarantee: 64
Max Digits In uint64_t: 64
Converting: 18446744073709551614
To long double Mantissa: 1
Roundtrip Back To uint64_t: 18446744073709551614