What is cprojl in C?

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

The l in cprojl indicates that this function’s argument and return datatype is a long double.

Syntax

long double complex cprojl(long double complex z);

Library

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

Parameter

The cprojl function takes a single parameter: a complex number of datatype long double, 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 cprojl function maps all infinities (e.g. \infty+3i, \infty-7) to one infinity (i.e., \infty).

Code

The following code shows some examples of the use of cprojl function.

The cproj function returns a complex number, while the creal function returns the real part of the complex number and cimag returns the imaginary of the complex number.

#include <stdio.h>
#include <math.h>
#include <complex.h>
int main()
{
double complex num1 = cprojl(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 = cprojl(INFINITY + 2.0*I);
printf("cproj(inf + 2i) = %.1f% + .1fi\n", creal(num2), cimag(num2));
}

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved