opt13.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 44 行
C
44 行
#include "fail.h"
#include <math.h>
#include <assert.h>
double drand48() {
double x;
x = rand();
x /= RAND_MAX;
return x;
}
/* Return random integer in [1,maxint], perturbed by [-1,1]*noise */
double randnoisyint(unsigned long maxint, double noise)
{
double d = 1.0 + (rand()%maxint) + (2*drand48()-1)*noise;
assert( d != 0 );
return d;
}
int main()
{
unsigned long maxint;
int samplesize=1e3;
int b, i, cnt;
double num, den, tol, noise;
for (tol = 1e-5; tol >= 1e-11; tol *= .01) {
for (maxint = 10; maxint <= 1e5; maxint *= 10) {
for (noise = .999, b = 0; b < 14; noise *= .1, b++) {
for (i = 0, cnt = 0; i < samplesize; i++) {
num = randnoisyint(maxint, noise);
assert( num != 0 );
den = randnoisyint(maxint, noise);
assert( den != 0 );
cnt += (((num-(num/den)*den)/num)>tol);
}
if( cnt != 0 ) fail(__LINE__);
}
}
}
_PASS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?