[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 constexpr complex operator+(const complex& lhs); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L606) *Returns*: complex(lhs)[.](#1.sentence-1) [🔗](#itemdecl:2) `template constexpr complex operator+(const complex& lhs, const complex& rhs); template constexpr complex operator+(const complex& lhs, const T& rhs); template constexpr complex operator+(const T& lhs, const complex& rhs); ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L618) *Returns*: complex(lhs) += rhs[.](#2.sentence-1) [🔗](#lib:operator-,complex) `template constexpr complex operator-(const complex& lhs); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L629) *Returns*: complex(-lhs.real(),-lhs.imag())[.](#3.sentence-1) [🔗](#lib:operator-,complex_) `template constexpr complex operator-(const complex& lhs, const complex& rhs); template constexpr complex operator-(const complex& lhs, const T& rhs); template constexpr complex operator-(const T& lhs, const complex& rhs); ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L642) *Returns*: complex(lhs) -= rhs[.](#4.sentence-1) [🔗](#lib:operator*,complex) `template constexpr complex operator*(const complex& lhs, const complex& rhs); template constexpr complex operator*(const complex& lhs, const T& rhs); template constexpr complex operator*(const T& lhs, const complex& rhs); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L655) *Returns*: complex(lhs) *= rhs[.](#5.sentence-1) [🔗](#lib:operator/,complex) `template constexpr complex operator/(const complex& lhs, const complex& rhs); template constexpr complex operator/(const complex& lhs, const T& rhs); template constexpr complex operator/(const T& lhs, const complex& rhs); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L668) *Returns*: complex(lhs) /= rhs[.](#6.sentence-1) [🔗](#lib:operator==,complex) `template constexpr bool operator==(const complex& lhs, const complex& rhs); template constexpr bool operator==(const complex& 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 basic_istream& operator>>(basic_istream& is, complex& 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 basic_ostream& operator<<(basic_ostream& o, const complex& 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 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*]