• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include <boost/numeric/interval/interval.hpp>
12 #include <boost/numeric/interval/arith.hpp>
13 #include <boost/numeric/interval/arith2.hpp>
14 #include <boost/numeric/interval/utility.hpp>
15 #include <boost/numeric/interval/checking.hpp>
16 #include <boost/numeric/interval/rounding.hpp>
17 #include <boost/test/minimal.hpp>
18 #include "bugs.hpp"
19 
20 struct my_rounded_arith {
sub_downmy_rounded_arith21   int sub_down(int x, int y) { return x - y; }
sub_upmy_rounded_arith22   int sub_up  (int x, int y) { return x - y; }
mul_downmy_rounded_arith23   int mul_down(int x, int y) { return x * y; }
mul_upmy_rounded_arith24   int mul_up  (int x, int y) { return x * y; }
div_downmy_rounded_arith25   int div_down(int x, int y) {
26     int q = x / y;
27     return (x % y < 0) ? (q - 1) : q;
28   }
int_downmy_rounded_arith29   int int_down(int x) { return x; }
30 };
31 
32 using namespace boost;
33 using namespace numeric;
34 using namespace interval_lib;
35 
36 typedef change_rounding<interval<int>, save_state_nothing<my_rounded_arith> >::type I;
37 
test_main(int,char * [])38 int test_main(int, char *[]) {
39 
40   BOOST_CHECK(equal(fmod(I(6,9), 7), I(6,9)));
41   BOOST_CHECK(equal(fmod(6, I(7,8)), I(6,6)));
42   BOOST_CHECK(equal(fmod(I(6,9), I(7,8)), I(6,9)));
43 
44   BOOST_CHECK(equal(fmod(I(13,17), 7), I(6,10)));
45   BOOST_CHECK(equal(fmod(13, I(7,8)), I(5,6)));
46   BOOST_CHECK(equal(fmod(I(13,17), I(7,8)), I(5,10)));
47 
48   BOOST_CHECK(equal(fmod(I(-17,-13), 7), I(4,8)));
49   BOOST_CHECK(equal(fmod(-17, I(7,8)), I(4,7)));
50   BOOST_CHECK(equal(fmod(I(-17,-13), I(7,8)), I(4,11)));
51 
52   return 0;
53 }
54