Functions for converting between complex number types.
More...
Functions for converting between complex number types.
◆ dc_double_to_frac()
Convert floating-point complex to rational complex (with approximation)
- Parameters
-
| c | The floating-point complex number (must not be NULL) |
| max_denominator | Maximum 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()
Convert floating-point complex to Gaussian integer (with rounding)
- Parameters
-
| c | The 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()
Convert rational complex to floating-point complex.
- Parameters
-
| c | The 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()
Convert rational complex to Gaussian integer (with rounding)
- Parameters
-
| c | The 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()
Convert Gaussian integer to floating-point complex (lossless for small integers)
- Parameters
-
| c | The 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()
Convert Gaussian integer to rational complex (lossless)
- Parameters
-
| c | The 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