[complex.ops]

# 29 Numerics library [[numerics]](./#numerics)

## 29.4 Complex numbers [[complex.numbers]](complex.numbers#complex.ops)

### 29.4.6 Non-member operations [complex.ops]

[ð](#lib:operator+,complex)

`template<class T> constexpr complex<T> operator+(const complex<T>& lhs);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L606)

*Returns*: complex<T>(lhs)[.](#1.sentence-1)

[ð](#itemdecl:2)

`template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator+(const T& lhs, const complex<T>& rhs);
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L618)

*Returns*: complex<T>(lhs) += rhs[.](#2.sentence-1)

[ð](#lib:operator-,complex)

`template<class T> constexpr complex<T> operator-(const complex<T>& lhs);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L629)

*Returns*: complex<T>(-lhs.real(),-lhs.imag())[.](#3.sentence-1)

[ð](#lib:operator-,complex_)

`template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator-(const T& lhs, const complex<T>& rhs);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L642)

*Returns*: complex<T>(lhs) -= rhs[.](#4.sentence-1)

[ð](#lib:operator*,complex)

`template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator*(const T& lhs, const complex<T>& rhs);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L655)

*Returns*: complex<T>(lhs) *= rhs[.](#5.sentence-1)

[ð](#lib:operator/,complex)

`template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator/(const T& lhs, const complex<T>& rhs);
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L668)

*Returns*: complex<T>(lhs) /= rhs[.](#6.sentence-1)

[ð](#lib:operator==,complex)

`template<class T> constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L680)

*Returns*: lhs.real() == rhs.real() && lhs.imag() == rhs.imag()[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L684)

*Remarks*: The imaginary part is assumed to beT(),
or 0.0, for theT arguments[.](#8.sentence-1)

[ð](#lib:operator%3e%3e,complex)

`template<class T, class charT, class traits>
  basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, complex<T>& x);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L700)

*Preconditions*: The input values are convertible toT[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L705)

*Effects*: Extracts a complex number x of the form:u,(u),
or(u,v),
whereu is the real part andv is the imaginary part ([[istream.formatted]](istream.formatted "31.7.5.3 Formatted input functions"))[.](#10.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L718)

If bad input is encountered, callsis.setstate(ios_base​::​failbit) (which may throwios_base​::​​failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")))[.](#11.sentence-1)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L724)

*Returns*: is[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L728)

*Remarks*: This extraction is performed as a series of simpler
extractions[.](#13.sentence-1)

Therefore, the skipping of whitespace is specified to be
the same for each of the simpler extractions[.](#13.sentence-2)

[ð](#lib:operator%3c%3c,complex)

`template<class T, class charT, class traits>
  basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
`

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L743)

*Effects*: Inserts the complex number x onto the stream o as if it were implemented as follows:basic_ostringstream<charT, traits> s;
s.flags(o.flags());
s.imbue(o.getloc());
s.precision(o.precision());
s << '(' << x.real() << ',' << x.imag() << ')';return o << s.str();

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L756)

[*Note [1](#note-1)*:

In a locale in which comma is used as a decimal point character, the
use of comma as a field separator can be ambiguous[.](#15.sentence-1)

Insertingshowpoint into the output stream forces all outputs to
show an explicit decimal point character; as a result, all inserted sequences of
complex numbers can be extracted unambiguously[.](#15.sentence-2)

â *end note*]
