Dynamic Fraction Library 1.0.0
Reference-counted arbitrary precision rational number library (MIT OR Unlicense)
Loading...
Searching...
No Matches
Functions
Advanced Mathematical Operations

Advanced mathematical functions for arbitrary precision integers. More...

Functions

di_int di_mod_pow (di_int base, di_int exp, di_int mod)
 Modular exponentiation: (base^exp) mod mod.
 
di_int di_gcd (di_int a, di_int b)
 Greatest Common Divisor using Euclidean algorithm.
 
di_int di_lcm (di_int a, di_int b)
 Least Common Multiple.
 
di_int di_extended_gcd (di_int a, di_int b, di_int *x, di_int *y)
 Extended Euclidean Algorithm.
 
di_int di_sqrt (di_int n)
 Integer square root using Newton's method.
 
di_int di_factorial (uint32_t n)
 Calculate factorial.
 

Detailed Description

Advanced mathematical functions for arbitrary precision integers.

Function Documentation

◆ di_extended_gcd()

di_int di_extended_gcd ( di_int  a,
di_int  b,
di_int x,
di_int y 
)

Extended Euclidean Algorithm.

Parameters
aFirst integer (may be NULL)
bSecond integer (may be NULL)
xPointer to store coefficient x
yPointer to store coefficient y
Returns
GCD of a and b, with coefficients such that ax + by = gcd(a,b)
Since
1.0.0
Note
Sets *x and *y to coefficients satisfying the Bezout identity

Definition at line 2622 of file dynamic_int.h.

◆ di_factorial()

di_int di_factorial ( uint32_t  n)

Calculate factorial.

Parameters
nNon-negative integer
Returns
New di_int with n! (n factorial), or NULL on failure
Since
1.0.0
di_int fact5 = di_factorial(5); // 120
di_int fact10 = di_factorial(10); // 3628800
struct di_int_internal * di_int
Integer handle for arbitrary precision integers.
di_int di_factorial(uint32_t n)
Calculate factorial.

Definition at line 2350 of file dynamic_int.h.

◆ di_gcd()

di_int di_gcd ( di_int  a,
di_int  b 
)

Greatest Common Divisor using Euclidean algorithm.

Parameters
aFirst integer (may be NULL)
bSecond integer (may be NULL)
Returns
New di_int with GCD of |a| and |b|, or NULL on failure
Since
1.0.0
See also
di_lcm() for Least Common Multiple
di_extended_gcd() for Extended Mathematical Operations Euclidean algorithm

Definition at line 2237 of file dynamic_int.h.

◆ di_lcm()

di_int di_lcm ( di_int  a,
di_int  b 
)

Least Common Multiple.

Parameters
aFirst integer (may be NULL)
bSecond integer (may be NULL)
Returns
New di_int with LCM of a and b, or NULL on failure
Since
1.0.0
Note
Uses identity: lcm(a,b) = |a*b| / gcd(a,b)
See also
di_gcd() for Greatest Common Divisor

Definition at line 2272 of file dynamic_int.h.

◆ di_mod_pow()

di_int di_mod_pow ( di_int  base,
di_int  exp,
di_int  mod 
)

Modular exponentiation: (base^exp) mod mod.

Parameters
baseBase integer (may be NULL)
expExponent integer (may be NULL)
modModulus integer (may be NULL)
Returns
New di_int with result of (base^exp) mod mod, or NULL on failure
Since
1.0.0
Note
Returns NULL if mod is zero or one
Uses binary exponentiation for efficiency

Definition at line 2376 of file dynamic_int.h.

◆ di_sqrt()

di_int di_sqrt ( di_int  n)

Integer square root using Newton's method.

Parameters
nInteger to find square root of (may be NULL)
Returns
New di_int with floor(sqrt(n)), or NULL on failure
Since
1.0.0
Note
Returns NULL for negative inputs

Definition at line 2301 of file dynamic_int.h.