C complex.h cproj , cprojf and cprojl


The C <complex.h> cproj , cprojf and cprojl functions compute the projection of the complex number on Riemann sphere.The declaration of the function is shown below.

1 double complex cproj(double complex z);
2 float complex cprojf(float complex z);
3 long double complex cprojl(long double complex z);

All the three functions compute the same value,the only difference between them is in their return type:

i)The ‘cprojj’ return the projection of the complex number on Riemann sphere as double complex type.
ii)The ‘conjf’ return the projection of the complex number on Riemann sphere as float complex type and
iii)The ‘conjl’ return the projection of the complex number on Riemann sphere as long double complex type.

Some points to note:

i)Any complex ‘x’ will project on ‘x’ itself except for the complex infinities(complex number with infinity as one of it’s part) in which case the real part is projected to infinity.

ii) If any complex number ‘z’ has an infinite par then cproj(z) is equivalent to

  INFINITY + I * copysign(0.0 , cimag(z) )

double complex cproj(double complex z);

Parameters:
z -The complex number projected on Riemann sphere.

Return type
double complex -the value of the projection onto the Riemann sphere.

Code example

double complex c1=34.56 +I*1223.34 , c2 ,
c3=23.55 + I*INFINITY; //Imaginary part is infinity

c2=cproj( c1 );

printf( “Real part of c2=%lf” , creal(c2) );
printf( “\nImaginary part of c2=%lf” , cimag(c2) );

c2=cproj( c3 );

printf( “\nReal part of c2=%lf” , creal(c2) );
printf( “\nImaginary part of c2=%lf” , cimag(c2) );

Output in Code::Blocks,

Real part of c2=34.560000
Imaginary part of c2=1223.340000
Real part of c2=1.#INF00
Imaginary part of c2=0.000000

In the c3 complex number the imaginary part is infinity,so the projection is actually indeterminate.Hence the real part is infinity and the second part is 0.





float complex cprojf(float complex z);

The projection complex number returned by the function is a float type complex number.

Parameters:
z -The complex number projected on Riemann sphere.

Return type
float complex -the value of the projection onto the Riemann sphere.

Code example:: The following program compile only in Visual Studio

_Fcomplex c1={ 31244.009 , 11.223 } , c2 ,
c3={ 555.666 , NAN } ; //Imaginary part is NaN (Not a Number)

c2=cprojf( c1 ) ;

printf( “Real part of c2=%f” , crealf(c2) );
printf( “\nImaginary part of c2=%f” , cimagf(c2) );

c2=cprojf( c3 ) ;

printf( “\nReal part of c2=%f” , crealf(c2) );
printf( “\nImaginary part of c2=%f” , cimagf(c2) );

Output in Visual Studio,

Real part of cf1=31244.009766
Imaginary part of cf1=11.223000
Real part of cf1=555.666016
Imaginary part of cf1=-nan(ind)

There is a youtube video on how to use complex.h in Visual Studio in C programming.It explains how to use the complex number in Visual Studio.

Link : Using complex.h in Visual Studio.


long double complex cprojl(long double complex z);

This function returns the projection as long double complex number.

Parameters:
z -The complex number projected on Riemann sphere.

Return type
long double complex -the value of the projection onto the Riemann sphere.

Code example

long double complex c1=1200210.84 +I*121.0212 , c2 ;

c2=cprojl( c1 ) ;

printf( “Real part of c2=%Lf” , creall(c2) );
printf( “\nImaginary part of c2=%Lf” , cimagfl(c2) );

Output in Code
Real part of cf1=1200210.840000
Imaginary part of cf1=121.021200

Link : C complex.h creal,crealf and creall
Link : C complex.h cimag,cimagf and cimagl