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

📄 dformat.cpp

📁 这个包里面包含了对Cordic算法的基本函数实现。通过Dformat类来控制系统的数据格式
💻 CPP
字号:
#include "Dformat.h"
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

Dformat::Dformat( unsigned M,unsigned N )
{
	set(M,N);
}

Dformat::Dformat(const Dformat &dfmt)
{
	m = dfmt.getm();
	n = dfmt.getn();
}

long Dformat::trans2Q( double fptr )const
{
	long factor =static_cast<long>( pow( (double)2,(int)n ) );
	return static_cast<long>( fptr*factor );
}

double Dformat::trans2f( long iptr )const
{
	double devidor =pow( (double)2,(int)n );
	return ( iptr/devidor );
}

void Dformat::set(const unsigned int M,const unsigned int N)
{
	if( validator( M,N )==false )
	{
		cout << "The given data format isn't supported.\n"
			 << "-----------------------------------------\n\n";
		m=M_CORDIC;
		n=N_CORDIC;
	}
	else { m=M;n=N; }
}

const unsigned& Dformat::getm() const
{
	return m;
}

const unsigned& Dformat::getn() const
{
	return n;
}

void Dformat::print( ostream& output )const
{
	output << left << setw(10) << "Qm.n" 
		   << "m=" << m << "  n=" << n << endl;
}

Dformat::~Dformat(void)
{
}

// utility function
bool Dformat::validator( const unsigned M,const unsigned N ) const
{
	if( ( M+N>M_CORDIC+N_CORDIC )||( M+N==0 ))
		return false;
	else return true;
}

⌨️ 快捷键说明

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