fork(1) download
  1. #include <math.h>
  2. #include <iostream>
  3.  
  4. #define dbg(x) do { volatile auto v = x; std::cout << #x << ": " << v << std::endl; } while (0)
  5.  
  6. template<typename T> long long to_ll(T x) {
  7. volatile T y = x;
  8. return (long long)y;
  9. }
  10.  
  11. int main() {
  12. volatile double x = 302500001100000001;
  13. volatile long double y = 302500001100000001;
  14. std::cout << std::fixed;
  15. std::cout.precision(12);
  16. dbg(x);
  17. dbg(y);
  18. dbg(sqrt(x));
  19. dbg(sqrt(y));
  20. dbg(to_ll(sqrt(x)));
  21. dbg(to_ll(sqrt(y)));
  22. dbg(sqrtl(x));
  23. dbg(sqrtl(y));
  24. dbg(to_ll(sqrtl(x)));
  25. dbg(to_ll(sqrtl(y)));
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
x: 302500001100000000.000000000000
y: 302500001100000001.000000000000
sqrt(x): 550000001.000000000000
sqrt(y): 550000001.000000000000
to_ll(sqrt(x)): 550000001
to_ll(sqrt(y)): 550000001
sqrtl(x): 550000000.999999999069
sqrtl(y): 550000001.000000000000
to_ll(sqrtl(x)): 550000000
to_ll(sqrtl(y)): 550000001