- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - cproj() function
The C complex library cproj() function is used to calculate the projection of z (complex number) on the Riemann sphere. Projection refers to a mapping or transformation that takes a point or a set of points from one space and maps them onto another space.
In mathematics, the Riemann sphere is a model for the complex plane. It maps all points on the plane to points on the sphere, introducing infinity as a representation of the behaviour of a complex function at infinity.
Syntax
Following is the C library syntax of cproj() function −
double complex cproj( double complex z );
Parameters
This function accepts a single parameter −
-
Z − It represent a complex number for which we want to compute the projection.
Return Value
This function returns a complex value that may be type such as double, float, or long double, which represents the projection of z on the Riemann sphere.
Example 1
Following is the basic c program to demonstrate the use of cproj() of a complex number.
#include <stdio.h> #include <complex.h> #include <math.h> int main() { double complex proj1 = cproj(1 + 2*I); printf("cproj(1+2i) = %.1f%+.1fi\n", creal(proj1),cimag(proj1)); double complex proj2 = cproj(INFINITY+2.0*I); printf("cproj(Inf+2i) = %.1f%+.1fi\n", creal(proj2),cimag(proj2)); }
Output
Following is the output −
cproj(1+2i) = 1.0+2.0i cproj(Inf+2i) = inf+0.0i
Example 2
Let's see another example, we create a complex number using the CMPLX(). We then use cproj() to calculate the projection of complex number.
#include <stdio.h> #include <complex.h> #include <math.h> int main() { double real = 3; double imag = 4; double complex z = CMPLX(real, imag); double proj = cproj(z); printf("Complex number: %.1f + %.1fi\n", creal(z), cimag(z)); printf("Projection of complex number = %.1f + %.1fi\n", creal(proj),cimag(proj)); }
Output
Following is the output −
Complex number: 3.0 + 4.0i Projection of complex number = 3.0 + 0.0i
Example 3
The below c example, calculate the projection of the negative complex number.
#include <stdio.h> #include <complex.h> int main(void) { double complex z = -3.0 + -4.0*I; // find the project of complex number double proj = cproj(z); printf("Complex number: %.2f + %.2fi\n", creal(z), cimag(z)); printf("project of complex number: %.2f + %.2fi", creal(proj), creal(proj)); return 0; }
Output
Following is the output −
Complex number: -3.00 + -4.00i project of complex number: -3.00 + -3.00i