Dynamic Complex Library 1.0.0
Reference-counted arbitrary precision complex number library (MIT OR Unlicense)
Loading...
Searching...
No Matches
Functions
Fraction Complex Functions

Functions for rational complex numbers. More...

Functions

dc_complex_frac dc_frac_from_ints (int64_t real_num, int64_t real_den, int64_t imag_num, int64_t imag_den)
 Create a rational complex number from integer components.
 
dc_complex_frac dc_frac_from_df (df_frac real, df_frac imag)
 Create a rational complex number from fraction components.
 
dc_complex_frac dc_frac_zero (void)
 Get the rational complex zero (0/1 + 0/1 i)
 
dc_complex_frac dc_frac_one (void)
 Get the rational complex one (1/1 + 0/1 i)
 
dc_complex_frac dc_frac_i (void)
 Get the rational complex i (0/1 + 1/1 i)
 
dc_complex_frac dc_frac_neg_one (void)
 Get the rational complex -1 (-1/1 + 0/1 i)
 
dc_complex_frac dc_frac_neg_i (void)
 Get the rational complex -i (0/1 + -1/1 i)
 
dc_complex_frac dc_frac_retain (dc_complex_frac c)
 Increment reference count and return the same object.
 
void dc_frac_release (dc_complex_frac *c)
 Decrement reference count and possibly free memory.
 
dc_complex_frac dc_frac_copy (dc_complex_frac c)
 Create a new copy with reference count 1.
 
dc_complex_frac dc_frac_add (dc_complex_frac a, dc_complex_frac b)
 Add two rational complex numbers.
 
dc_complex_frac dc_frac_sub (dc_complex_frac a, dc_complex_frac b)
 Subtract two rational complex numbers.
 
dc_complex_frac dc_frac_mul (dc_complex_frac a, dc_complex_frac b)
 Multiply two rational complex numbers.
 
dc_complex_frac dc_frac_div (dc_complex_frac a, dc_complex_frac b)
 Divide two rational complex numbers.
 
dc_complex_frac dc_frac_negate (dc_complex_frac c)
 Negate a rational complex number.
 
dc_complex_frac dc_frac_conj (dc_complex_frac c)
 Complex conjugate of a rational complex number.
 
dc_complex_frac dc_frac_reciprocal (dc_complex_frac c)
 Reciprocal of a rational complex number.
 
df_frac dc_frac_real (dc_complex_frac c)
 Get the real part of a rational complex number.
 
df_frac dc_frac_imag (dc_complex_frac c)
 Get the imaginary part of a rational complex number.
 
bool dc_frac_eq (dc_complex_frac a, dc_complex_frac b)
 Test if two rational complex numbers are equal.
 
bool dc_frac_is_zero (dc_complex_frac c)
 Test if a rational complex number is zero.
 
bool dc_frac_is_real (dc_complex_frac c)
 Test if a rational complex number is real (imaginary part is zero)
 
bool dc_frac_is_imag (dc_complex_frac c)
 Test if a rational complex number is purely imaginary (real part is zero)
 
bool dc_frac_is_gaussian_int (dc_complex_frac c)
 Test if a rational complex number is actually a Gaussian integer.
 
char * dc_frac_to_string (dc_complex_frac c)
 Convert rational complex number to mathematical string representation.
 

Detailed Description

Functions for rational complex numbers.

Function Documentation

◆ dc_frac_add()

dc_complex_frac dc_frac_add ( dc_complex_frac  a,
dc_complex_frac  b 
)
extern

Add two rational complex numbers.

Parameters
aFirst operand (must not be NULL)
bSecond operand (must not be NULL)
Returns
New complex number a + b
Note
Result has reference count of 1
Result automatically reduced to lowest terms

◆ dc_frac_conj()

dc_complex_frac dc_frac_conj ( dc_complex_frac  c)
extern

Complex conjugate of a rational complex number.

Parameters
cThe operand (must not be NULL)
Returns
New complex number with imaginary part negated
Note
Result has reference count of 1
For a+bi, returns a-bi

◆ dc_frac_copy()

dc_complex_frac dc_frac_copy ( dc_complex_frac  c)
extern

Create a new copy with reference count 1.

Parameters
cThe complex number to copy (must not be NULL)
Returns
New complex number with same value
Note
Result has reference count of 1

◆ dc_frac_div()

dc_complex_frac dc_frac_div ( dc_complex_frac  a,
dc_complex_frac  b 
)
extern

Divide two rational complex numbers.

Parameters
aDividend (must not be NULL)
bDivisor (must not be NULL and not zero)
Returns
New complex number a / b
Note
Result has reference count of 1
Result automatically reduced to lowest terms
Uses formula: (a+bi)/(c+di) = ((ac+bd)+(bc-ad)i)/(c²+d²)

◆ dc_frac_eq()

bool dc_frac_eq ( dc_complex_frac  a,
dc_complex_frac  b 
)
extern

Test if two rational complex numbers are equal.

Parameters
aFirst operand (must not be NULL)
bSecond operand (must not be NULL)
Returns
true if a == b, false otherwise
Note
Compares reduced forms for exact equality

◆ dc_frac_from_df()

dc_complex_frac dc_frac_from_df ( df_frac  real,
df_frac  imag 
)
extern

Create a rational complex number from fraction components.

Parameters
realThe real part (must not be NULL)
imagThe imaginary part (must not be NULL)
Returns
New rational complex number (must be released)
Note
Result has reference count of 1
Input fractions are retained

◆ dc_frac_from_ints()

dc_complex_frac dc_frac_from_ints ( int64_t  real_num,
int64_t  real_den,
int64_t  imag_num,
int64_t  imag_den 
)
extern

Create a rational complex number from integer components.

Parameters
real_numNumerator of real part
real_denDenominator of real part (must not be zero)
imag_numNumerator of imaginary part
imag_denDenominator of imaginary part (must not be zero)
Returns
New rational complex number (must be released)
Note
Result has reference count of 1
Automatically reduced to lowest terms
Denominators normalized to be positive

◆ dc_frac_i()

dc_complex_frac dc_frac_i ( void  )
extern

Get the rational complex i (0/1 + 1/1 i)

Returns
Singleton imaginary unit
Note
This is a singleton with high reference count

◆ dc_frac_imag()

df_frac dc_frac_imag ( dc_complex_frac  c)
extern

Get the imaginary part of a rational complex number.

Parameters
cThe complex number (must not be NULL)
Returns
New dynamic fraction (must be released)
Note
Result has reference count of 1

◆ dc_frac_is_gaussian_int()

bool dc_frac_is_gaussian_int ( dc_complex_frac  c)
extern

Test if a rational complex number is actually a Gaussian integer.

Parameters
cThe complex number (must not be NULL)
Returns
true if both real and imaginary parts are integers, false otherwise
Note
Useful after dc_int_div() to check if result simplified to integer

◆ dc_frac_is_imag()

bool dc_frac_is_imag ( dc_complex_frac  c)
extern

Test if a rational complex number is purely imaginary (real part is zero)

Parameters
cThe complex number (must not be NULL)
Returns
true if real part is zero, false otherwise

◆ dc_frac_is_real()

bool dc_frac_is_real ( dc_complex_frac  c)
extern

Test if a rational complex number is real (imaginary part is zero)

Parameters
cThe complex number (must not be NULL)
Returns
true if imaginary part is zero, false otherwise

◆ dc_frac_is_zero()

bool dc_frac_is_zero ( dc_complex_frac  c)
extern

Test if a rational complex number is zero.

Parameters
cThe complex number (must not be NULL)
Returns
true if c == 0+0i, false otherwise

◆ dc_frac_mul()

dc_complex_frac dc_frac_mul ( dc_complex_frac  a,
dc_complex_frac  b 
)
extern

Multiply two rational complex numbers.

Parameters
aFirst operand (must not be NULL)
bSecond operand (must not be NULL)
Returns
New complex number a * b
Note
Result has reference count of 1
Result automatically reduced to lowest terms
Uses formula: (a+bi)(c+di) = (ac-bd) + (ad+bc)i

◆ dc_frac_neg_i()

dc_complex_frac dc_frac_neg_i ( void  )
extern

Get the rational complex -i (0/1 + -1/1 i)

Returns
Singleton negative imaginary unit
Note
This is a singleton with high reference count

◆ dc_frac_neg_one()

dc_complex_frac dc_frac_neg_one ( void  )
extern

Get the rational complex -1 (-1/1 + 0/1 i)

Returns
Singleton negative one complex number
Note
This is a singleton with high reference count

◆ dc_frac_negate()

dc_complex_frac dc_frac_negate ( dc_complex_frac  c)
extern

Negate a rational complex number.

Parameters
cThe operand (must not be NULL)
Returns
New complex number -c
Note
Result has reference count of 1

◆ dc_frac_one()

dc_complex_frac dc_frac_one ( void  )
extern

Get the rational complex one (1/1 + 0/1 i)

Returns
Singleton one complex number
Note
This is a singleton with high reference count

◆ dc_frac_real()

df_frac dc_frac_real ( dc_complex_frac  c)
extern

Get the real part of a rational complex number.

Parameters
cThe complex number (must not be NULL)
Returns
New dynamic fraction (must be released)
Note
Result has reference count of 1

◆ dc_frac_reciprocal()

dc_complex_frac dc_frac_reciprocal ( dc_complex_frac  c)
extern

Reciprocal of a rational complex number.

Parameters
cThe operand (must not be NULL and not zero)
Returns
New complex number 1/c
Note
Result has reference count of 1
Equivalent to dc_frac_div(dc_frac_one(), c)

◆ dc_frac_release()

void dc_frac_release ( dc_complex_frac c)
extern

Decrement reference count and possibly free memory.

Parameters
cPointer to complex number pointer (gracefully handles NULL)
Note
Sets *c to NULL after release
Only frees memory when reference count reaches 0
Singletons are never freed

◆ dc_frac_retain()

dc_complex_frac dc_frac_retain ( dc_complex_frac  c)
extern

Increment reference count and return the same object.

Parameters
cThe complex number to retain (must not be NULL)
Returns
The same object passed in
Note
Increases reference count by 1

◆ dc_frac_sub()

dc_complex_frac dc_frac_sub ( dc_complex_frac  a,
dc_complex_frac  b 
)
extern

Subtract two rational complex numbers.

Parameters
aFirst operand (must not be NULL)
bSecond operand (must not be NULL)
Returns
New complex number a - b
Note
Result has reference count of 1
Result automatically reduced to lowest terms

◆ dc_frac_to_string()

char * dc_frac_to_string ( dc_complex_frac  c)
extern

Convert rational complex number to mathematical string representation.

Parameters
cThe complex number (must not be NULL)
Returns
Newly allocated string (must be freed with free())
Note
Format examples: "3/4+2/3i", "1/2-1/3i", "2/3i", "-i", "5/7", "0"
Uses mathematical notation with 'i' for imaginary unit
Shows fractions in reduced form

◆ dc_frac_zero()

dc_complex_frac dc_frac_zero ( void  )
extern

Get the rational complex zero (0/1 + 0/1 i)

Returns
Singleton zero complex number
Note
This is a singleton with high reference count