Example Floating Point Filter, Interval, and Integer ComputationThe following program shows the usage of The resulting output shows that the sign in the #include <LEDA/numbers/floatf.h> #include <LEDA/numbers/integer.h> #include <LEDA/numbers/interval.h> using namespace leda; int SignExample(int Iter) { integer A=1314157,B=3,RES; floatf af(A),bf(B),resf; interval_round_inside ai(A), bi(B),resi; // integer computation int i; for (i=1;i<Iter;i++) A=A*B; B=A+1; RES=A-B; // floatf computation for (i=1;i<Iter;i++) af=af*bf; bf=af+floatf(1); resf=af-bf; // interval computation for (i=1;i<Iter;i++) ai=ai*bi; bi=ai+interval_round_inside(1); resi=ai-bi; if (Sign(resf)==NO_IDEA) std::cout<<"?"; else std::cout<< Sign(resf); cstd::out << "\t"; if (resi.sign_is_known()) std::cout << resi.sign(); else std::cout << "?"; std::cout<<"\t\t"; std::cout << sign(RES); std::cout << std::endl; return 0; } int main() { std::cout << "Sign-Example" << std::endl; std::cout << "------------" << std::endl << std::endl; std::cout << "Iterations\tfloatf\tinterval\tinteger" << std::endl; for (int i=5; i<=30; i++) { std::cout << i << "\t\t"; SignExample(i); } return 0; } |
See also:Manual Entries: Manual Page Floating Point Filter |