// The template and inlines for the -*- C++ -*- complex number classes. // Copyright (C) 1994 Free Software Foundation // This file is part of the GNU ANSI 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 GNU CC; see the file COPYING. If not, write to // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // As a special exception, if you link this library with files compiled // with a GNU compiler to produce an executable, this does not 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. // Written by Jason Merrill based upon the specification in the 27 May 1994 // C++ working paper, ANSI document X3J16/94-0098. #ifdef __GNUG__ #pragma interface #endif #include template class __complex { public: __complex (FLOAT r = 0, FLOAT i = 0): re (r), im (i) { } __complex& operator += (__complex); __complex& operator -= (__complex); __complex& operator *= (__complex); __complex& operator /= (__complex); private: FLOAT re, im; friend FLOAT real (__complex); friend FLOAT imag (__complex); }; // Declare specializations. class __complex; class __complex; template inline __complex& __complex::operator += (__complex r) { re += r.re; im += r.im; return *this; } template inline __complex& __complex::operator -= (__complex r) { re -= r.re; im -= r.im; return *this; } template inline __complex& __complex::operator *= (__complex r) { FLOAT f = re * r.re - im * r.im; im = re * r.im + im * r.re; re = f; return *this; } template inline FLOAT imag (__complex x) { return x.im; } template inline FLOAT real (__complex x) { return x.re; } #ifdef __GNUG__ extern template float imag (__complex); extern template float real (__complex); #endif template inline __complex operator + (__complex x, __complex y) { return __complex (real (x) + real (y), imag (x) + imag (y)); } template inline __complex operator + (__complex x, FLOAT y) { return __complex (real (x) + y, imag (x)); } template inline __complex operator + (FLOAT x, __complex y) { return __complex (x + real (y), imag (y)); } template inline __complex operator - (__complex x, __complex y) { return __complex (real (x) - real (y), imag (x) - imag (y)); } template inline __complex operator - (__complex x, FLOAT y) { return __complex (real (x) - y, imag (x)); } template inline __complex operator - (FLOAT x, __complex y) { return __complex (x - real (y), - imag (y)); } template inline __complex operator * (__complex x, __complex y) { return __complex (real (x) * real (y) - imag (x) * imag (y), real (x) * imag (y) + imag (x) * real (y)); } template inline __complex operator * (__complex x, FLOAT y) { return __complex (real (x) * y, imag (x) * y); } template inline __complex operator * (FLOAT x, __complex y) { return __complex (x * real (y), x * imag (y)); } template __complex operator / (__complex x, FLOAT y) { return __complex (real (x) / y, imag (x) / y); } template inline __complex operator + (__complex x) { return x; } template inline __complex operator - (__complex x) { return __complex (-real (x), -imag (x)); } template inline bool operator == (__complex x, __complex y) { return real (x) == real (y) && imag (x) == imag (y); } template inline bool operator == (__complex x, FLOAT y) { return real (x) == y && imag (x) == 0; } template inline bool operator == (FLOAT x, __complex y) { return x == real (y) && imag (y) == 0; } template inline bool operator != (__complex x, __complex y) { return real (x) != real (y) || imag (x) != imag (y); } template inline bool operator != (__complex x, FLOAT y) { return real (x) != y || imag (x) != 0; } template inline bool operator != (FLOAT x, __complex y) { return x != real (y) || imag (y) != 0; } template inline FLOAT abs (__complex x) { return hypot (real (x), imag (x)); } template inline FLOAT arg (__complex x) { return atan2 (imag (x), real (x)); } template inline __complex polar (FLOAT r, FLOAT t) { return __complex (r * cos (t), r * sin (t)); } template inline __complex conj (__complex x) { return __complex (real (x), -imag (x)); } template inline FLOAT norm (__complex x) { return real (x) * real (x) + imag (x) * imag (x); } // Declarations of templates in complext.ccI template __complex operator / (__complex, __complex); template __complex operator / (FLOAT, __complex); template __complex cos (__complex); template __complex cosh (__complex); template __complex exp (__complex); template __complex log (__complex); template __complex pow (__complex, __complex); template __complex pow (__complex, FLOAT); template __complex pow (__complex, int); template __complex pow (FLOAT, __complex); template __complex sin (__complex); template __complex sinh (__complex); template __complex sqrt (__complex); class istream; class ostream; template istream& operator >> (istream&, __complex&); template ostream& operator << (ostream&, __complex); // Specializations and such template inline __complex _float_complex(const __complex& r) { return __complex (real (r), imag (r)); } #include #include // Declare the instantiations. #include