Skip to content

Instantly share code, notes, and snippets.

@t-uda
Created June 15, 2012 15:22
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/2937001 to your computer and use it in GitHub Desktop.
Save t-uda/2937001 to your computer and use it in GitHub Desktop.
boost::numeric::interval<int>(0): C++ Boost 区間演算ライブラリ 概要 ref: http://qiita.com/items/7712671389e016d24df6
$ g++ hello-interval.cpp -o hello-interval
$ ./hello-interval
[-1,2]
$ g++ test-interval-double.cpp -o test-interval-double
$ ./test-interval-double
eps = 1e-14
one = [1,1]
x = one + eps - one = [9.99201e-15,1.02141e-14]
width(x) = 2.22045e-16
eps is in x
$ clang++ test-interval-double.cpp -o test-interval-double
$ ./test-interval-double
eps = 1e-14
one = [1,1]
x = one + eps - one = [9.99201e-15,9.99201e-15]
width(x) = 0
eps is not in x
#include <iostream>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
int main () {
boost::numeric::interval<int> a(-1, 2);
std::cout << a << std::endl;
return 0;
}
#include <iostream>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
int main () {
using namespace std;
using namespace boost::numeric;
typedef double R;
typedef interval<R> IR;
const R eps(1.0e-14);
const IR one(1.0);
const IR x = one + eps - one;
cout << "eps = " << eps << endl;
cout << "one = " << one << endl;
cout << "x = one + eps - one = " << x << endl;
cout << "width(x) = " << width(x) << endl;
cout << "eps is " << (in(eps, x) ? "" : "not ") << "in x" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment