fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. void print(double v) {
  7. cout << "0x" << hex << (*(long *)&v) << " = " << fixed << setprecision(40) << v << endl;
  8. }
  9.  
  10. int main() {
  11. //unsigned long val_ul = 0x3d824f7400000000;
  12. //double val = *(double *)&val_ul;
  13.  
  14. double val = 0.0;
  15.  
  16. double step = 0.001;
  17. double min = -99999.0;
  18. double max = 99999.0;
  19.  
  20. double r1 = val - min;
  21. double r2 = r1 / step;
  22. double r3 = round(r2);
  23. double r4 = r3 * step;
  24. double r5 = r4 + min;
  25.  
  26. print(val);
  27. print(step);
  28. print(min);
  29. print(max);
  30.  
  31. cout << endl;
  32.  
  33. print(r1);
  34. print(r2);
  35. print(r3);
  36. print(r4);
  37. print(r5);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
0x0 = 0.0000000000000000000000000000000000000000
0x3f50624dd2f1a9fc = 0.0010000000000000000208166817117216851329
0xc0f869f000000000 = -99999.0000000000000000000000000000000000000000
0x40f869f000000000 = 99999.0000000000000000000000000000000000000000

0x40f869f000000000 = 99999.0000000000000000000000000000000000000000
0x4197d77460000000 = 99999000.0000000000000000000000000000000000000000
0x4197d77460000000 = 99999000.0000000000000000000000000000000000000000
0x40f869f000000000 = 99999.0000000000000000000000000000000000000000
0x0 = 0.0000000000000000000000000000000000000000