码迷,mamicode.com
首页 > 编程语言 > 详细

C++ IEEE754 数据生成

时间:2017-09-29 22:58:51      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:stdio.h   library   stream   sign   项目   eee   class   nta   ace   

由于手头的FPGA项目需要生成三角函数的表,所以有如下程序。

最近时间紧,后面抽空把注释补上。

#include <iostream>
#include <fstream>
#include<stdio.h>
#include <cmath>

using namespace std;



int main(void)
{
    ofstream fotan("/Users/tantaiyunfei/Documents/ttyfLibrary/C++/actan/cos.txt");

    float pi=3.1415926;

    for(float f=0;f<pi/2;)
    {
        //float m=f;
        float m=cos(f);
        unsigned char *p, ch;
        int i;
        p = (unsigned char *) (&m);


        i = sizeof(m);

        for (i = sizeof(m) - 1; i >= 0; i--) {
            ch = *(p + i);
            int j;
            for(j=0;j<8;j++)
            {
                if( (ch<<j) & 0x80) fotan<<1;
                else fotan<<0;
            }


        }
        f=f+0.0001;
        fotan<<"\n";
    }
    fotan.close();
    return 0;
}

 

C++ IEEE754 数据生成

标签:stdio.h   library   stream   sign   项目   eee   class   nta   ace   

原文地址:http://www.cnblogs.com/TTYF/p/7612844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!