Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is cproj in C?

Sheza Munir

The cproj function computes the projection of a complex number on the Reimann spherecan be visualized as the complex number plane wrapped around a sphere.

Syntax

double complex cproj(double complex z);

Library

The cproj function is accessible via the math.h library. To access complex numbers, we must include the complex.h.

Parameter

The cproj function takes a single parameter: a complex number, the projection of which is also required.

Return value

The function returns the projection of the argument on the Reimann sphere as a complex number.

The cproj function maps all infinities (e.g. \infty+3i, \infty-7) to one infinity (i.e., \infty).

Code

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 place

    double complex num2 = cproj(INFINITY + 2.0*I);
    printf("cproj(inf + 2i) = %.1f% + .1fi\n", creal(num2), cimag(num2));
 
}

RELATED TAGS

c

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring