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

📄 ieetst.c

📁 linux下用PCMCIA无线网卡虚拟无线AP的程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Test printf-scanf identity */
if( ecmp( print, scan ) != 0 )
	{
	pvec( print, NE );
	printf( " ->printf-> %s ->scanf->\n", string );
	pvec( scan, NE );
	printf( " is not an identity.\n" );
	++identerr;
	}
}


/* Check scanf result
 */
void chkscan( ref, tst, string )
unsigned short ref[], tst[];
char *string;
{
/* Test scanf()  */
if( ecmp( ref, tst ) != 0 )
	{
	printf( "scanf(%s) -> ", string );
	pvec( tst, NE );
	printf( "\n should be    " );
	pvec( ref, NE );
	printf( ".\n" );
	++errscan;
	++errtot;
	}
}


/* Test printf() result
 */
void chkprint( ref, tst, string ) 
unsigned short ref[], tst[];
char *string;
{
if( ecmp(ref, tst) != 0 )
	{
	printf( "printf( ");
	pvec( ref, NE );
	printf( ") -> %s\n", string );
	printf( "      = " );
	pvec( tst, NE );
	printf( ".\n" );
	++errprint;
	++errtot;
	}
}


/* Print array of n 16-bit shorts
 */
void pvec( x, n )
unsigned short x[];
int n;
{
int i;

for( i=0; i<n; i++ )
	{
	printf( "%04x ", x[i] );
	}
}

/* Measure worst case printf rounding error
 */
void cmpprint( ref, tst )
unsigned short ref[], tst[];
{
unsigned short e[NE];

if( ecmp( ref, ezero ) != 0 )
	{
	esub( ref, tst, e );
	ediv( ref, e, e );
	eabs( e );
	if( ecmp( e, rprint ) > 0 )
		emov( e, rprint );
	}
}

/* Measure worst case scanf rounding error
 */
void cmpscan( ref, tst )
unsigned short ref[], tst[];
{
unsigned short er[NE];

if( ecmp( ref, ezero ) != 0 )
	{
	esub( ref, tst, er );
	ediv( ref, er, er );
	eabs( er );
	if( ecmp( er, rscan ) > 0 )
		emov( er, rscan );
	if( ecmp( er, ehalf ) > 0 )
		{
		etoasc( tst, str1, 21 );
		printf( "Bad error: scanf(%s) = %s !\n", str0, str1 );
		}
	}
}

/* Check rounded-down decimal string output of printf
 */
void cmptrunc( ref, tst )
unsigned short ref[], tst[];
{
if( ecmp( ref, tst ) != 0 )
	{
	printf( "printf(%s%s%s, %s) -> %s\n", quo, tformat, quo, str1, str2 );
	printf( "should be      %s .\n", str3 );
	errprint += 1;
	}
}


void shownoncrit()
{

etoasc( rprint, str0, 3 );
printf( "Maximum relative printf error found = %s .\n", str0 );
etoasc( rscan, str0, 3 );
printf( "Maximum relative scanf error found = %s .\n", str0 );
}



/* Produce arguments and call comparison subroutines.
 */
void chkit( testno )
int testno;
{
unsigned short t[NE], u[NE], v[NE];
int j;

switch( mprec )
	{
#if LDOUBLE
	case 64:
		etoe64( fullp, &prec64 );
		e64toe( &prec64, rounded );
#if CHKINTERNAL
		e64toasc( &prec64, str1, SPREC );
		asctoe64( str1, &xprec64 );
		e64toe( &xprec64, t );
		chkinternal( rounded, t, str1 );
#endif
/* check printf and scanf */
		sprintf( str2, format, prec64 );
		sscanf( str2, fformat, &sprec64 );
		e64toe( &sprec64, u );
		chkid( rounded, u, str2 );
		asctoe64( str2, &ssprec64 );
		e64toe( &ssprec64, v );
		chkscan( v, u, str2 );
		chkprint( rounded, v, str2 );
		if( testno < 8 )
			break;
/* rounding error measurement */
		etoasc( fullp, str0, 24 );
		etoe64( fullp, &ssprec64 );
		e64toe( &ssprec64, u );
		sprintf( str2, format, ssprec64 );
		asctoe( str2, t );
		cmpprint( u, t );
		sscanf( str0, fformat, &sprec64 );
		e64toe( &sprec64, t );
		cmpscan( fullp, t );
		if( testno < 8 )
			break;
/* strings rounded to less than maximum precision */
		e64toasc( &ssprec64, str1, 24 );
		for( j=SPREC-1; j>0; j-- )		
			{
			e64toasc( &ssprec64, str3, j );
			asctoe( str3, v );
			sprintf( tformat, "%s.%dLe", pct, j );
			sprintf( str2, tformat, ssprec64 );
			asctoe( str2, t );
			cmptrunc( v, t );
			}
		break;
#endif
#ifdef DEC
	case 56:
#endif
	case 53:
		etoe53( fullp, &prec53 );
		e53toe( &prec53, rounded );
#if CHKINTERNAL
		e53toasc( &prec53, str1, SPREC );
		asctoe53( str1, &xprec53 );
		e53toe( &xprec53, t );
		chkinternal( rounded, t, str1 );
#endif
		sprintf( str2, format, prec53 );
		sscanf( str2, fformat, &sprec53 );
		e53toe( &sprec53, u );
		chkid( rounded, u, str2 );
		asctoe53( str2, &ssprec53 );
		e53toe( &ssprec53, v );
		chkscan( v, u, str2 );
		chkprint( rounded, v, str2 );
		if( testno < 8 )
			break;
/* rounding error measurement */
		etoasc( fullp, str0, 24 );
		etoe53( fullp, &ssprec53 );
		e53toe( &ssprec53, u );
		sprintf( str2, format, ssprec53 );
		asctoe( str2, t );
		cmpprint( u, t );
		sscanf( str0, fformat, &sprec53 );
		e53toe( &sprec53, t );
		cmpscan( fullp, t );
		if( testno < 8 )
			break;
		e53toasc( &ssprec53, str1, 24 );
		for( j=SPREC-1; j>0; j-- )		
			{
			e53toasc( &ssprec53, str3, j );
			asctoe( str3, v );
			sprintf( tformat, "%s.%de", pct, j );
			sprintf( str2, tformat, ssprec53 );
			asctoe( str2, t );
			cmptrunc( v, t );
			}
		break;

	case 24:
		etoe24( fullp, &prec24 );
		e24toe( &prec24, rounded );
#if CHKINTERNAL
		e24toasc( &prec24, str1, SPREC );
		asctoe24( str1, &xprec24 );
		e24toe( &xprec24, t );
		chkinternal( rounded, t, str1 );
#endif
		sprintf( str2, format, prec24 );
		sscanf( str2, fformat, &sprec24 );
		e24toe( &sprec24, u );
		chkid( rounded, u, str2 );
		asctoe24( str2, &ssprec24 );
		e24toe( &ssprec24, v );
		chkscan( v, u, str2 );
		chkprint( rounded, v, str2 );
		if( testno < 8 )
			break;
/* rounding error measurement */
		etoasc( fullp, str0, 24 );
		etoe24( fullp, &ssprec24 );
		e24toe( &ssprec24, u );
		sprintf( str2, format, ssprec24 );
		asctoe( str2, t );
		cmpprint( u, t );
		sscanf( str0, fformat, &sprec24 );
		e24toe( &sprec24, t );
		cmpscan( fullp, t );
/*
		if( testno < 8 )
			break;
*/
		e24toasc( &ssprec24, str1, 24 );
		for( j=SPREC-1; j>0; j-- )		
			{
			e24toasc( &ssprec24, str3, j );
			asctoe( str3, v );
			sprintf( tformat, "%s.%de", pct, j );
			sprintf( str2, tformat, ssprec24 );
			asctoe( str2, t );
			cmptrunc( v, t );
			}
		break;
	}
}


void printerr()
{
if( (errscan == 0) && (identerr == 0) && (errprint == 0) )
	printf( "No errors found.\n" );
else
	{
	printf( "%d binary -> decimal errors found.\n", errprint );
	printf( "%d decimal -> binary errors found.\n", errscan );
	}
errscan = 0;	/* reset for next test */
identerr = 0;
errprint = 0;
errtot = 0;
}


/* Random number generator
 * in the range M * 10^N, where 1 <= M <= 10^17 - 1
 * and -27 <= N <= +27.  Test values of M are logarithmically distributed
 * random integers; test values of N are uniformly distributed random integers.
 */

static char *fwidth = "1.036163291797320557783096e1"; /* log(sqrt(10^9-1)) */
static char *dwidth = "1.957197329044938830915E1"; /* log(sqrt(10^17-1)) */
static char *ldwidth = "2.302585092994045684017491e1"; /* log(sqrt(10^20-1)) */

static char *a13 = "13.0";
static char *a27 = "27.0";
static char *a34 = "34.0";
static char *a10m13 = "1.0e-13";
static unsigned short LOW[ NE ], WIDTH[NE], e27[NE], e10m13[NE];


void mnrand( erand )
unsigned short erand[];
{
unsigned short ea[NE], em[NE], en[NE], ex[NE];
double x, a;

if( mnrflag )
	{
	if( mnrflag == 3 )
		{
		asctoe( ldwidth, WIDTH );
		asctoe( a34, e27 );
		}
	if( mnrflag == 2 )
		{
		asctoe( dwidth, WIDTH );
		asctoe( a27, e27 );
		}
	if( mnrflag == 1 )
		{
		asctoe( fwidth, WIDTH );
		asctoe( a13, e27 );
		}
	asctoe( a10m13, e10m13 );
	mnrflag = 0;
	}
drand( &x );
e53toe( &x, ex ); /* x = WIDTH *  ( x - 1.0 )  +  LOW; */
esub( eone, ex, ex );
emul( WIDTH, ex, ex );
eexp( ex, ex );   /* x = exp(x); */

drand( &a );
e53toe( &a, ea );
emul( ea, ex, ea );  /* a = 1.0e-13 * x * a; */
emul( e10m13, ea, ea );
eabs( ea );
eadd( ea, ex, ex );	/* add fuzz */
emul( ex, ex, ex );	/* square it, to get range to 10^17 - 1 */
efloor( ex, em ); /* this is M */

/* Random power of 10 */
drand( &a );
e53toe( &a, ex );
esub( eone, ex, ex ); /* y3 = 54.0 *  ( y3 - 1.0 ) + 0.5; */
emul( e27, ex, ex );
eadd( ex, ex, ex );
eadd( ehalf, ex, ex );
efloor( ex, ex ); /* y3 = floor( y3 ) - 27.0; */
esub( e27, ex, en ); /* this is N */
epow( eten, en, ex );
emul( ex, em, erand );
}

/* -ln 2^16382 */
char *ldemin = "-1.1355137111933024058873097E4";
char *ldewid =  "2.2710274223866048117746193E4";
/* -ln 2^1022 */
char *demin  = "-7.0839641853226410622441123E2";
char *dewid  =  "1.4167928370645282124488225E3";
/* -ln 2^125 */
char *femin  = "-8.6643397569993163677154015E1";
char *fewid  =  "1.7328679513998632735430803E2";

void etrand( erand )
unsigned short erand[];
{
unsigned short ea[NE], ex[NE];
double x, a;

if( etrflag )
	{
	if( etrflag == 3 )
		{
		asctoe( ldemin, LOW );
		asctoe( ldewid, WIDTH );
		asctoe( a34, e27 );
		}
	if( etrflag == 2 )
		{
		asctoe( demin, LOW );
		asctoe( dewid, WIDTH );
		asctoe( a27, e27 );
		}
	if( etrflag == 1 )
		{
		asctoe( femin, LOW );
		asctoe( fewid, WIDTH );
		asctoe( a13, e27 );
		}
	asctoe( a10m13, e10m13 );
	etrflag = 0;
	}
drand( &x );
e53toe( &x, ex ); /* x = WIDTH *  ( x - 1.0 )  +  LOW; */
esub( eone, ex, ex );
emul( WIDTH, ex, ex );
eadd( LOW, ex, ex );
eexp( ex, ex );   /* x = exp(x); */

/* add fuzz
 */
drand( &a );
e53toe( &a, ea );
emul( ea, ex, ea );  /* a = 1.0e-13 * x * a; */
emul( e10m13, ea, ea );
if( ecmp( ex, ezero ) > 0 )
	eneg( ea );
eadd( ea, ex, erand );
}

⌨️ 快捷键说明

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