fmod.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Boost test/fmod.cpp
  2. * test the fmod with specially crafted integer intervals
  3. *
  4. * Copyright 2002-2003 Guillaume Melquiond
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * (See accompanying file LICENSE_1_0.txt or
  8. * copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #include <boost/numeric/interval/interval.hpp>
  11. #include <boost/numeric/interval/arith.hpp>
  12. #include <boost/numeric/interval/arith2.hpp>
  13. #include <boost/numeric/interval/utility.hpp>
  14. #include <boost/numeric/interval/checking.hpp>
  15. #include <boost/numeric/interval/rounding.hpp>
  16. #include <boost/test/minimal.hpp>
  17. #include "bugs.hpp"
  18. struct my_rounded_arith {
  19. int sub_down(int x, int y) { return x - y; }
  20. int sub_up (int x, int y) { return x - y; }
  21. int mul_down(int x, int y) { return x * y; }
  22. int mul_up (int x, int y) { return x * y; }
  23. int div_down(int x, int y) {
  24. int q = x / y;
  25. return (x % y < 0) ? (q - 1) : q;
  26. }
  27. int int_down(int x) { return x; }
  28. };
  29. using namespace boost;
  30. using namespace numeric;
  31. using namespace interval_lib;
  32. typedef change_rounding<interval<int>, save_state_nothing<my_rounded_arith> >::type I;
  33. int test_main(int, char *[]) {
  34. BOOST_CHECK(equal(fmod(I(6,9), 7), I(6,9)));
  35. BOOST_CHECK(equal(fmod(6, I(7,8)), I(6,6)));
  36. BOOST_CHECK(equal(fmod(I(6,9), I(7,8)), I(6,9)));
  37. BOOST_CHECK(equal(fmod(I(13,17), 7), I(6,10)));
  38. BOOST_CHECK(equal(fmod(13, I(7,8)), I(5,6)));
  39. BOOST_CHECK(equal(fmod(I(13,17), I(7,8)), I(5,10)));
  40. BOOST_CHECK(equal(fmod(I(-17,-13), 7), I(4,8)));
  41. BOOST_CHECK(equal(fmod(-17, I(7,8)), I(4,7)));
  42. BOOST_CHECK(equal(fmod(I(-17,-13), I(7,8)), I(4,11)));
  43. return 0;
  44. }