Complex number library written in and for C.
This simple C library allows you to easily manipulate complex numbers by creating math functions that are made specifically for complex numbers.
- Elementary operations with complex numbers (addition, substraction, multiplication, division)
- Exponentiation of complex numbers
- Square root function
- Degrees to radians conversion and viceversa
- Conjugate of a complex number
- Real and imaginary part of a complex number
- Convert a complex number type (
complex_t
) to a string.
- Modulus of a complex number (absolute value)
- Polar coordinates of a complex number
To import the library, simply add #include
"complex.h"
to the file. All functions will be imported and you'll now be able to use the library.
The complex number data type is defined as complex_t
, which is a struct with 2 long double
data types: the real part and the imaginary part. Although it is possible to change the individual values of the complex_t
data type, it is recommended to use the built-in functions.
In this documentation,
complex_t
means the complex data type,
long double
is a real number, and
char*
is a C null-terminated string.
These are all the functions with the corresponding description and arguments:
char* ctoa(complex_t)
Convert complex number to a string, in format a+bi
or a-bi.
long double degtorad(long double)
Convert degrees to radians.
long double radangle(complex_t)
Calculate the angle (argument) of a complex number, in radians.
long double radtodeg(complex_t)
Convert radians to degrees.
long double cabs(complex_t)
Absolute value of a complex number.
complex_t cadd(complex_t, complex_t)
Add 2 complex numbers.
complex_t cdiff(complex_t, complex_t)
Substract 2 complex numbers.
complex_t cdivide(complex_t, complex_t)
Divide 2 complex numbers.
complex_t cmultiply(complex_t, complex_t)
Multiply 2 complex numbers.
complex_t conj(complex_t)
Conjugate of a complex number.
complex_t cpower(complex_t, long double)
Raise a complex number to a power (power must be real).
long double csqrt(complex_t)
Square root of a complex number
long double degangle(long double)
Calculate the angle (argument) of a complex number, in degrees.
long double imag(complex_t)
Get the imaginary part of a complex number, returns 0 if no imaginary part exists.
long double real(complex_t)
Get the real part of a complex number, returns 0 if no real part exists.
complex_t cvalue(long double, long double)
Assign new values to a complex number, and return that value.