unroller.cpp
来自「3D游戏编程领域的老手撰写的启迪性文章之一」· C++ 代码 · 共 35 行
CPP
35 行
#include <iostream.h>
#include <math.h>
#include <complex.h>
#include <fstream.h>
void main(void)
{
int k, n; // intergers for the loops
complex mult; // a complex number
float prod; // a floating point number for the real component
complex i=complex(0, 1); // the square root of -1
fstream file; // a file to store the generated source code in
file.open("FFT.C", ios::out); // opens a text file
for(k=0; k<512; k++) // loops through each sub harmonic
{
for(n=0; n<1024; n++) // loops through each sample
{
mult=exp((-2*M_PI*i*k*(n+1))/1024); // calculates the equation
prod=real(mult); // gets the real component
if(prod!=0) // eliminates useless lines of code
{
if(prod!=1) // only multiplies if the product isn't 1
{
file<<" Net.Input["<<k<<"]=+X["<<n<<"]"<<"*"<<prod<<";\n";
}
else // prints only the variable because the product is 1
{
file<<" Net.Input["<<k<<"]=+X["<<n<<"];\n";
}
}
}
}
file.close(); // closes the file
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?