Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/numeric/interval/examples/rational.cpp @ 29

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

updated boost from 1_33_1 to 1_34_1

File size: 1.3 KB
Line 
1/* Boost example/rational.cpp
2 * example program of how to use interval< rational<> >
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// it would have been enough to only include:
12//   <boost/numeric/interval.hpp>
13// but it's a bit overkill to include processor intrinsics
14// and transcendental functions, so we do it by ourselves
15
16#include <boost/numeric/interval/interval.hpp>      // base class
17#include <boost/numeric/interval/rounded_arith.hpp> // default arithmetic rounding policy
18#include <boost/numeric/interval/checking.hpp>      // default checking policy
19#include <boost/numeric/interval/arith.hpp>         // += *= -= etc
20#include <boost/numeric/interval/policies.hpp>      // default policy
21
22#include <boost/rational.hpp>
23#include <iostream>
24
25typedef boost::rational<int> Rat;
26typedef boost::numeric::interval<Rat> Interval;
27
28std::ostream& operator<<(std::ostream& os, const Interval& r) {
29  os << "[" << r.lower() << "," << r.upper() << "]";
30  return os;
31}
32
33int main() {
34  Rat p(2, 3), q(3, 4);
35  Interval z(4, 5);
36  Interval a(p, q);
37  a += z;
38  z *= q;
39  a -= p;
40  a /= q;
41  std::cout << z << std::endl;
42  std::cout << a << std::endl;
43}
Note: See TracBrowser for help on using the repository browser.