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

📄 fixmean.cpp

📁 这是我本人编写的一个32位定点小数运算的函数库。对于没有浮点运算器的场合
💻 CPP
字号:
// FixMean.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>

long FixMean32(long* x,int n);
long FixMean32_C(long* x,int n);

#define N 1151

int main(int argc, char* argv[])
{
	double sum=0,maxd=0;
	for (int i=0;i<10000;i++) {
		long x[N];
		double y=0;
		for (int j=0;j<N;j++) {
			x[j]=(rand()<<17)+(rand()<<2)+(rand()&0x3);
			y+=(double)x[j]/(1<<20);
		}
		long x1=FixMean32(x,N),xx=FixMean32_C(x,N);
		double yy=y/N;

		double d=fabs(yy-(double)xx/(1<<20));
		if (d>maxd) maxd=d;
		sum+=d;
	}
	printf("Max Delta = %16.12lf\n",maxd);
	printf("Aver Delta = %16.12lf\n",sum/10000);
	getch();

	return 0;
}

⌨️ 快捷键说明

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