dformat.cpp
来自「这个包里面包含了对Cordic算法的基本函数实现。通过Dformat类来控制系统」· C++ 代码 · 共 70 行
CPP
70 行
#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 + =
减小字号Ctrl + -
显示快捷键?