Skip to content

Instantly share code, notes, and snippets.

@t-uda
Created June 16, 2012 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-uda/2941941 to your computer and use it in GitHub Desktop.
Save t-uda/2941941 to your computer and use it in GitHub Desktop.
boost::numeric::interval<int>(1): C++ Boost 区間演算ライブラリ 四則演算と基本的な関数 ref: http://qiita.com/items/e4f554b8af864b638a6d
a = 1.7
b = 3.3
a + b = [5,5]w(8.88178e-16)
a - b = [-1.6,-1.6]w(0)
a * b = [5.61,5.61]w(8.88178e-16)
a / b = [0.515152,0.515152]w(1.11022e-16)
#include <iostream>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
int main () {
typedef double R;
typedef boost::numeric::interval<R> IR;
using std::cout;
using std::endl;
const IR a(1.0, 2.0);
const IR b(3.0, 4.0);
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a / b = " << a / b << endl;
return 0;
}
#include <iostream>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
int main () {
typedef double R;
typedef boost::numeric::interval<R> IR;
using std::cout;
using std::endl;
const IR a(1.0, 2.0);
const R b = 3.0;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a / b = " << a / b << endl;
return 0;
}
#include <iostream>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
int main () {
typedef double R;
typedef boost::numeric::interval<R> IR;
using std::cout;
using std::endl;
const R a = 1.7;
const R b = 3.3;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
{
using namespace boost::numeric::interval_lib;
cout << "a + b = " << add<IR>(a, b) << "w(" << width(add<IR>(a, b)) << ")" << endl;
cout << "a - b = " << sub<IR>(a, b) << "w(" << width(sub<IR>(a, b)) << ")" << endl;
cout << "a * b = " << mul<IR>(a, b) << "w(" << width(mul<IR>(a, b)) << ")" << endl;
cout << "a / b = " << div<IR>(a, b) << "w(" << width(div<IR>(a, b)) << ")" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment