Polymake Template Library (PTL): Number Types, Borrowed from GMP
Polymake Template Library (PTL)  4.2
Number Types, Borrowed from GMP

Most calculations in polymake are made exactly, using rational numbers. The best implementation known to us which provides arbitrary precision and high-tuned performance on various computer platforms, is http://www.swox.com/gmp/ . On the other hand, we did like very much the convenient interface of the Rational and Integer classes from the (in the meanwhile obsolete and no more supported) libg++, which allowed to use the rational values in expressions in the most natural way, as if they were built-in numeric types. So we have decided to union the advantages of both and have written thin wrapper classes mimicking the old Rational and Integer classes. They perform almost no calculations on their own, but delegate the whole hard job to GMP functions.

In the meanwhile, GMP has got its own C++ wrapper classes. They are implemented differently from our classes: all arithmetic operators are "lazy", returning expression templates instead of ready results. While this technique has proven to improve the performance in longer chained expressions, and is massively used in polymake vector and matrix classes too, we consider it a bit dangerous for the basic numerical type.

In an innocent expression like (a+b)*M, where a and b are rational scalars and M is a rational matrix, the sum a+b would be repeatedly calculated for each element of the resulting matrix. Since such mixed expressions are prevailing in polymake code, we have decided to stay with our own wrappers, relying on the so called return value optimization of the compiler. Future changes in GMP may let us revise this decision.

GMP numbers can be constructed from the most built-in types. They can be converted to each other and to the most built-in types.