Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is conjl() in C?

Kainat Asif

The conjl() function in C reverses the sign of the imaginary part of a complex number in order to compute its conjugate.

Library

To use the conjl() function, include the complex.h library as shown below:

#include <complex.h>

Syntax

The conjl() function is declared as follows:

long double complex conjl(long double complex z);

The conjl() function takes in the complex number z as a parameter and returns the conjugate of z.

conjl() vs conj()

The conjl() function computes the conjugate of a complex number stored in a long double datatype, whereas the conj() function computes the conjugate of a complex number stored in a double datatype.

Code

Consider the code snippet below, which uses conjl() to compute the conjugate of a complex number:

#include <stdio.h>
#include <complex.h>

int main() {

  long double complex complexNumber1 = 1 + I*2;
  long double complex complexNumber2 = 1 - I*2;

  long double complex conjugate1 = conjl(complexNumber1);
  long double complex conjugate2 = conjl(complexNumber2);

  printf("conj ( %lf + %lfi ) = ( %lf + %lfi ) \n", creal(complexNumber1), cimag(complexNumber1) , creal(conjugate1), cimag(conjugate1));
  printf("conj ( %lf + %lfi ) = ( %lf + %lfi ) \n", creal(complexNumber2), cimag(complexNumber2) , creal(conjugate2), cimag(conjugate2));
  
  return 0;
}

Explanation

The conjl() function is used in lines 9 and 10 to compute the conjugate of the complex numbers complexNumber1 and complexNumber2 that are created in lines 6 and 7.

RELATED TAGS

c

CONTRIBUTOR

Kainat Asif
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring