Created
June 15, 2012 15:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ hello-interval.cpp -o hello-interval | |
$ ./hello-interval | |
[-1,2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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