Leonardus
Loading...
Searching...
No Matches
Functions
algo Namespace Reference

Collection of numeric algorithms. More...

Functions

std::tuple< __int128, __int128, __int128 > xgcd (__int128 p_a, __int128 p_b)
 Extended Euclidean algorithm.
 
bool isint128 (const std::string &p_str)
 Is the string a 128 bit integer.
 
bool isint128 (const mpz_t p_x)
 Is the multiple precision integer a 128 bit integer.
 
bool hasFloatSyntax (const std::string &p_str)
 Checks, if the string has the syntax of a float.
 
bool hasRationalSyntax (const std::string &p_str)
 Checks, if the string has the syntax of a rational number.
 
bool isSquareFree (__int128 p_n)
 Checks if an integer is square free.
 
std::pair< int32_t, uint32_t > rand (uint32_t p_seed)
 ISO C rand_r() for 32 bit.
 
__int128 mmod (__int128 p_d, __int128 p_m)
 Mathematical modulus.
 

Detailed Description

Collection of numeric algorithms.

Function Documentation

◆ hasFloatSyntax()

bool algo::hasFloatSyntax ( const std::string &  p_str)

Checks, if the string has the syntax of a float.

This pure syntax check does not apply the size limits of a 128 bit float.

Parameters
[in]p_strThe string to check.
Returns
bool ... To use in an assert.

◆ hasRationalSyntax()

bool algo::hasRationalSyntax ( const std::string &  p_str)

Checks, if the string has the syntax of a rational number.

The regex has to match: [-+]?[0-9]+:[0-9]*[1-9][0-9]*

Parameters
[in]p_strThe string to check.
Returns
bool ... To use in an assert.

◆ isint128() [1/2]

bool algo::isint128 ( const mpz_t  p_x)

Is the multiple precision integer a 128 bit integer.

Parameters
[in]p_xmpz_t to check.
Returns
bool ... For an assert.

◆ isint128() [2/2]

bool algo::isint128 ( const std::string &  p_str)

Is the string a 128 bit integer.

Parameters
[in]p_strThe string to check
Returns
bool ... To use in an assert.

◆ isSquareFree()

bool algo::isSquareFree ( __int128  p_n)

Checks if an integer is square free.

0 is per definition not square free.

Parameters
[in]p_nThe integer to check.
Returns
bool ... true, if the integer is square free.

◆ mmod()

__int128 algo::mmod ( __int128  p_d,
__int128  p_m 
)
inline

Mathematical modulus.

It differs from C++ 11 and newer,
which defines the calculation of a remainder such that (a/b)*b + ab = a.

Parameters
[in]p_dThe dividend.
[in]p_mThe modulus.
Returns
__int128 ... The remainder.

◆ rand()

std::pair< int32_t, uint32_t > algo::rand ( uint32_t  p_seed)

ISO C rand_r() for 32 bit.

Parameters
[in]p_seedRandom generator seed.
Returns
std::pair<int32_t,int32_t> ...
- Pseudo random value between 0 and $ 2^{31}-1 $.
- The new seed value.

◆ xgcd()

std::tuple< __int128, __int128, __int128 > algo::xgcd ( __int128  p_a,
__int128  p_b 
)

Extended Euclidean algorithm.

Calculates the gcd of both input integers as well as
a pair of Bézout coefficients s and t such that gcd(a,b) = s*a + t*b.
Returns 0 if both p_a and p_b are 0.

Parameters
[in]p_aFirst input number.
[in]p_bSecond input number.
Postcondition
gcd(a,b) = p_s*p_a + p_t*p_b
Returns
std::tuple<__int128, __int128, __int128> ...
- The gcd of p_a and p_b (first element).
- The Bézout coefficient s for p_a (second element).
- The Bézout coefficient t for p_b (third element).