| 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 { |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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 | } |
|---|