fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double my_remainder(double Value1, double Value2)
  7. {
  8. const double Result = fmod(Value1, Value2);
  9. return Value2 < 0.0 ? -Result : Result;
  10. }
  11.  
  12. void test(double a, double b)
  13. {
  14. double res1 = my_remainder(a, b);
  15. double res2 = remainder(a, b);
  16.  
  17. std::cout << a << "/" << b << "\n"
  18. << " impl: " << res1 << "\n"
  19. << " std: " << res2 << "\n"
  20. << ((res1 == res2) ? " pass\n" : " fail\n");
  21. }
  22.  
  23.  
  24.  
  25. int main()
  26. {
  27. test(5.3, 2);
  28. test(18.5, 4.2);
  29. test(-5.3, 2);
  30. test(-18.5, 4.2);
  31. test(5.3, -2);
  32. test(18.5, -4.2);
  33. test(-5.3, -2);
  34. test(-18.5, -4.2);
  35. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
5.3/2
 impl: 1.3
  std: -0.7
 fail
18.5/4.2
 impl: 1.7
  std: 1.7
 pass
-5.3/2
 impl: -1.3
  std: 0.7
 fail
-18.5/4.2
 impl: -1.7
  std: -1.7
 pass
5.3/-2
 impl: -1.3
  std: -0.7
 fail
18.5/-4.2
 impl: -1.7
  std: 1.7
 fail
-5.3/-2
 impl: 1.3
  std: 0.7
 fail
-18.5/-4.2
 impl: 1.7
  std: -1.7
 fail