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

Functions for converting between complex number types. More...

Functions

dc_complex_frac dc_int_to_frac (dc_complex_int c)
 Convert Gaussian integer to rational complex (lossless)
 
dc_complex_double dc_int_to_double (dc_complex_int c)
 Convert Gaussian integer to floating-point complex (lossless for small integers)
 
dc_complex_double dc_frac_to_double (dc_complex_frac c)
 Convert rational complex to floating-point complex.
 
dc_complex_int dc_frac_to_int (dc_complex_frac c)
 Convert rational complex to Gaussian integer (with rounding)
 
dc_complex_int dc_double_to_int (dc_complex_double c)
 Convert floating-point complex to Gaussian integer (with rounding)
 
dc_complex_frac dc_double_to_frac (dc_complex_double c, int64_t max_denominator)
 Convert floating-point complex to rational complex (with approximation)
 

Detailed Description

Functions for converting between complex number types.

Function Documentation

◆ dc_double_to_frac()

dc_complex_frac dc_double_to_frac ( dc_complex_double  c,
int64_t  max_denominator 
)
extern

Convert floating-point complex to rational complex (with approximation)

Parameters
cThe floating-point complex number (must not be NULL)
max_denominatorMaximum allowed denominator for approximation
Returns
New rational complex number approximating the input
Note
Result has reference count of 1
Uses continued fraction approximation
Larger max_denominator gives better approximation but larger fractions

◆ dc_double_to_int()

dc_complex_int dc_double_to_int ( dc_complex_double  c)
extern

Convert floating-point complex to Gaussian integer (with rounding)

Parameters
cThe floating-point complex number (must not be NULL)
Returns
New Gaussian integer (rounded to nearest)
Note
Result has reference count of 1
Both real and imaginary parts rounded to nearest integer
NaN and infinity values may produce undefined behavior

◆ dc_frac_to_double()

dc_complex_double dc_frac_to_double ( dc_complex_frac  c)
extern

Convert rational complex to floating-point complex.

Parameters
cThe rational complex number (must not be NULL)
Returns
New floating-point complex number
Note
Result has reference count of 1
Precision may be lost due to floating-point representation

◆ dc_frac_to_int()

dc_complex_int dc_frac_to_int ( dc_complex_frac  c)
extern

Convert rational complex to Gaussian integer (with rounding)

Parameters
cThe rational complex number (must not be NULL)
Returns
New Gaussian integer (rounded to nearest)
Note
Result has reference count of 1
Both real and imaginary parts rounded to nearest integer
Use dc_frac_is_gaussian_int() to check if conversion is exact

◆ dc_int_to_double()

dc_complex_double dc_int_to_double ( dc_complex_int  c)
extern

Convert Gaussian integer to floating-point complex (lossless for small integers)

Parameters
cThe Gaussian integer (must not be NULL)
Returns
New floating-point complex number
Note
Result has reference count of 1
Large integers may lose precision due to double limits

◆ dc_int_to_frac()

dc_complex_frac dc_int_to_frac ( dc_complex_int  c)
extern

Convert Gaussian integer to rational complex (lossless)

Parameters
cThe Gaussian integer (must not be NULL)
Returns
New rational complex number with same value
Note
Result has reference count of 1
Conversion is exact: integer n becomes n/1