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

Collection of numeric algorithms. More...

Functions

__int128 xgcd (__int128 p_a, __int128 p_b, __int128 *p_s, __int128 *p_t)
 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 isfloat128 (const std::string &p_str)
 Is the string a 128 bit float.
 
int32_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

◆ isfloat128()

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

Is the string a 128 bit float.

We accept loosing unsignificant digits.

Parameters
[in]p_strString 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,out]p_strThe string to check
Returns
bool ... To use in an assert.

◆ 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()

int32_t algo::rand ( uint32_t *  p_seed)

ISO C rand_r() for 32 bit.

Parameters
[in,out]p_seedRandom generator seed.
Returns
int32_t ... Pseudo random value between 0 and $ 2^{31}-1 $.

◆ xgcd()

__int128 algo::xgcd ( __int128  p_a,
__int128  p_b,
__int128 *  p_s,
__int128 *  p_t 
)

Extended Euclidean algorithm.

Calculates the gcd of both input integers and additionally calculates
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.
[out]p_sA Bézout coefficient of p_a.
[out]p_tA Bézout coefficient of p_b.
Postcondition
gcd(a,b) = p_s*p_a + p_t*p_b
Returns
__int128 ... gcd of p_a and p_b.