Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added boost

File size: 1.8 KB
Line 
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
18typedef boost::numeric::interval<int>         I_i;
19typedef boost::numeric::interval<float>       I_f;
20typedef boost::numeric::interval<double>      I_d;
21typedef boost::numeric::interval<long double> I_ld;
22
23using boost::numeric::interval_lib::pi;
24using boost::numeric::interval_lib::pi_half;
25using boost::numeric::interval_lib::pi_twice;
26
27int 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}
Note: See TracBrowser for help on using the repository browser.