Permission to use, copy,
and distribute this software and
It’s documentation for any non commercial purpose is hereby granted without fee,
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO
EVENT SHALL Henrik Vestermark, BE LIABLE FOR ANY
SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY
OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Arbitrary precision package. (Revised January 2017)
Arbitrary precision for integers, floating points, complex numbers etc. Nearly everything is here!. A collections of 4 C++ header files. One for arbitrary integer precision, one for arbitrary floating point precision, a portable complex template<class T> and finally a portable interval arithmetic template<class T>.
All standard C++ operators are supported plus all trigonometric and logarithm functions like exp(),log(), log10(), exp(), sin(), cos(), tan(), atan(), asin()(, acos(), atan2() and of course pow() and sqrt(). Recently we added the following hyperbolic functions: sinh(), cosh(), tanh(), asinh(), acosh() and atanh() and the n-th root of a number nroot().
Furthermore for each floating precision numbers the working rounding mode for arithmetic operations can be controlled. Four rounding modes are supported. Round to nearest, Round up, round down and round towards zero, makes it easy to implement interval arithmetic, which mean you can now get a precise bound of the error for every floating point calculations!
Universal constant like π, Ln(2), Ln(10) and Exp(1) exist in arbitrary precision.
Technically the number of digits for a number that can be handle are around 4 Billions digits, however most likely you will run into system limitation before that. However we have been working with number that exceed 10-100 million digits without any issues!
Click here to download the user manual Download
Also dont forget to check out our document the math behind arbitrary precision.Click for here for Download
| Why use this package instead of Gnu's GMP?
It has less restrictive permission rules.
It support all relevant trigonometric, logarithms and exponential functions like exp(), log(), sin(), cos() etc. which GMP does not
It's born as a C++ class and not a C library with a C++ wrapper.
You also have rounding controls which GMP does not have.
π, Ln 2, Ln 10 is available in arbitrary precision.
Easier to use
|Why use Gnu's GMP
Because it's GNU!
Faster and more choices on basic functions and algorithms
Gnu's GMP can be located at: www.gnu.org/software/gmp
|Please note that I did not developed this package to compete with Gnu's GMP but rather because I was missing features not found in GMP, however since I get a lot of questions why? I have tried to answer it above. Have fun.
Arbitrary Precision Math C++ Package. Include C++ header file & pdf documentation.
The current version is: (updated January 2017)
integer precision: 1.29
float precision: 1.29
complex Precision: 1.03
interval Precision: 1.15
precisioncore: 1.36 -- Dont forget to include this cpp file in your project file when compiling the code. Also note this was compiled with Microsoft Visual Studio c++ Express 2015. But should be easily portable to other environments.
In this release the sqrt() is 3 times faster using a new algorithm. the n-th root of a number is now available as a special function nroot(). Calculation of PI is now 3 times faster using the Brent-Salamin algorithm and the transcendental constants ln(2), ln(10), exp(1) is now 20-100 times faster than in previous version using a spigot algorithm.
A special thanks to Stephen Gertsch who improve the documentation dramatically.
Examples of using int_precision & float_precision:
int_precision a(11111111), d;
float_precision f1(10,64); // Initialized to zero and set precision to 64 digits
float_precision f2(2.0), f3(3), f4("0.12345678901234567890" );
d = a * a * a; // a^3
cout << "11111111^3=" << d << endl;
d /= a;
cout << "11111111^2=" << d << endl;
f1 = log( f1 );
f1 *= f2 + f3 / f4;
f1 = _float_table( _PI, 48 ); // Get PI with 48 decimals
cout << "PI with 48 digits:" << f1 << endl;
f1 = float_precision( 2 );
f1 = sqrt( f1 );
cout << "Sqrt(2) with 48 digits:" << f1 << endl;
For integer precision the following extra functions are available:
int_precision ipow( const int_precision&, const int_precision& ) // a^b
int_precision ipow_modular( const int_precision&, const int_precision&, const int_precision& ) // a^b%c
bool iprime( const int_precision& ) // Fast function to check if a int_precision
number is a prime.
For floating point precision the following extra functions are available:
float_precision modf( float_precision, float_precision * )
float_precision fmod( float_precision, float_precision )
float_precision floor( float_precision )
float_precision ceil( float_precision )
float_precision frexp( float_precision, int * )
float_precision ldexp( float_precision, int )
Internal Base of the Numbers
To enhanced the effectiveness or for experimental test the Internal base that a number is represented in can be choosen as either BASE 2, 8, 10, 16 or 256. Default is BASE 10. You can edit the header file iprecision.h or fprecision.h to change the base.
Example using complex_precision and float_precision
// This example show how to evaluate a polynomial with complex coeeficients a at a complex point z. The evaluation is done using
// the precision of z and using Horner algorithm
complex_precision<float_precision> horner( const register int n, const complex_precision<float_precision> a,
const complex_precision<float_precision> z )
fval = a[ 0 ];
for( int i = 1; i <= n; i++ ) fval = fval * z + a[ i ];