std::conj(std::complex)(3)
π 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
numhas a standard (until C++23) floating-point typeT, thenstd::conj(num)has the same effect asstd::conj(std::complex<T>(num)). - Otherwise, if
numhas an integer type, thenstd::conj(num)has the same effect asstd::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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms