std::conj(std::complex)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… NAME πŸ’…

std::conj(std::complex) β€” bestie, this is literally std::conj(std::complex), the glow-up machine that flips the sign on the imaginary part and hands you back the complex conjugate ✨


πŸ¦‹ Synopsis πŸ¦‹

Ok so first things first, this whole thing lives in the header <complex> πŸ’–

template< class T >
std::complex<T> conj( const std::complex<T>& z );

(until C++20)

template< class T >
constexpr std::complex<T> conj( const std::complex<T>& z );

(since C++20)

🌸 Additional overloads (since C++11) 🌸

Also! Defined in the header <complex> (yes, again, same header, she's consistent):

std::complex<float>       conj( float f );
std::complex<double>      conj( double f );
std::complex<long double> conj( long double f );

(until C++20)

constexpr std::complex<float>       conj( float f );
constexpr std::complex<double>      conj( double f );
constexpr std::complex<long double> conj( long double f );

(since C++20) (until C++23) β€” that's overload (A) iykyk

template< class FloatingPoint >
constexpr std::complex<FloatingPoint> conj( FloatingPoint f );

(since C++23)

template< class Integer >
constexpr std::complex<double> conj( Integer i );

(until C++20) β€” overload (B) πŸŽ€

template< class Integer >
constexpr std::complex<double> conj( Integer i );

(since C++20)


🧚 DESCRIPTION vibes 🧚

1) Computes the complex conjugate of z by reversing the sign of the imaginary part. That's it, that's the whole trick, and she ate πŸ’…

A,B) Additional overloads are provided for all integer and floating-point types, which are treated as complex numbers with zero imaginary component. (since C++11) β€” so your boring little float gets to sit at the complex-kids table 🫢


πŸ“ Parameters πŸ“

  • z β€” a complex value πŸ’œ
  • f β€” a floating-point value ✨
  • i β€” an integer value 🌸

πŸ‘‘ Return value πŸ‘‘

  • 1) The complex conjugate of z. Slay.
  • A) std::complex(f).
  • B) std::complex<double>(i).

πŸ’€ Notes πŸ’€

Real talk: the additional overloads are not required to be provided exactly as (A,B). They only need to be sufficient to ensure that for their argument num:

  • If num has a standard (until C++23) floating-point type T, then std::conj(num) has the same effect as std::conj(std::complex<T>(num)).
  • Otherwise, if num has an integer type, then std::conj(num) has the same effect as std::conj(std::complex<double>(num)).

So like, the vibes are flexible but the behaviour is locked in 😌


πŸŽ€ Example πŸŽ€

// Run this code

#include <complex>
#include <iostream>

int main()
{
    std::complex<double> z(1.0, 2.0);
    std::cout << "The conjugate of " << z << " is " << std::conj(z) << '\n'
              << "Their product is " << z * std::conj(z) << '\n';
}

⭐ Output: ⭐

The conjugate of (1,2) is (1,-2)
Their product is (5,0)

Not the product being <hotpink>(5,0)</hotpink> β€” a real number era, main character energy fr fr πŸ”₯


🌈 See also 🌈

  • abs(std::complex) β€” returns the magnitude of a complex number (function template) πŸ’–
  • norm β€” returns the squared magnitude (function template) ✨
  • polar β€” constructs a complex number from magnitude and phase angle (function template) πŸ¦‹
  • C documentation for conj β€” the C side of the family, go say hi 🫢

ok bestie that's the whole page, no cap, nothing skipped, you're officially a conj connoisseur πŸ’…

mwah πŸ’‹ this page came to you courtesy of http://cppreference.com, version 2024.06.10, filed under std::conj(std::complex)(3) β€” go forth and conjugate responsibly 🌸

πŸ“¦ where this page comes from