@@ -89,35 +89,34 @@ class complex
8989 return *this ;
9090 }
9191
92- BOOST_MP_CXX14_CONSTEXPR bool operator ==(const complex & rhs) noexcept
92+ BOOST_MP_CXX14_CONSTEXPR bool operator ==(const complex & rhs) const noexcept
9393 {
9494 return real_ == rhs.real_ && imag_ == rhs.imag_ ;
9595 }
9696
97- BOOST_MP_CXX14_CONSTEXPR bool operator !=(const complex & rhs) noexcept
97+ BOOST_MP_CXX14_CONSTEXPR bool operator !=(const complex & rhs) const noexcept
9898 {
9999 return !(*this == rhs);
100100 }
101101
102- BOOST_MP_CXX14_CONSTEXPR bool operator ==(const T& rhs) noexcept
102+ BOOST_MP_CXX14_CONSTEXPR bool operator ==(const T& rhs) const noexcept
103103 {
104104 return real_ == rhs && imag_ == T{0 };
105105 }
106106
107- BOOST_MP_CXX14_CONSTEXPR bool operator !=(const T& rhs) noexcept
107+ BOOST_MP_CXX14_CONSTEXPR bool operator !=(const T& rhs) const noexcept
108108 {
109109 return !(*this == rhs);
110110 }
111111
112- // Writes in the form (real, imag)
113112 template <typename CharT, typename Traits>
114- std::basic_ostream<CharT, Traits>& operator <<(std::basic_ostream<CharT, Traits>& os)
113+ friend std::basic_ostream<CharT, Traits>& operator <<(std::basic_ostream<CharT, Traits>& os, const complex & z )
115114 {
116115 std::basic_ostringstream<CharT, Traits> s;
117116 s.flags (os.flags ());
118117 s.imbue (os.getloc ());
119118 s.precision (os.precision ());
120- s << ' (' << real_ << ' ,' << imag_ << ' )' ;
119+ s << ' (' << z. real_ << ' ,' << z. imag_ << ' )' ;
121120
122121 return os << s.str ();
123122 }
@@ -127,7 +126,7 @@ class complex
127126 // 2) (real)
128127 // 3) (real, imag)
129128 template <typename CharT, typename Traits>
130- std::basic_istream<CharT, Traits>& operator >>(std::basic_ostream <CharT, Traits>& is)
129+ friend std::basic_istream<CharT, Traits>& operator >>(std::basic_istream <CharT, Traits>& is, complex & z )
131130 {
132131 CharT ch {};
133132 T real = T{0 };
@@ -163,8 +162,8 @@ class complex
163162
164163 if (!is.fail ())
165164 {
166- real_ = real;
167- imag_ = imag;
165+ z. real_ = real;
166+ z. imag_ = imag;
168167 }
169168
170169 return is;
@@ -215,6 +214,17 @@ inline BOOST_MP_CXX14_CONSTEXPR complex<boost::multiprecision::number<T, ET>> co
215214 return {z.real (), -z.imag ()};
216215}
217216
217+ template <typename T, expression_template_option ET >
218+ inline BOOST_MP_CXX14_CONSTEXPR complex <boost::multiprecision::number<T, ET >> proj (const complex <boost::multiprecision::number<T, ET >>& z) noexcept
219+ {
220+ if (isinf (z.real ()) || isinf (z.imag ()))
221+ {
222+ return {std::numeric_limits<boost::multiprecision::number<T, ET >>::infinity (), copysign (boost::multiprecision::number<T, ET >{0 }, z.imag ())};
223+ }
224+
225+ return z;
226+ }
227+
218228} // Namespace multiprecision
219229} // Namespace boost
220230
0 commit comments