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

📄 complex.cc

📁 计算f t)=exp -|t|)的FFT
💻 CC
字号:
#include <iostream>
#include <math.h>
#include "complex.h"
using namespace std;

Complex::Complex(void){
	this->real=0;
	this->image=0;
}

Complex::Complex(double a,double b){
	this->real=a;
	this->image=b;	
}

Complex Complex::operator+(Complex c){
	double a,b;
	a=this->real+c.real;
	b=this->image+c.image;
	return Complex(a,b);
}

Complex Complex::operator-(Complex c){
	double a,b;
	a=this->real-c.real;
	b=this->image-c.image;
	return Complex(a,b);
}

Complex Complex::operator*(Complex c){
	double a,b;
	a=this->real*c.real-this->image*c.image;
	b=this->real*c.image+this->image*c.real;
	return Complex(a,b);
}

Complex Complex::operator*(double c){
	double a,b;
	a=this->real*c;
	b=this->image*c;
	return Complex(a,b);
}

Complex Complex::operator/(Complex c){
	return (*this)*c*Complex(1/(c.real*c.real+c.image*c.image),0);
}

Complex &Complex::operator=(double c){
	this->real=c;
	this->image=0;
	return *this;
}

double Complex::getReal(void){
	return real;
}

double Complex::getImage(void){
	return image;
}

Complex Complex::power(int n){
	int i;
	Complex c(1,0);
	if(n)
		for(i=1;i<=n;i++){
			c=c*(*this);
		}
	return c;
}

int Complex::operator==(Complex c){
	if(this->real==c.real&&this->image==c.image)return 1;
	return 0;
}

Complex Complex::conj(void){
	return Complex(this->real,(-1.)*this->image);
}

void Complex::print(void){
	if(this->image>0)
		cout << this->real << "+" << this->image << "i" ;
	else if(this->image==0)
		cout << this->real ;
	else
		cout << this->real << this->image << "i" ;
}

void Complex::fprint(FILE *f){
	if(this->image>=0)
		fprintf(f,"%12.9f+%15.9e i",this->real,this->image);
	else
		fprintf(f,"%12.9f%15.9e i",this->real,this->image);
}

⌨️ 快捷键说明

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