📄 c32_asm.cpp
字号:
// C32_ASM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
extern "C" {
long dosFIX_MPY32(long x,long y);
long dosFIX_MPY32_C(long x,long y);
long VectorMul32(const long v1[],const long v2[],long n);
long VectorMul32_C(const long v1[],const long v2[],long n);
long FixLog32(long x,long e);
long FixLog32_C(long x,long e);
long FixSqrt32(long x,long y);
long FixSqrt32_C(long x,long y);
};
/*
int main()
{
char buf[8];
double m=0;
for (int k=0;k<1000;k++) {
for (int i=0;i<8;i++)
buf[i]=(char)rand();
long x=*(long*)buf,y=*(long*)(buf+4);
long xy=dosFIX_MPY32_C(x,y);
double fxy=(double)x*((double)y/0x80000000u);
double d=fabs(fxy-xy); if (d>m) m=d;
if (d>1)
printf("%d\t",k);
}
printf("\n");
printf("Max Delta=%lf\n",m);
//printf("x=%ld\ty=%ld\nxy=%ld\tfxy=%lf\tdelta=%lf%%\n",x,y,xy,fxy,(xy-fxy)/fxy*100);
getch(); return 0;
}
*/
/*
#define N 60
int main()
{
char buf[8];
double m=0;
for (int k=0;k<1000;k++) {
long x[N],y[N];
for (int l=0;l<N;l++) {
for (int i=0;i<8;i++)
buf[i]=(char)rand();
buf[3]=(buf[3]<0)?-1:0;
x[l]=*(long*)buf; y[l]=*(long*)(buf+4);
}
long xy=VectorMul32_C(x,y,N);
double fxy=0; for (l=0;l<N;l++) fxy+=(double)x[l]*((double)y[l]/0x80000000u);
double d=fabs(fxy-xy); if (d>m) m=d;
if (d>N)
printf("%d\t",k);
}
printf("\n");
printf("Max Delta=%lf\n",m);
getch(); return 0;
}
*/
/*
int main()
{
char buf[4];
double m=0;
for (int k=0;k<1000;k++) {
for (int i=0;i<4;i++)
buf[i]=(char)rand();
if (buf[3]<0) buf[3]=-buf[3];
long x=*(long*)buf,e=rand()*52/RAND_MAX-10;
long lx0=FixLog32(x,e),lx=FixLog32_C(x,e);
double flx=log((double)x/pow(2,e));
double d=fabs(flx*(1<<26)-(double)lx); if (d>m) m=d;
if (d>100)
printf("%d\t",k);
}
printf("\n");
printf("Max Delta=%lf\n",m);
//printf("x=%ld\ty=%ld\nxy=%ld\tfxy=%lf\tdelta=%lf%%\n",x,y,xy,fxy,(xy-fxy)/fxy*100);
getch(); return 0;
}
*/
int main()
{
char buf[8];
double m=0;
for (int k=0;k<100000;k++) {
for (int i=0;i<8;i++)
buf[i]=(char)rand();
long x=*(long*)buf,y=*(long*)(buf+4);
x/=2; y/=2;
long xy=FixSqrt32_C(x,y);
double fxy=sqrt((double)x*x+(double)y*y);
double d=fabs(fxy-xy); if (d>m) m=d;
if (d>1000)
printf("%d\t",k);
}
printf("\n");
printf("Max Delta=%lf\n",m);
//printf("x=%ld\ty=%ld\nxy=%ld\tfxy=%lf\tdelta=%lf%%\n",x,y,xy,fxy,(xy-fxy)/fxy*100);
getch(); return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -