From 23ed71c60c5a2783c092a00cd39133c2f057d4dc Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 25 May 2008 18:59:19 +0000 Subject: [PATCH] complex (complex<>::real(_Tp), [...]): Add per DR 387. 2008-05-25 Paolo Carlini * include/std/complex (complex<>::real(_Tp), complex<>::imag(_Tp), complex::real(float), complex::imag(float), complex::real(double), complex::imag(double), complex::real(long double), complex::imag(long double)): Add per DR 387. (complex<>::real(), complex<>::imag(), complex::real(), complex::imag(), complex::real(), complex::imag(), complex::real(), complex::imag(long double)): Adjust in C++0x mode. (real(complex<>&), imag(complex<>&), real(const complex<>&), imag(const complex<>&)): Likewise. * testsuite/26_numerics/complex/dr387.cc: New. * doc/xml/manual/intro.xml: Add an entry for DR 387. From-SVN: r135878 --- libstdc++-v3/ChangeLog | 16 ++++ libstdc++-v3/doc/xml/manual/intro.xml | 26 ++++-- libstdc++-v3/include/std/complex | 84 +++++++++++++++++++ .../testsuite/26_numerics/complex/dr387.cc | 52 ++++++++++++ 4 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/complex/dr387.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 19e3dca233f..a5003293c7b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2008-05-25 Paolo Carlini + + * include/std/complex (complex<>::real(_Tp), complex<>::imag(_Tp), + complex::real(float), complex::imag(float), + complex::real(double), complex::imag(double), + complex::real(long double), + complex::imag(long double)): Add per DR 387. + (complex<>::real(), complex<>::imag(), complex::real(), + complex::imag(), complex::real(), + complex::imag(), complex::real(), + complex::imag(long double)): Adjust in C++0x mode. + (real(complex<>&), imag(complex<>&), real(const complex<>&), + imag(const complex<>&)): Likewise. + * testsuite/26_numerics/complex/dr387.cc: New. + * doc/xml/manual/intro.xml: Add an entry for DR 387. + 2008-05-25 Paolo Carlini * include/std/complex: Trivial stylistic changes, define inline diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 0287c9e5562..55c48a6d1fc 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -475,19 +475,21 @@ 303: Bitset input operator underspecified - Basically, compare the input character to is.widen(0) - and is.widen(1). + Basically, compare the input character to + is.widen(0) and is.widen(1). 305: - Default behavior of codecvt<wchar_t, char, mbstate_t>::length() + Default behavior of codecvt<wchar_t, char, + mbstate_t>::length() - Do not specify what codecvt<wchar_t, char, mbstate_t>::do_length - must return. + Do not specify what codecvt<wchar_t, char, + mbstate_t>::do_length must return. 328: - Bad sprintf format modifier in money_put<>::do_put() + Bad sprintf format modifier in + money_put<>::do_put() Change the format string to "%.0Lf". @@ -498,8 +500,18 @@ Add const overloads of is_open. + 387: + std::complex over-encapsulated + + Add the real(T) and imag(T) + members; in C++0x mode, also adjust the existing + real() and imag() members and + free functions. + + 389: - Const overload of valarray::operator[] returns by value + Const overload of valarray::operator[] returns + by value Change it to return a const T&. diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index 947ab0ec9ef..0fa381cbeac 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -131,6 +131,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(const complex<_Up>& __z) : _M_real(__z.real()), _M_imag(__z.imag()) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + _Tp real() const + { return _M_real; } + + _Tp imag() const + { return _M_imag; } +#else /// Return real part of complex number. _Tp& real() { return _M_real; } @@ -146,6 +155,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) /// Return imaginary part of complex number. const _Tp& imag() const { return _M_imag; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(_Tp __val) + { _M_real = __val; } + + void imag(_Tp __val) + { _M_imag = __val; } /// Assign this complex number to scalar @a t. complex<_Tp>& operator=(const _Tp&); @@ -504,6 +522,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } // Values +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + inline _Tp + real(const complex<_Tp>& __z) + { return __z.real(); } + + template + inline _Tp + imag(const complex<_Tp>& __z) + { return __z.imag(); } +#else template inline _Tp& real(complex<_Tp>& __z) @@ -523,6 +552,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline const _Tp& imag(const complex<_Tp>& __z) { return __z.imag(); } +#endif // 26.2.7/3 abs(__z): Returns the magnitude of __z. template @@ -993,6 +1023,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) explicit complex(const complex&); explicit complex(const complex&); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + float real() const + { return __real__ _M_value; } + + float imag() const + { return __imag__ _M_value; } +#else float& real() { return __real__ _M_value; } @@ -1004,6 +1043,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const float& imag() const { return __imag__ _M_value; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(float __val) + { __real__ _M_value = __val; } + + void imag(float __val) + { __imag__ _M_value = __val; } complex& operator=(float __f) @@ -1121,6 +1169,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) explicit complex(const complex&); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + double real() const + { return __real__ _M_value; } + + double imag() const + { return __imag__ _M_value; } +#else double& real() { return __real__ _M_value; } @@ -1132,6 +1189,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const double& imag() const { return __imag__ _M_value; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(double __val) + { __real__ _M_value = __val; } + + void imag(double __val) + { __imag__ _M_value = __val; } complex& operator=(double __d) @@ -1249,6 +1315,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) complex(const complex& __z) : _M_value(__z.__rep()) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + long double real() const + { return __real__ _M_value; } + + long double imag() const + { return __imag__ _M_value; } +#else long double& real() { return __real__ _M_value; } @@ -1260,6 +1335,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) const long double& imag() const { return __imag__ _M_value; } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 387. std::complex over-encapsulated. + void real(long double __val) + { __real__ _M_value = __val; } + + void imag(long double __val) + { __imag__ _M_value = __val; } complex& operator=(long double __r) diff --git a/libstdc++-v3/testsuite/26_numerics/complex/dr387.cc b/libstdc++-v3/testsuite/26_numerics/complex/dr387.cc new file mode 100644 index 00000000000..4431842242c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/dr387.cc @@ -0,0 +1,52 @@ +// 2008-05-22 Paolo Carlini +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include + +// DR 387. std::complex over-encapsulated. +template + void + do_test() + { + bool test __attribute__((unused)) = true; + + const T r = 1.0; + const T i = -1.0; + const T v = 0.0; + + std::complex z1(r, i); + z1.real(v); + VERIFY( z1.real() == v ); + VERIFY( z1.imag() == i ); + + std::complex z2(r, i); + z2.imag(v); + VERIFY( z2.real() == r ); + VERIFY( z2.imag() == v ); + } + +int main() +{ + do_test(); + do_test(); + do_test(); + return 0; +} -- 2.30.2