1 | /* Boost test/pi.cpp |
---|
2 | * test if the pi constant is correctly defined |
---|
3 | * |
---|
4 | * Copyright 2002-2003 Guillaume Melquiond, Sylvain Pion |
---|
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.hpp> |
---|
12 | #include <boost/limits.hpp> |
---|
13 | #include <boost/test/minimal.hpp> |
---|
14 | #include "bugs.hpp" |
---|
15 | |
---|
16 | #define PI 3.14159265358979323846 |
---|
17 | |
---|
18 | typedef boost::numeric::interval<int> I_i; |
---|
19 | typedef boost::numeric::interval<float> I_f; |
---|
20 | typedef boost::numeric::interval<double> I_d; |
---|
21 | typedef boost::numeric::interval<long double> I_ld; |
---|
22 | |
---|
23 | using boost::numeric::interval_lib::pi; |
---|
24 | using boost::numeric::interval_lib::pi_half; |
---|
25 | using boost::numeric::interval_lib::pi_twice; |
---|
26 | |
---|
27 | int test_main(int, char *[]) { |
---|
28 | I_i pi_i = pi<I_i>(); |
---|
29 | I_f pi_f = pi<I_f>(); |
---|
30 | I_d pi_d = pi<I_d>(); |
---|
31 | I_ld pi_ld = pi<I_ld>(); |
---|
32 | |
---|
33 | BOOST_CHECK(in((int) PI, pi_i)); |
---|
34 | BOOST_CHECK(in((float) PI, pi_f)); |
---|
35 | BOOST_CHECK(in((double)PI, pi_d)); |
---|
36 | BOOST_CHECK(subset(pi_i, widen(I_i((int) PI), 1))); |
---|
37 | BOOST_CHECK(subset(pi_f, widen(I_f((float) PI), (std::numeric_limits<float> ::min)()))); |
---|
38 | BOOST_CHECK(subset(pi_d, widen(I_d((double)PI), (std::numeric_limits<double>::min)()))); |
---|
39 | |
---|
40 | // We can't test the following equalities for interval<int>. |
---|
41 | I_f pi_f_half = pi_half<I_f>(); |
---|
42 | I_f pi_f_twice = pi_twice<I_f>(); |
---|
43 | |
---|
44 | I_d pi_d_half = pi_half<I_d>(); |
---|
45 | I_d pi_d_twice = pi_twice<I_d>(); |
---|
46 | |
---|
47 | I_ld pi_ld_half = pi_half<I_ld>(); |
---|
48 | I_ld pi_ld_twice = pi_twice<I_ld>(); |
---|
49 | |
---|
50 | BOOST_CHECK(equal(2.0f * pi_f_half, pi_f)); |
---|
51 | BOOST_CHECK(equal(2.0 * pi_d_half, pi_d)); |
---|
52 | BOOST_CHECK(equal(2.0l * pi_ld_half, pi_ld)); |
---|
53 | |
---|
54 | BOOST_CHECK(equal(2.0f * pi_f, pi_f_twice)); |
---|
55 | BOOST_CHECK(equal(2.0 * pi_d, pi_d_twice)); |
---|
56 | BOOST_CHECK(equal(2.0l * pi_ld, pi_ld_twice)); |
---|
57 | |
---|
58 | return 0; |
---|
59 | } |
---|