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

Functions for Gaussian integers (complex numbers with integer components) More...

Functions

dc_complex_int dc_int_from_ints (int64_t real, int64_t imag)
 Create a Gaussian integer from int64_t real and imaginary parts.
 
dc_complex_int dc_int_from_di (di_int real, di_int imag)
 Create a Gaussian integer from dynamic integer components.
 
dc_complex_int dc_int_zero (void)
 Get the Gaussian integer zero (0 + 0i)
 
dc_complex_int dc_int_one (void)
 Get the Gaussian integer one (1 + 0i)
 
dc_complex_int dc_int_i (void)
 Get the Gaussian integer i (0 + 1i)
 
dc_complex_int dc_int_neg_one (void)
 Get the Gaussian integer -1 (-1 + 0i)
 
dc_complex_int dc_int_neg_i (void)
 Get the Gaussian integer -i (0 - 1i)
 
dc_complex_int dc_int_retain (dc_complex_int c)
 Increment reference count and return the same object.
 
void dc_int_release (dc_complex_int *c)
 Decrement reference count and possibly free memory.
 
dc_complex_int dc_int_copy (dc_complex_int c)
 Create a new copy with reference count 1.
 
dc_complex_int dc_int_add (dc_complex_int a, dc_complex_int b)
 Add two Gaussian integers.
 
dc_complex_int dc_int_sub (dc_complex_int a, dc_complex_int b)
 Subtract two Gaussian integers.
 
dc_complex_int dc_int_mul (dc_complex_int a, dc_complex_int b)
 Multiply two Gaussian integers.
 
dc_complex_frac dc_int_div (dc_complex_int a, dc_complex_int b)
 Divide two Gaussian integers (returns exact rational result)
 
dc_complex_int dc_int_negate (dc_complex_int c)
 Negate a Gaussian integer.
 
dc_complex_int dc_int_conj (dc_complex_int c)
 Complex conjugate of a Gaussian integer.
 
di_int dc_int_real (dc_complex_int c)
 Get the real part of a Gaussian integer.
 
di_int dc_int_imag (dc_complex_int c)
 Get the imaginary part of a Gaussian integer.
 
bool dc_int_eq (dc_complex_int a, dc_complex_int b)
 Test if two Gaussian integers are equal.
 
bool dc_int_is_zero (dc_complex_int c)
 Test if a Gaussian integer is zero.
 
bool dc_int_is_real (dc_complex_int c)
 Test if a Gaussian integer is real (imaginary part is zero)
 
bool dc_int_is_imag (dc_complex_int c)
 Test if a Gaussian integer is purely imaginary (real part is zero)
 
char * dc_int_to_string (dc_complex_int c)
 Convert Gaussian integer to mathematical string representation.
 

Detailed Description

Functions for Gaussian integers (complex numbers with integer components)

Function Documentation

◆ dc_int_add()

dc_complex_int dc_int_add ( dc_complex_int  a,
dc_complex_int  b 
)
extern

Add two Gaussian integers.

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

◆ dc_int_conj()

dc_complex_int dc_int_conj ( dc_complex_int  c)
extern

Complex conjugate of a Gaussian integer.

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

dc_complex_int dc_int_copy ( dc_complex_int  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_int_div()

dc_complex_frac dc_int_div ( dc_complex_int  a,
dc_complex_int  b 
)
extern

Divide two Gaussian integers (returns exact rational result)

Parameters
aDividend (must not be NULL)
bDivisor (must not be NULL and not zero)
Returns
New rational complex number a / b
Note
Returns dc_complex_frac for exact division
Result has reference count of 1
Use dc_frac_is_gaussian_int() to check if result is still integer

◆ dc_int_eq()

bool dc_int_eq ( dc_complex_int  a,
dc_complex_int  b 
)
extern

Test if two Gaussian integers are equal.

Parameters
aFirst operand (must not be NULL)
bSecond operand (must not be NULL)
Returns
true if a == b, false otherwise

◆ dc_int_from_di()

dc_complex_int dc_int_from_di ( di_int  real,
di_int  imag 
)
extern

Create a Gaussian integer from dynamic integer components.

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

◆ dc_int_from_ints()

dc_complex_int dc_int_from_ints ( int64_t  real,
int64_t  imag 
)
extern

Create a Gaussian integer from int64_t real and imaginary parts.

Parameters
realThe real part
imagThe imaginary part
Returns
New Gaussian integer complex number (must be released)
Note
Result has reference count of 1

◆ dc_int_i()

dc_complex_int dc_int_i ( void  )
extern

Get the Gaussian integer i (0 + 1i)

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

◆ dc_int_imag()

di_int dc_int_imag ( dc_complex_int  c)
extern

Get the imaginary part of a Gaussian integer.

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

◆ dc_int_is_imag()

bool dc_int_is_imag ( dc_complex_int  c)
extern

Test if a Gaussian integer 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_int_is_real()

bool dc_int_is_real ( dc_complex_int  c)
extern

Test if a Gaussian integer is real (imaginary part is zero)

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

◆ dc_int_is_zero()

bool dc_int_is_zero ( dc_complex_int  c)
extern

Test if a Gaussian integer is zero.

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

◆ dc_int_mul()

dc_complex_int dc_int_mul ( dc_complex_int  a,
dc_complex_int  b 
)
extern

Multiply two Gaussian integers.

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
Uses formula: (a+bi)(c+di) = (ac-bd) + (ad+bc)i

◆ dc_int_neg_i()

dc_complex_int dc_int_neg_i ( void  )
extern

Get the Gaussian integer -i (0 - 1i)

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

◆ dc_int_neg_one()

dc_complex_int dc_int_neg_one ( void  )
extern

Get the Gaussian integer -1 (-1 + 0i)

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

◆ dc_int_negate()

dc_complex_int dc_int_negate ( dc_complex_int  c)
extern

Negate a Gaussian integer.

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

◆ dc_int_one()

dc_complex_int dc_int_one ( void  )
extern

Get the Gaussian integer one (1 + 0i)

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

◆ dc_int_real()

di_int dc_int_real ( dc_complex_int  c)
extern

Get the real part of a Gaussian integer.

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

◆ dc_int_release()

void dc_int_release ( dc_complex_int 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_int_retain()

dc_complex_int dc_int_retain ( dc_complex_int  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_int_sub()

dc_complex_int dc_int_sub ( dc_complex_int  a,
dc_complex_int  b 
)
extern

Subtract two Gaussian integers.

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

◆ dc_int_to_string()

char * dc_int_to_string ( dc_complex_int  c)
extern

Convert Gaussian integer 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+4i", "2-3i", "i", "-i", "5", "0"
Uses mathematical notation with 'i' for imaginary unit

◆ dc_int_zero()

dc_complex_int dc_int_zero ( void  )
extern

Get the Gaussian integer zero (0 + 0i)

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