Algebraic Real NumbersThe data type real approximates mathematics' real numbers. It most powerful number type.ExampleThe following program shows a computation where the exact real arithmetic evaluates to zero in contrast to floating point arithmetic. Notice that the explicit cast of the numbers 12 and 17 is really necessary, here. Otherwise the right hand side is evaluated with double arithmetic.#include <LEDA/numbers/real.h> using namespace leda; int main() { real x; x=(sqrt(real(17))-sqrt(real(12))); x*=(sqrt(real(17))+sqrt(real(12))); x-=5; if (x==0) std::cout << "x==0\n"; else std::cout << "x!=0\n"; double xd; xd=(sqrt(17)-sqrt(12)); xd*=(sqrt(17)+sqrt(12)); xd-=5; if (xd==0) std::cout << "xd==0\n"; else std::cout << "xd!=0\n"; return 0; } Strengths
Disadvantages
TipUse reals to do exact computations with square roots and k-th roots. Otherwise consider using Big Floatingpoint Numbers. |
See also:Vectors and Matrices with Integer Entries Vectors and Matrices with Double Entries Functions of numerical analysis Manual Entries: Manual Page Algebraic Real Numbers
|