summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-13 09:45:57 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-13 09:45:57 +0000
commit969de1a7ac34004f2e8261772e52b321e68f43aa (patch)
tree69cbc5ab4f5b1191894f34353c69e0d82d3b19db /libstdc++-v3/include
parentfd9a63cd5381ff28b17e2ddc90d9574a9fa4c58a (diff)
downloadppe42-gcc-969de1a7ac34004f2e8261772e52b321e68f43aa.tar.gz
ppe42-gcc-969de1a7ac34004f2e8261772e52b321e68f43aa.zip
2006-01-13 Paolo Carlini <pcarlini@suse.de>
Howard Hinnant <hhinnant@apple.com> * include/tr1/complex (arg, conj, imag, norm, polar, pow, real): Add, implementing TR1, 8.1.9. (__promote_2): New. * include/tr1/common.h: New, provides __promote, __promote_2. * include/Makefile.am: Add. * include/Makefile.in: Regenerate. * testsuite/testsuite_tr1.h (check_ret_type): New. * testsuite/tr1/8_c_compatibility/complex/overloads_int.cc: New. * testsuite/tr1/8_c_compatibility/complex/overloads_float.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109663 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/Makefile.am1
-rw-r--r--libstdc++-v3/include/Makefile.in1
-rw-r--r--libstdc++-v3/include/tr1/common.h66
-rw-r--r--libstdc++-v3/include/tr1/complex106
4 files changed, 167 insertions, 7 deletions
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 68b1d81d80a..faa23495f14 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -483,6 +483,7 @@ tr1_headers = \
${tr1_srcdir}/bind_repeat.h \
${tr1_srcdir}/bind_iterate.h \
${tr1_srcdir}/boost_shared_ptr.h \
+ ${tr1_srcdir}/common.h \
${tr1_srcdir}/complex \
${tr1_srcdir}/functional \
${tr1_srcdir}/functional_iterate.h \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 9b9c82253b4..2425898ff29 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -701,6 +701,7 @@ tr1_headers = \
${tr1_srcdir}/bind_repeat.h \
${tr1_srcdir}/bind_iterate.h \
${tr1_srcdir}/boost_shared_ptr.h \
+ ${tr1_srcdir}/common.h \
${tr1_srcdir}/complex \
${tr1_srcdir}/functional \
${tr1_srcdir}/functional_iterate.h \
diff --git a/libstdc++-v3/include/tr1/common.h b/libstdc++-v3/include/tr1/common.h
new file mode 100644
index 00000000000..ca9559e463a
--- /dev/null
+++ b/libstdc++-v3/include/tr1/common.h
@@ -0,0 +1,66 @@
+// Internal header for TR1 complex -*- C++ -*-
+
+// Copyright (C) 2006 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.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file
+ * This is a TR1 C++ Library header.
+ */
+
+#ifndef _TR1_COMMON_H
+#define _TR1_COMMON_H 1
+
+#include <tr1/type_traits>
+
+// namespace std::tr1
+namespace std
+{
+_GLIBCXX_BEGIN_NAMESPACE(tr1)
+
+ template<typename _Tp, bool = is_integral<_Tp>::value>
+ struct __promote
+ { typedef double __type; };
+
+ template<typename _Tp>
+ struct __promote<_Tp, false>
+ { typedef _Tp __type; };
+
+ template<typename _Tp, typename _Up>
+ struct __promote_2
+ {
+ private:
+ typedef typename __promote<_Tp>::__type __type1;
+ typedef typename __promote<_Up>::__type __type2;
+
+ public:
+ typedef __typeof__(__type1() + __type2()) __type;
+ };
+
+_GLIBCXX_END_NAMESPACE
+} // namespace std
+
+#endif
diff --git a/libstdc++-v3/include/tr1/complex b/libstdc++-v3/include/tr1/complex
index 5df17bb09b5..39205afefdc 100644
--- a/libstdc++-v3/include/tr1/complex
+++ b/libstdc++-v3/include/tr1/complex
@@ -35,6 +35,7 @@
#define _TR1_COMPLEX 1
#include "../complex"
+#include <tr1/common.h>
// namespace std::tr1
namespace std
@@ -51,7 +52,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
template<typename _Tp> std::complex<_Tp> fabs(const std::complex<_Tp>&);
- /// @brief acos(__z) [8.1.2]
+ /// @brief acos(__z) [8.1.2].
// Effects: Behaves the same as C99 function cacos, defined
// in subclause 7.3.5.1.
template<typename _Tp>
@@ -87,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_acos(__z); }
#endif
- /// @brief asin(__z) [8.1.3]
+ /// @brief asin(__z) [8.1.3].
// Effects: Behaves the same as C99 function casin, defined
// in subclause 7.3.5.2.
template<typename _Tp>
@@ -123,7 +124,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_asin(__z); }
#endif
- /// @brief atan(__z) [8.1.4]
+ /// @brief atan(__z) [8.1.4].
// Effects: Behaves the same as C99 function catan, defined
// in subclause 7.3.5.3.
template<typename _Tp>
@@ -167,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_atan(__z); }
#endif
- /// @brief acosh(__z) [8.1.5]
+ /// @brief acosh(__z) [8.1.5].
// Effects: Behaves the same as C99 function cacosh, defined
// in subclause 7.3.6.1.
template<typename _Tp>
@@ -206,7 +207,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_acosh(__z); }
#endif
- /// @brief asinh(__z) [8.1.6]
+ /// @brief asinh(__z) [8.1.6].
// Effects: Behaves the same as C99 function casin, defined
// in subclause 7.3.6.2.
template<typename _Tp>
@@ -245,7 +246,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_asinh(__z); }
#endif
- /// @brief atanh(__z) [8.1.7]
+ /// @brief atanh(__z) [8.1.7].
// Effects: Behaves the same as C99 function catanh, defined
// in subclause 7.3.6.3.
template<typename _Tp>
@@ -289,7 +290,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __complex_atanh(__z); }
#endif
- /// @brief fabs(__z) [8.1.8]
+ /// @brief fabs(__z) [8.1.8].
// Effects: Behaves the same as C99 function cabs, defined
// in subclause 7.3.8.1.
template<typename _Tp>
@@ -297,6 +298,97 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
fabs(const std::complex<_Tp>& __z)
{ return std::abs(__z); }
+
+ /// @brief Additional overloads [8.1.9].
+ //
+
+ // See common.h for the primary template.
+ template<typename _Tp, typename _Up>
+ struct __promote_2<std::complex<_Tp>, _Up>
+ {
+ public:
+ typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
+ };
+
+ template<typename _Tp, typename _Up>
+ struct __promote_2<_Tp, std::complex<_Up> >
+ {
+ public:
+ typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
+ };
+
+ template<typename _Tp, typename _Up>
+ struct __promote_2<std::complex<_Tp>, std::complex<_Up> >
+ {
+ public:
+ typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
+ };
+
+
+ template<typename _Tp>
+ inline typename __promote<_Tp>::__type
+ arg(_Tp __x)
+ {
+ typedef typename __promote<_Tp>::__type __type;
+ return std::arg(std::complex<__type>(__x));
+ }
+
+ template<typename _Tp>
+ inline std::complex<typename __promote<_Tp>::__type>
+ conj(_Tp __x)
+ { return __x; }
+
+ template<typename _Tp>
+ inline typename __promote<_Tp>::__type
+ imag(_Tp)
+ { return _Tp(); }
+
+ template<typename _Tp>
+ inline typename __promote<_Tp>::__type
+ norm(_Tp __x)
+ {
+ typedef typename __promote<_Tp>::__type __type;
+ return __type(__x) * __type(__x);
+ }
+
+ template<typename _Tp, typename _Up>
+ inline std::complex<typename __promote_2<_Tp, _Up>::__type>
+ polar(const _Tp& __rho, const _Up& __theta)
+ {
+ typedef typename __promote_2<_Tp, _Up>::__type __type;
+ return std::polar(__type(__rho), __type(__theta));
+ }
+
+ template<typename _Tp, typename _Up>
+ inline std::complex<typename __promote_2<_Tp, _Up>::__type>
+ pow(const std::complex<_Tp>& __x, const _Up& __y)
+ {
+ typedef typename __promote_2<_Tp, _Up>::__type __type;
+ return std::pow(std::complex<__type>(__x), __type(__y));
+ }
+
+ template<typename _Tp, typename _Up>
+ inline std::complex<typename __promote_2<_Tp, _Up>::__type>
+ pow(const _Tp& __x, const std::complex<_Up>& __y)
+ {
+ typedef typename __promote_2<_Tp, _Up>::__type __type;
+ return std::pow(__type(__x), std::complex<__type>(__y));
+ }
+
+ template<typename _Tp, typename _Up>
+ inline std::complex<typename __promote_2<_Tp, _Up>::__type>
+ pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y)
+ {
+ typedef typename __promote_2<_Tp, _Up>::__type __type;
+ return std::pow(std::complex<__type>(__x),
+ std::complex<__type>(__y));
+ }
+
+ template<typename _Tp>
+ inline typename __promote<_Tp>::__type
+ real(_Tp __x)
+ { return __x; }
+
_GLIBCXX_END_NAMESPACE
}
OpenPOWER on IntegriCloud