y-cruncher Multi-Precision Library

A Multi-threaded Multi-Precision Arithmetic Library

(Powered by y-cruncher)

(Last updated: March 7, 2016)

 

Shortcuts:

YMP Library:

Large Number Objects:

Low-Level Programming:

BigFloatO - Large Floating-Point (with RAII)

 

BigFloatO is an ownership subclass of BigFloat.

 

 

Ownership subclasses are standard RAII objects that can be copied and moved. While they are easy to use, they also have tremendous overhead from memory allocation and page-commit. If utmost maximum performance is desired, consider using the raw classes intstead.

 

Ownership classes are designed for scripting and research. They are not used in y-cruncher. Most functions for ownership classes are implemented as wrappers over their counterparts from the raw classes.

 

More on "ownership" classes.

 

 

Most functions that require large multiplication have two versions: One with and one without the mp parameter that allows control over the "hidden parameters" required for large multiplication.

 

Some functions require more scratch buffers in addition to the one in the mp parameter. These extra scratch buffers are allocated automatically and currently cannot be controlled with the BigFloatO class. Users wishing to bypass even these memory allocations will be required to use BigFloatR instead.

 

 

 

Function List:

 

Inherited from BigFloat:

Constructors:

Basic Arithmetic:

Large Multiplication:

Functions Library:

 

Constructors:

 

Default:

BigFloatO<u32_t>::BigFloatO ();

BigFloatO<u64_t>::BigFloatO ();

 

Construct a new object with the value of zero.

 

Small Integer:

BigFloatO<u32_t>::BigFloatO (u32_t x);

BigFloatO<u64_t>::BigFloatO (u32_t x);

 

BigFloatO<u32_t>::BigFloatO (s32_t x);

BigFloatO<u64_t>::BigFloatO (s32_t x);

 

BigFloatO<u32_t>::BigFloatO (uiL_t x);

BigFloatO<u64_t>::BigFloatO (uiL_t x);

 

BigFloatO<u32_t>::BigFloatO (siL_t x);

BigFloatO<u64_t>::BigFloatO (siL_t x);

 

Construct a new object with a value of x.

 

Bignum Object:

BigFloatO<u32_t>::BigFloatO (const BasicInt<u32_t>& x);

BigFloatO<u64_t>::BigFloatO (const BasicInt<u64_t>& x);

 

BigFloatO<u32_t>::BigFloatO (const ExactFloat<u32_t>& x);

BigFloatO<u64_t>::BigFloatO (const ExactFloat<u64_t>& x);

 

BigFloatO<u32_t>::BigFloatO (const BigFloat<u32_t>& x);

BigFloatO<u64_t>::BigFloatO (const BigFloat<u64_t>& x);

 

Construct a new object with a value of x. These constructors perform a copy of the value from x into the new object.

 

Basic Arithmetic:

 

Negate:

void BigFloatO<u32_t>::negate ();

void BigFloatO<u64_t>::negate ();

Description:

Negates this object.

Performance:

 


Strip Trailing Zeros:

void BigFloatO<u32_t>::strip_tzs_all ();

void BigFloatO<u64_t>::strip_tzs_all ();

Description:

Remove all trailing zeros from the representation of the current object.

 

While this has no effect on the numerical value of the current object, shortening the internal size may speed up subsequent operations on it.

Performance:

 


Multiply by Power-of-Two:

void BigFloatO<u32_t>::operator<<= (siL_t pow);

void BigFloatO<u64_t>::operator<<= (siL_t pow);

Description:

Multiplies this object by 2pow. Negative pow implies by division power-of-two.

This operation is done without loss of any precision.

Performance:

 


Single-Word Multiply:

void BigFloatO<u32_t>::operator*= (u32_t x);

void BigFloatO<u64_t>::operator*= (u64_t x);

Description:

Multiplies this object by x.

This operation is done without loss of any precision.

Performance:

 


Addition/Subtraction:

BigFloatO<u32_t> add (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

BigFloatO<u64_t> add (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

 

BigFloatO<u32_t> sub (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

BigFloatO<u64_t> sub (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

 

void BigFloatO<u32_t>::set_add (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

void BigFloatO<u64_t>::set_add (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

 

void BigFloatO<u32_t>::set_sub (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

void BigFloatO<u64_t>::set_sub (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

Description:

Computes A + B or A - B.

 

The result will have an error no more than base-p relative to the larger input (in magnitude).

The rounding behavior is not defined. Though the current implementation truncates towards zero.

Variants:

Performance:

 

Large Multiplication:

 

Large Multiplication - Basic:

BigFloatO<u32_t> sqr (const BigFloat<u32_t>& A, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> sqr (const BigFloat<u64_t>& A, upL_t p, upL_t tds = 1);

 

BigFloatO<u32_t> mul (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> mul (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p, upL_t tds = 1);

 

void BigFloatO<u32_t>::set_sqr (const BigFloat<u32_t>& A, upL_t p, upL_t tds = 1);

void BigFloatO<u64_t>::set_sqr (const BigFloat<u64_t>& A, upL_t p, upL_t tds = 1);

 

void BigFloatO<u32_t>::set_mul (const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p, upL_t tds = 1);

void BigFloatO<u64_t>::set_mul (const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p, upL_t tds = 1);

Large Multiplication - Parameter Controlled:

BigFloatO<u32_t> sqr (const BasicParameters& mp, const BigFloat<u32_t>& A, upL_t p);

BigFloatO<u64_t> sqr (const BasicParameters& mp, const BigFloat<u64_t>& A, upL_t p);

 

BigFloatO<u32_t> mul (const BasicParameters& mp, const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

BigFloatO<u64_t> mul (const BasicParameters& mp, const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

 

void BigFloatO<u32_t>::set_sqr (const BasicParameters& mp, const BigFloat<u32_t>& A, upL_t p);

void BigFloatO<u64_t>::set_sqr (const BasicParameters& mp, const BigFloat<u64_t>& A, upL_t p);

 

void BigFloatO<u32_t>::set_mul (const BasicParameters& mp, const BigFloat<u32_t>& A, const BigFloat<u32_t>& B, upL_t p);

void BigFloatO<u64_t>::set_mul (const BasicParameters& mp, const BigFloat<u64_t>& A, const BigFloat<u64_t>& B, upL_t p);

Description:

Computes A2 or A * B.

 

The result will have an error no more than base-p relative to a correct result (as if it were done using infinite precision).

The rounding behavior is not defined.

Parameters:

Variants:

Performance:

BasicParameter (mp) Required Fields:

 

Functions Library:

 

Addition, subtraction, and multiplication are the only operations that are supported by the class itself. Everything else is implemented separately in a functions library.

Most functions here are thin wrappers over native implementations in y-cruncher. So they have access to optimizations that are only possible via the internal interface.

 


Object to Hexadecimal String:

std::string to_string_hex (const BigFloat<u32_t>& x, upL_t digits);

std::string to_string_hex (const BigFloat<u64_t>& x, upL_t digits);

Description:

Converts x to a string representation in base 16 with at most digits significant digits.

 

The rounding behavior is unspecified. But the current implementation truncates towards zero.

The function will auto-select between floating and scientific notation.

Performance:

 


Object to Decimal String:

std::string to_string_dec (const BigFloat<u32_t>& x, upL_t digits, upL_t tds = 1);

std::string to_string_dec (const BigFloat<u64_t>& x, upL_t digits, upL_t tds = 1);

Description:

Converts x to a string representation in base 10 with at most digits significant digits.

 

The rounding behavior is unspecified. But the current implementation usually truncates towards zero.

The function will auto-select between floating and scientific notation.

 

Note that the current implementation of this function suffers heavily from Amdahl's Law - the serial part being the string formatting and the final conversion to std::string.

Parameters:

Performance:

 


Reciprocal and Division - Basic:

BigFloatO<u32_t> rcp (const BigFloat<u32_t>& A, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> rcp (const BigFloat<u64_t>& A, upL_t p, upL_t tds = 1);

 

BigFloatO<u32_t> div (const BigFloat<u32_t>& N, const BigFloat<u32_t>& D, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> div (const BigFloat<u64_t>& N, const BigFloat<u64_t>& D, upL_t p, upL_t tds = 1);

Reciprocal and Division - Parameter Controlled:

void rcp (const BasicParameters& mp, BigFloatO<u32_t>& T, const BigFloat<u32_t>& A, upL_t p);

void rcp (const BasicParameters& mp, BigFloatO<u32_t>& T, const BigFloat<u64_t>& A, upL_t p);

 

void rcp_sizes<u32_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

void rcp_sizes<u64_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

 

void div (const BasicParameters& mp, BigFloatO<u32_t>& T, const BigFloat<u32_t>& N, const BigFloat<u32_t>& D, upL_t p);

void div (const BasicParameters& mp, BigFloatO<u32_t>& T, const BigFloat<u64_t>& N, const BigFloat<u64_t>& D, upL_t p);

 

void div_sizes<u32_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

void div_sizes<u64_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

Description:

Computes 1/A or N/D and returns the result. Division by zero will throw an exception.

 

The result will have an error no more than base-p relative to a correct result (as if it were done using infinite precision).

The rounding behavior is not defined.

 

The minimum size of {mp.M, mp.ML} can be obtained by calling rcp_sizes() and div_sizes() respectively. While these sizing functions are intended for the BigFloatR class, they are applicable here as well.

Parameters:

Performance:

BasicParameter (mp) Required Fields:

 


Inverse Square Root (Single Word) - Basic:

BigFloatO<u32_t> invsqrt_uW (u32_t x, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> invsqrt_uW (u64_t x, upL_t p, upL_t tds = 1);

Inverse Square Root (Single Word) - Parameter Controlled:

void invsqrt_uW (const BasicParameters& mp, BigFloatR<u32_t>& T, u32_t x, upL_t p);

void invsqrt_uW (const BasicParameters& mp, BigFloatR<u64_t>& T, u64_t x, upL_t p);

 

void invsqrt_uW_sizes<u32_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

void invsqrt_uW_sizes<u64_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

Description:

Computes 1 / sqrt(x) and returns the result. Division by zero will throw an exception.

 

The result will have an error no more than base-p relative to a correct result (as if it were done using infinite precision).

The rounding behavior is not defined.

 

The minimum size of {mp.M, mp.ML} can be obtained by calling invsqrt_uW_sizes(). While this sizing function is intended for the BigFloatR class, it is applicable here as well.

Parameters:

Performance:

BasicParameter (mp) Required Fields:

 


Square Root - Basic:

BigFloatO<u32_t> invsqrt (const BigFloat<u32_t>& x, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> invsqrt (const BigFloat<u64_t>& x, upL_t p, upL_t tds = 1);

 

BigFloatO<u32_t> sqrt (const BigFloat<u32_t>& x, upL_t p, upL_t tds = 1);

BigFloatO<u64_t> sqrt (const BigFloat<u64_t>& x, upL_t p, upL_t tds = 1);

Description:

Computes 1 / sqrt(x) or sqrt(x) and returns the result. Division by zero will throw an exception.

 

The result will have an error no more than base-p relative to a correct result (as if it were done using infinite precision).

The rounding behavior is not defined.

 

There are currently no BigFloatR or parameter controlled versions of these functions.

Parameters:

Performance:

 


Power Function (Integer Power) - Basic:

void pow_sL (BigFloatR<u32_t>& T, u32_t x, siL_t pow, upL_t p, upL_t tds = 1);

void pow_sL (BigFloatR<u64_t>& T, u64_t x, siL_t pow, upL_t p, upL_t tds = 1);

Power Function (Integer Power) - Parameter Controlled:

void pow_sL (const BasicParameters& mp, BigFloatR<u32_t>& T, u32_t x, siL_t pow, upL_t p);

void pow_sL (const BasicParameters& mp, BigFloatR<u64_t>& T, u64_t x, siL_t pow, upL_t p);

 

void pow_sL_sizes<u32_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

void pow_sL_sizes<u64_t> (uiL_t& Tsize, uiL_t& Psize, uiL_t& Msize, uiL_t p, upL_t tds);

Description:

Computes xpow. The result is stored into T overwriting it. Division by zero will throw an exception. 00 is undefined.

 

The result will have an error no more than base-p relative to a correct result (as if it were done using infinite precision).

The rounding behavior is not defined.

 

The minimum size of {mp.M, mp.ML} can be obtained by calling pow_sL_sizes(). While this sizing function is intended for the BigFloatR class, it is applicable here as well.

 

Currently, there is only support for integerinteger. This will likely be extended to BigFloatinteger in a later version.

Support for BigFloatBigFloat will be more difficult as that requires exp() which requires log() which requires AGM() which requires sqrt(). And none of these are currently supported.

Parameters:

Performance:

BasicParameter (mp) Required Fields: