📄 testcordic.cpp
字号:
// test class Cordic
#include "Cordic.h"
#include "Dformat.h"
#include "data.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <cmath>
#define M_int 1
#define N_fract 30
using namespace std;
void main()
{
Dformat Dataformat( M_int,N_fract );
Cordic test( Dataformat);
// test Sin/Cos-----------------------------------------------------
ofstream SINE( "_sin.dat",ios::app ),COSINE( "_cos.dat",ios::app );
// create file out.dat to store sin(theta)
if( !SINE || !COSINE )
{
cerr << "_sin.dat could not be created." << endl;
exit(0);
}
for( unsigned i =0;i<NUM;++i )
{
test.set( 1,0,_theta[i] );
SINE << test.Sin() << endl;
COSINE << test.Cos() << endl;
}
test.print( SINE );
test.print( COSINE );
// test Abs/Atan -----------------------------------------------------
ofstream ABS( "_abs.dat",ios::app ),ATAN( "_atan.dat",ios::app );
if( !ABS || !ATAN )
{
cerr << "_abs.dat could not be created." << endl;
exit(0);
}
test.set( 2,29 ); // ATTENTION m=1,n=30 will overflow
for( unsigned i=0;i<NUM;++i )
{
test.set( _x[i],_y[i],0 );
ABS << test.Abs() << endl;
test.set( 1,_y[i],0 );
ATAN << test.Atan() << endl;
}
test.print( ABS );
test.print( ATAN );
// test Mult ---------------------------------------------------------
ofstream MULT( "_mult.dat",ios::app );
if( !MULT )
{
cerr << "_mult.dat could not be created." << endl;
exit(0);
}
test.set( M_int,N_fract );// default
for( unsigned i=0;i<NUM;++i )
{
test.set( _x[i],0,_y[i] );
MULT << test.Mult() << endl;
}
test.print( MULT );
// test Dev ----------------------------------------------------------
ofstream DEV( "_dev.dat",ios::app );
if( !DEV )
{
cerr << "_dev.dat could not be created." << endl;
exit(0);
}
for( unsigned i=0;i<NUM;++i )
{
test.set( _x[i],_y[i],0 );
DEV << test.Dev() << endl;
}
test.print( DEV );
// test Sinh/Cosh ----------------------------------------------------
ofstream SINH( "_sinh.dat",ios::app ),COSH( "_cosh.dat",ios::app );
if( !SINH || !COSH )
{
cerr << "_sin.dat could not be created." << endl;
exit(0);
}
test.set( 2,29 );// modify Qm.n
for( unsigned i =0;i<NUM;++i )
{
test.set( 1,0,_theta[i] );
SINH << test.Sinh() << endl;
COSH << test.Cosh() << endl;
}
test.print( SINH );
test.print( COSH );
// test Sqrt/Atanh ----------------------------------------------------
ofstream SQRT( "_sqrt.dat",ios::app ),ATANH( "_atanh.dat",ios::app );
test.set( M_int,N_fract );
for( unsigned i=0;i<NUM;++i )
{
test.set( _sqrt[i]+0.25,_sqrt[i]-0.25,0 );
SQRT << test.Sqrt() << endl;
test.set( 1,_atanh[i],0 );
ATANH << test.Atanh() << endl;
}
test.print( SQRT );
test.print( ATANH );
test.print( cout );
_getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -