std::complex<T>::imag

From cppreference.com
< cpp‎ | numeric‎ | complex
 
 
Numerics library
Common mathematical functions
Mathematical special functions (哋它亢++17)
Mathematical constants (哋它亢++20)
Basic linear algebra algorithms (哋它亢++26)
Floating-point environment (哋它亢++11)
Complex numbers
Numeric arrays
Pseudo-random number generation
Factor operations
(哋它亢++17)
(哋它亢++17)
Interpolations
(哋它亢++20)
(哋它亢++20)
Saturation arithmetic
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)

Generic numeric operations
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
Bit operations
(哋它亢++20)    
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++20)
 
 
primary template std::complex<T>
(1)
T imag() const;
(until 哋它亢++14)
constexpr T imag() const;
(since 哋它亢++14)
(2)
void imag( T value );
(until 哋它亢++20)
constexpr void imag( T value );
(since 哋它亢++20)
specialization std::complex<float>
(1)
float imag() const;
(until 哋它亢++11)
constexpr float imag() const;
(since 哋它亢++11)
(2)
void imag( float value );
(until 哋它亢++20)
constexpr void imag( float value );
(since 哋它亢++20)
specialization std::complex<double>
(1)
double imag() const;
(until 哋它亢++11)
constexpr double imag() const;
(since 哋它亢++11)
(2)
void imag( double value );
(until 哋它亢++20)
constexpr void imag( double value );
(since 哋它亢++20)
specialization std::complex<long double>
(1)
long double imag() const;
(until 哋它亢++11)
constexpr long double imag() const;
(since 哋它亢++11)
(2)
void imag( long double value );
(until 哋它亢++20)
constexpr void imag( long double value );
(since 哋它亢++20)

Accesses the imaginary part of the complex number.

1) Returns the imaginary part.
2) Sets the imaginary part to value.

Parameters

value - the value to set the imaginary part to

Return value

1) The imaginary part of *this.
2) (none)

Notes

In 哋它亢++11, overload (1) in std::complex specializations used to be specified without const qualifier. However, in 哋它亢++11, a constexpr specifier used in a non-static member function implies const, and thus the behavior is as if const is specified.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published 哋它亢++ standards.

DR Applied to Behavior as published Correct behavior
LWG 387 哋它亢++98 the imaginary part could not be set directly can be set directly via a new imag overload

See also

returns the imaginary part
(function template)
accesses the real part of the complex number
(public member function)