// The template and inlines for the -*- C++ -*- complex number classes.
-// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+// 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
// Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
//
-/** @file std_complex.h
- * This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
+/** @file complex
+ * This is a Standard C++ Library header. You should @c #include this header
+ * in your programs, rather than any of the "st[dl]_*.h" implementation files.
*/
#ifndef _CPP_COMPLEX
__s.flags(__os.flags());
__s.imbue(__os.getloc());
__s.precision(__os.precision());
- __s << '(' << __x.real() << "," << __x.imag() << ')';
+ __s << '(' << __x.real() << ',' << __x.imag() << ')';
return __os << __s.str();
}
{
_Tp __x = __z.real();
_Tp __y = __z.imag();
- const _Tp __s = max(abs(__x), abs(__y));
+ const _Tp __s = std::max(abs(__x), abs(__y));
if (__s == _Tp()) // well ...
return __s;
__x /= __s;
inline _Tp
norm(const complex<_Tp>& __z)
{
- return _Norm_helper<__is_floating<_Tp>::_M_type>::_S_do_it(__z);
+ return _Norm_helper<__is_floating<_Tp>::_M_type && !_GLIBCPP_FAST_MATH>::_S_do_it(__z);
}
template<typename _Tp>
}
template<typename _Tp>
- inline complex<_Tp>
+ complex<_Tp>
pow(const complex<_Tp>& __x, const _Tp& __y)
{
- return exp(__y * log(__x));
+ if (__x.imag() == _Tp())
+ return pow(__x.real(), __y);
+
+ complex<_Tp> __t = log(__x);
+ return polar(exp(__y * __t.real()), __y * __t.imag());
}
template<typename _Tp>
inline complex<_Tp>
pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
- return exp(__y * log(__x));
+ return __x == _Tp() ? _Tp() : exp(__y * log(__x));
}
template<typename _Tp>
inline complex<_Tp>
pow(const _Tp& __x, const complex<_Tp>& __y)
{
- return exp(__y * log(__x));
+ return __x == _Tp()
+ ? _Tp()
+ : polar(pow(__x, __y.real()), __y.imag() * log(__x));
}
// 26.2.3 complex specializations