MPFRCPP Frequently Asked Questions

Design Issues

Why MPFRCPP functions are global objects?

Library was designed for professional computations with interval arithmetic. MPFRCPP uses functors (functions-objects) to allow user change parameters such a precision and round mode more efficiently.

Functions are based on NumericFunction class; NumericFunctions is a special container for synchronous changing of parameters.

There are a lot of repetitive code in functor definitions. Why common template code wasn't used?

Yes, MPFR function syntax is common, but MPFR definitions are too complex and some MPFR items are macro.

Are there pre-compiled binaries for MPFRCPP?

MPFRCPP goes as a sources set only. If you want to increase compilation time, use the pre-compiled headers feature.

Why do you use Base, Precision, RoundMode classes instead of primitive scalar types?

If base, precision, round mode are simple integers differ by typedef (as they are in MPFR, GMP and first versions of MPFRCPP), it's very hard to prevent potential errors with polymorphic methods and default parameters.

For example, is Real (100) stays for number 100 or number with mantissa width of 100?

Can I patch MPFRCPP?

You can do everything allowed by LGPL. Please, take time to share your patches with me — maybe it will be useful to include them in further versions.


Building and Running Programs

Code using MPFRCPP compiled successfully, but linking failed.

Since MPFRCPP is a wrapper to MPFR and GMP, you need to link mpfr and lgmp libraries. In g++ you need to add references -lmpfr and -lgmp:

g++ foo.c -lmpfr -lgmp

Program crashes with high precisions.

Your stack size limit may be too small. Increase it with the limit, unlimit or ulimit command, depending on your shell.

I can't compare mpfrcpp::Real with POD-type number.

You should compare mpfrcpp::Real with other types explicitly:

x > mpfrcpp::Real(y)

If you found this too strict, you can apply a quick hack. For example:

template<typename T> inline bool operator<
    (const mpfrcpp::Real& x,const  T& y) {
    return x < mpfrcpp::Real(y);
}

We are decided not to include this hack in major distribution.

Program crashes with ComparisonWithNaNError.

Any comparison could throw the ComparisonWithNaNError exception. NaN result for some computation on IEEE arithmetic is usual case, but if you are trying to compare NaN result with other number, it seems to be an error. ComparisonWithNaNError should help you to catch unserved special cases.


Miscellaneous

Could you write the same wrapper for other language?

I plan to start work on JMPFR, the Java Branch. Contact me, if you are interested.

What coding standard you are using?

We are using Herb Sutter's coding standard (with some specific modifications). For example:

FooBarBazfunctor object, i.e. object of class with operator() overloaded
FooBarBazClassfunctor class, i.e. class with operator() overloaded
fooBarBazfunction or class method
FooBarBazclass
fooBarBaz_protected or private class field

Do not mix up functions and functors. For example, Asin is a functor calculating arc-sine and asin is the function.

What is the NACRE?

NACRE stands for Numeric Analysis / Computer REsearch. It is a small library containing classes Polynomial<T>, Complex<T>, Rational<T>. Matrix<T> will be added soon. These classes are portable but simple and they were not oriented on high-performance computations.

NACRE templates are common and they could be used with MPFRCPP.