Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/interval/test/fmod.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 1.6 KB
Line 
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
20struct my_rounded_arith {
21  int sub_down(int x, int y) { return x - y; }
22  int sub_up  (int x, int y) { return x - y; }
23  int mul_down(int x, int y) { return x * y; }
24  int mul_up  (int x, int y) { return x * y; }
25  int div_down(int x, int y) {
26    int q = x / y;
27    return (x % y < 0) ? (q - 1) : q;
28  }
29  int int_down(int x) { return x; }
30};
31
32using namespace boost;
33using namespace numeric;
34using namespace interval_lib;
35
36typedef change_rounding<interval<int>, save_state_nothing<my_rounded_arith> >::type I;
37
38int 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}
Note: See TracBrowser for help on using the repository browser.