cplx.h

来自「QWT5.01用于Qt开发的二维图形库程序」· C头文件 代码 · 共 63 行

H
63
字号
#ifndef BODE_CPLX_H
#define BODE_CPLX_H

#include <math.h>


class cplx {
private:
    double re,im;

public:

    double real() {return re;}
    double imag() {return im;}

    cplx() {
        re = 0.0;
        im  = -0.0;
    }

    cplx& operator= (cplx a) {
        re = a.re;
        im = a.im;
        return *this;
    }

    cplx(double r, double i = 0.0) {
        re = r;
        im = i;
    }

    friend cplx operator * (cplx x1, cplx x2);
    friend cplx operator + (cplx x1, cplx x2);
    friend cplx operator - (cplx x1, cplx x2);
    friend cplx operator / (cplx x1, cplx x2);

};

inline cplx operator+(cplx x1, cplx x2)
{
    return cplx(x1.re + x2.re, x1.im + x2.im);
}

inline cplx operator-(cplx x1, cplx x2)
{
    return cplx(x1.re - x2.re, x1.im - x2.im);
}

inline cplx operator*(cplx x1, cplx x2)
{
    return cplx(x1.re * x2.re - x1.im * x2.im,
        x1.re * x2.im + x2.re * x1.im);
}

inline cplx operator/(cplx x1, cplx x2)
{
    double denom = x2.re * x2.re + x2.im * x2.im;
    return cplx( (x1.re * x2.re + x1.im * x2.im) /denom,
            (x1.im * x2.re - x2.im * x1.re) / denom);
}

#endif

⌨️ 快捷键说明

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