Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-09-04 15:20:15


Since some may not have bothered to look at this interesting/amusing example
added by Sylvain Pion at my 'request', I show it below:

// Example program of how to use interval<> of rational<> numbers.
//
// Sylvain Pion, 2002.

#include <iostream>
#include <boost/interval.hpp>
#include <boost/rational.hpp>

using boost::interval;
using boost::rational;

typedef rational<double> Rat;
typedef interval<Rat> Interval;

int main() {
  Rat r(0), p(2, 3), q(3, 4);
  Interval z(0);
  Interval a(p, q);
  a += z;
  z *= z;
  a -= p;
  a /= q;
  std::cout << z << std::endl;
  std::cout << a << std::endl;
}

On Tue, Sep 03, 2002 at 05:41:23PM +0100, Paul A. Bristow wrote:
> And an example of use with a bigint type would provide proof of
> extensibility.

There's no bigint in Boost :(, so I attach an example program using
boost::rational<double>, which I have just committed as
examples/rational.cpp.
(an exact rounding policy would need some work, but rational<double> is
probably non-sense anyway in practice, we'd need a bigint.)
E.g. using the MPFR as bigint, using the rounding modes from there, will
be a target.

The library is definitely meant to support that kind of things.

> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]]On Behalf Of Sylvain Pion
> Sent: Wednesday, September 04, 2002 5:16 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Formal Review for Interval Library beginning
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk