The cproj function computes the projection of a complex number on the
double complex cproj(double complex z);
The cproj function is accessible via the math.h library. To access complex numbers, we must include the complex.h.
The cproj function takes a single parameter: a complex number, the projection of which is also required.
The function returns the projection of the argument on the Reimann sphere as a complex number.
The
cprojfunction maps all infinities (e.g. +3i, -7) to one infinity (i.e., ).
The cproj function returns a complex number, while creal function returns the real part of the complex number and cimag returns the imaginary of the complex number.
The following code shows some examples of the use of cproj function.
#include <stdio.h>#include <math.h>#include <complex.h>int main(){double complex num1 = cproj(3 + 4*I);printf("cproj(3 + 4i) = %.1f% + .1fi\n", creal(num1), cimag(num1));// %.1f specifies precision of the given float number to 1 decimal placedouble complex num2 = cproj(INFINITY + 2.0*I);printf("cproj(inf + 2i) = %.1f% + .1fi\n", creal(num2), cimag(num2));}
Free Resources