⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complex.h

📁 使用量子轨道方法计算量子主方程的C++库
💻 H
字号:
// Complex.h     -*- C++ -*-/* Copyright (C) 1988 Free Software Foundation    written by Doug Lea (dl@rocky.oswego.edu)This file is part of the GNU C++ Library.  This library is freesoftware; you can redistribute it and/or modify it under the terms ofthe GNU Library General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at youroption) any later version.  This library is distributed in the hopethat it will be useful, but WITHOUT ANY WARRANTY; without even theimplied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE.  See the GNU Library General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, 675 Mass Ave, Cambridge, MA 02139, USA.*/// Modified by rschack#ifndef _Complex_hhh#define _Complex_hhh 1#include <iostream.h>#include <math.h>class Complex{public://protected:  double           re;  double           im;  double           real() const;  double           imag() const;                   Complex();                   Complex(const Complex& y);                   Complex(double r, double i=0);                  ~Complex();  Complex&         operator =  (const Complex& y);  Complex&         operator += (const Complex& y);  Complex&         operator += (double y);  Complex&         operator -= (const Complex& y);  Complex&         operator -= (double y);  Complex&         operator *= (const Complex& y);  Complex&         operator *= (double y);  Complex&         operator /= (const Complex& y);   Complex&         operator /= (double y);   void             error(const char* msg) const;  Complex&         timesI ();  Complex&         timesMinusI ();};// non-inline functionsdouble    hypotenuse (double, double);Complex   operator /  (const Complex& x, const Complex& y);Complex   operator /  (const Complex& x, double y);Complex   operator /  (double   x, const Complex& y);Complex   cos(const Complex& x);Complex   sin(const Complex& x);Complex   cosh(const Complex& x);Complex   sinh(const Complex& x);Complex   exp(const Complex& x);Complex   log(const Complex& x);Complex   pow(const Complex& x, int p);Complex   pow(const Complex& x, const Complex& p);Complex   pow(const Complex& x, double y);Complex   sqrt(const Complex& x);   istream&  operator >> (istream& s, Complex& x);ostream&  operator << (ostream& s, const Complex& x);// inline membersinline double  Complex::real() const { return re; }inline double  Complex::imag() const { return im; }inline Complex::Complex() {}inline Complex::Complex(const Complex& y) :re(y.real()), im(y.imag()) {}inline Complex::Complex(double r, double i) :re(r), im(i) {}inline Complex::~Complex() {}inline Complex&  Complex::operator =  (const Complex& y) {   re = y.real(); im = y.imag(); return *this; } inline Complex&  Complex::operator += (const Complex& y){   re += y.real();  im += y.imag(); return *this; }inline Complex&  Complex::operator += (double y){   re += y; return *this; }inline Complex&  Complex::operator -= (const Complex& y){   re -= y.real();  im -= y.imag(); return *this; }inline Complex&  Complex::operator -= (double y){   re -= y; return *this; }inline Complex&  Complex::operator *= (const Complex& y){    double r = re * y.real() - im * y.imag();  im = re * y.imag() + im * y.real();   re = r;   return *this; }inline Complex&  Complex::operator *= (double y){    re *=  y; im *=  y; return *this; }//  functionsinline int  operator == (const Complex& x, const Complex& y){  return x.real() == y.real() && x.imag() == y.imag();}inline int  operator == (const Complex& x, double y){  return x.imag() == 0.0 && x.real() == y;}inline int  operator != (const Complex& x, const Complex& y){  return x.real() != y.real() || x.imag() != y.imag();}inline int  operator != (const Complex& x, double y){  return x.imag() != 0.0 || x.real() != y;}inline Complex  operator - (const Complex& x){  return Complex(-x.real(), -x.imag());}inline Complex  conj(const Complex& x){  return Complex(x.real(), -x.imag());}inline Complex  operator + (const Complex& x, const Complex& y){  return Complex(x.real() + y.real(), x.imag() + y.imag());}inline Complex  operator + (const Complex& x, double y){  return Complex(x.real() + y, x.imag());}inline Complex  operator + (double x, const Complex& y){  return Complex(x + y.real(), y.imag());}inline Complex  operator - (const Complex& x, const Complex& y){  return Complex(x.real() - y.real(), x.imag() - y.imag());}inline Complex  operator - (const Complex& x, double y){  return Complex(x.real() - y, x.imag());}inline Complex  operator - (double x, const Complex& y){  return Complex(x - y.real(), -y.imag());}inline Complex  operator * (const Complex& x, const Complex& y){  return Complex(x.real() * y.real() - x.imag() * y.imag(),                  x.real() * y.imag() + x.imag() * y.real());}inline Complex  operator * (const Complex& x, double y){  return Complex(x.real() * y, x.imag() * y);}inline Complex  operator * (double x, const Complex& y){  return Complex(x * y.real(), x * y.imag());}inline double  real(const Complex& x){  return x.real();}inline double  imag(const Complex& x){  return x.imag();}inline double  abs(const Complex& x){  return hypotenuse(x.real(), x.imag());}inline double  norm(const Complex& x){  return (x.real() * x.real() + x.imag() * x.imag());}inline double  arg(const Complex& x){  return atan2(x.imag(), x.real());}inline Complex  polar(double r, double t){  return Complex(r * cos(t), r * sin(t));}#endif //_Complex_hhh

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -