Morgan - Numerical Methods (523161), страница 47
Текст из файла (страница 47)
0d1d6h, 0d272h, 0d30dh, 0d3a8h,0d443h, 0d4ddh, 0d577h, 0d610h, 0d6a9h, 0d742h,0d7dah, 0d871h, 0d908h, 0d99fh, 0da35h, 0dacbhword0dbG1h,0dedah,0e246h,0e5a4h,0e8f6h,0dbf6h,0df6dh,0e2d6h,0e633h,0e983h,0dc8bh,0e000h,0e367h,0e6c1h,0ea0fh,0dd1fh,0e092h,0e3f7h,0e74fh,0eagbh,0ddb3h,0e123h,0e486h,0e7dch,0eb26h,0de47h,0e1b5h,0e515h,0e869h,0ebb1hword0ec3ch,0ef77h,0f2a6h,0f5cbh,0f8e6h,0ecc7h,0f000h,0f32dh,0f651h,0f96ah,0ed51h,0f088h,0f3b4h,0f6d6h,0fgedh,0eddbh,0f11Oh,0f43ah,0f75ah,0fa7Oh,0ee65h,0f198h,0f4cOh,0f7deh,0faf3h,0eeeeh,0f21fh,0f546h,0f863h,0fb75hword0fbf7h, 0fc79h, 0fcfbh, 0fd7ch, 0fdfdh, 0fe7eh,0feffh, 0ff7fh, 00000h;sqrt(2**x)sqr_power wordatanh_array00ffffh,002000h,000400h,000080h,000010h,000002h,dword00b504h,0016aOh,0002d4h,00005ah,00000bh,000001h,008000h,001000h,000200h,000040h,000008h,000001h005a82h,000b50h,00016ah,00002dh,000006h,004000h,000800h,000100h,000020h,000004h,002d41h,0005a8h,0000b5h,000016h,000002h,0h, 8c9f53d5h, 4162bbeah, 202b1239h, 1005588ah,800aac4h, 4001556h, 20002aah, 1000055h,80000ah, 400001h, 200000h, 100000h, 80000h, 40000h,20000h, 10000h, 8000h, 3fffh, 1fffh,0fffh, 7ffh, 3ffh, 1ffh, 0ffh, 7fh, 3fh, 1fh, 0fh, 7h,3h, 1h, 0h471NUMERICAL METHODSatan_arraydword0c90fdaa2h, 76b19c16h, 3eb6ebf2h, 1fd5ba9bh, 0ffaaddch,7ff556fh, 3ffeaabh, 1fffd55h,0ffffabh, 7ffff5h, 3fffffh, 200000h, 100000h, 80000h,40000h, 20000h, 10000h, 8000h,4000h, 2000h, 1000h, 800h, 400h, 200h, 100h, 80h, 40h,20h, 10h, 8h, 4h, 2h, 1hpower2qword100000000h, 95c01a3ah, 5269e12fh, 2b803473h, 1663f6fah,0b5d69bah, 5b9e5a1h, 2dfca16h, 1709c46h,5c60aah, 2e2d71h, 171600h, 0b8adlh, 5c55dh, 2e2abh,17155h, 0b8aah, 5c55h, 2e2ah, 1715h, 0b8ah,5c5h, 2e2h, 171h, 0b8h, 5ch, 2eh, 17h, 0bh, 5h, 2h, 1hlog2qword100000000h, 6a3fe5c6h, 31513015h, 17d60496h, 0bb9ca64h,5d0fba1h, 2e58f74h, 1720d9ch, 0b8d875h,5c60aah, 2e2d71h, 171600h, 0b8ad1h, 5c55dh, 2e2abh,17155h, 0b8aah, 5c55h, 2e2ah, 1715h, 0b8ah,5c5h, 2e2h, 171h, 0b8h, 5ch, 2eh, 17h, 0bh, 5h, 2h, 1hpower10qword4d104d42h, 2d145116h, 18cf1838h, 0d1854ebh, 6bd7e4bh,36bd211h, 1b9476ah,0dd7ea4h, 6ef67ah, 378915h, 1bc802h, 0de4dfh, 6f2a7h,37961h, 1bcb4h, 0de5bh,6f2eh, 3797h, 1bcbh, 0de6h, 6f3h, 379h, 1bdh, 0deh, 6fh,38h, 1ch, 0eh, 7h, 3h, 2h, 1halgqword3f3180000000h, 0b95e8082e308h, 3ede5bd8a937h,0beee08307e16h, 3c5ed689e495h, 0c0b286223e39h,3f8000000000hxpqword3f3000000000h, 3bb90bfbe8efh, 3e8000000000h,3b885307cc09h, 3f0000000000h,3d4cbf5b2122hsincosqword404900000000h, 3a7daa20968bh, 0be2aaaa8fdbeh,3c088739cb85h, 0b94fb2227f1ah,362e9c5a91d8htancotqword3fc900000000h, 39fdaa22168ch, 3f8000000000h,472TRANS.ASM AND TABLE.ASM0bdc433b8376bh, 3f8000000000h, 0bedbb7af3f84h,3c1f33753551hpolytanqword100000000h, 0, 0aaaaaaabh, 0, 33333333h, 0, 0db6db6dbh,0, 1c71c71ch, 0, 0e8ba2e8ch, 0, 13b13b14h, 0,0eeeeeeefh, 0, 0f0f0f0fh, 0, 0f286bca2h, 0, 0c30c30ch,0, 0f4de9bd3h, 0, 0a3d70a4h, 0, 0f684bda1h, 0, 8d3dcb1h,0, 0f7bdef7ch, 0polysinqword100000000h, 0, 0ffffffffd5555555h, 0, 222222221, 0,0fffffffffff2ff30h, 0, 2e3ch, 0, 0ffffffffffffff94hdgtqwordonetenqwordqwordone-halfqword000000000000h,404000000000h,40c000000000h,411000000000h3f8000000000h412000000000h,4cbebc200000h,3f0000000000h3f8000000000h, 400000000000h,408000000000h, 40a000000000h,40e000000000h, 410000000000h,42c800000000h, 461c40000000h,5a0e1bc9bf00h, 749dc5ada82bhend473474Previous HomeAPPENDIX GMath.C#include<io.h>#include<conio.h>#include<stdio.h>#include <fcntl.h>#include<sys\types.h>#include <sys\stat.h>#include<malloc.h>#include<errno.h>#include<math.h>#include<float.h>#include<stdlib.h>#include<time.h>#include<string.h>/* O_constant definitions *//* S_constant definitions */#define TRUE 1#define FALSE 0union{float realsmall;double realbig;int smallint;long bigint;char bytes[16];int words[8];long dwords[4];}operand0;union{float realsmall;double realbig;int smallint;475NextNUMERICAL METHODSlong bigint;char bytes[16];int words[8];long dwords[4];}operand1;union{float realsmall;double realbig;int smallint;long bigint;char bytes[16];int words[8];long dwords[4];}operand2;union{float realsmall;double realbig;int smallint;long bigint;char bytes[16];int words[8];long dwords[4];}answer0;union{float realsmall;double realbig;int smallint;long bigint;char bytes[16];int words[8];long dwords[4];}answer1;/*doubles are used to indicate to C to push a quadword parameter, please see*//*the unions above for more information on how to manipulate these parameters*/extern void lgb(union answr, double *);extern void pwrb(double, double *);476MATH.Cexternexternexternexternexternexternexternexternexternexternexternexternexternexternexternint irandom(void);void rinit(int);void divnewt(double, double, double*);void divmul(double, double, double*);void ftf(double, double*);void ftfx(double, double*);void taylorsin(double, double*);void ihyper(double *, double *, double *);void hyper(double *, double *, double *);void icirc(double *, double *, double *);void circular(double *, double *, double *);void fp_sqr(float, float*);void fp_tan(float, float*);void fp_cos(float, float*);void fp_sin(float, float*);externexternexternexternexternexternexternexternexternexternexternexternexternexternexternvoid fp_mul(float, float, float *);void fp_div(float, float, float *);void fp_add(float, float, float *);void fp_sub(float, float, float *);void fp_abs(float, float*);void lg10(double *, double *);void sqrtt(double *, double *);void dcsin(double *, double *, unsigned char);atf(char*string, float *asm_val);ftofx(float, long*);ftoasc(float, char*);fr_xp(float, float *, char *);ld_xp(float, float*, char);fx_sqr(long, long*);school_sqr(long, long*);externexternexternexternexternexternexterndnt_bn(char *, int *);dfc_bn(char *, int *);bn_dnt(unsigned long int, char *);bfc_dc(unsigned long int, char *);fp_intrnd(float, float*);fp_ceil(float, float*);fp_floor(float, float*);477NUMERICAL METHODSint binary_integer;char decimal_string0[20];char decimal_string1[20];char string0[25], string1[25];radicand;longroot;longchar exponent;float temp;float value;float mantissa;float asm_val0, asm_val1;float floor_test;float ceil_test;float intrnd_test;float asm_mul;float tst_asm_mul;float asm_div;float asm_add;float asm_sub;float mul_tst;float asm_mul_tst;float div_tst;float add_tst;float sub_tst;float fpsin;float fpsqr;float fplog;float fplog10;/*this routine scales a random number to a maximum without using a modularoperation*/int get random(int max){unsigned long a, b;a = irandom();b = max*a;return(b/32768);}478MATH.Cmain()float fp_numa;float fp_numb;float fp_numc;float fp_numd;long numa, numb, numc, numd;double dwrd;double test;float nt;char *buf;int ad_buf, ch, j;double error;unsigned long temporary;unsigned count = 0x1000, cnt = 0, errcnt,passes, maxpass, cycle_cnt;dwrd=4294967296.0;nt = 65536;/*2^32*//*2^16*/ad_buf = open( "tstdata", O_TEXT | O_WRONLY | O_CREAT |O_TRUNC, S_IREAD | S_IWRITE );if( ad_buf == -1 ) {perror("\nopen failed");exit(-1);}/* allocate a file buffer.*/If( (buf = (char*)malloc( (size_t)count )) ==NULL) {perror("\nnot enuf memory");exit(-1);cycle_cnt = 0;do{rinit((unsigned int)time(NULL) );479NUMERICAL METHODSmaxpass=1000;error= 0.00001;errcnt = 0;/*a zero error can result in errors of +0.0 or -0.0reported*//*smaller errors sometimes exceedtheprecisionof a single real*/passes = 0;do{getrandom(irandom());while((numa=getrandom(irandom())) == 0);if((irandom() * .001) >15) fp_numa = (float)numa * -1.0;else fp_numa = (float)numa;while((numb = getrandom(irandom())) == 0);if((irandom0 * .001) >15) fp_numb = (float)numb * -1.0;else fp_numb = (float)numb;while((numc = irandom()) == 0);fp_sqr((float)numc, &fp_numc);fp_numa *= fp_numc;while((numd = irandom()) == 0);fp_sqr((float)numd, &fp_numd);fp_numb *= fp_numd;sprintf(buf,"\ntwo random floats are fp_numa %f andfp_numb %f", fp_numa, fp_numb);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");test=(double)fp_numa;gcvt((double)fp_numa, 8, string0); /*needed to test asmconversions*/gcvt((double)fp_numb, 8, string1);sprintf(buf,"\nstring0 (fp_numa): %s, string1 (fp_numb): %s",string0, string1);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");atf(string0, &asm_va10); /*convert string to float*/480MATH.Catf(string1, &asm_val1);sprintf(buf,"\nasm_val0(string0):%fandasm-val1(stringl):fp_numa, fp_numb);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");%f",mul_tst=fp_numa*fp_numb;asm_mul_tst = asm_val0*asm_val1;div_tst = fp_numa/fp_numb;add_tst = fp_numa+fp_numb;sub_tst = fp_numa-fp_numb;fp_mul(asm_val0, asm_vail, &asm_mul);fp_mul(fp3uma, fp_numb, &tst_asm_mul);fp_div(asm_val0, asm_val1, &asm_div);fp_add(asm_val0, asm_val1, &asm_add);fp_sub(asm_val0, asm_vall, &asm_sub);sprintf(buf,"\nfp_numa*fp_numb, msc = %f, asm = %f,difference = %f", mul_tst, asm_mul, mul_tst-asm_mul);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");sprintf(buf,"\nfp_numa/fp_numb, msc = %f, asm = %f,difference = %f", div_tst, asm_div, div_tst-asm_div);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");sprintf(buf,"\nfp_numa+fp_numb, msc = %f, asm = %f,difference = %f", add_tst, asm_add, add_tst-asm_add);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");sprintf(buf,"\nfp_numa-fp_numb, msc = %f, asm = %f,difference = %f", sub_tst, asm_sub, sub_tst-asm_sub);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");temp = (float)getrandom(100);fp_sqr(temp, &fpsqr);sprintf(buf,"\nsqrt(%f),msc = %f, asm = %f", temp,(float)sqrt((double)temp),fpsqr) ;481NUMERICAL METHODSif(count=write( ad_buf, buf, strlen(buf)) == - 1)perror("couldn't write");fp_sin(temp, &fpsin);sprintf(buf,"\nfp_sin(%f), msc = %f, asm = %f", temp,(float)sin((double)temp), fpsin);if(count = write( ad_buf, buf, strlen(buf) 1 == - 1)perror("couldn't write");/*error reporting*/sprintf(buf,"\niteration: %x", cnt++);if(count = write( ad_buf, buf, strlen(buf) 1 == - 1)perror("couldn't write");sprintf(buf,"\nfp-numais %f and fp_numb is %f", fp_numa, fp_numb);if(count = write( ad_buf, buf, strlen(buf) 1 == - 1)perror("couldn't write");sprintf(buf,"\nstring0 is %s and string1 is %s", string0, string1);if(count = write( ad_buf, buf, strlen(buf)) == - 1)perror("couldn't write");if((fabs((double)mul_tst-(double)asm_mul)) >error) {errcnt++;sprintf(buf,"\nmsc multiplication says %f, I say %f, error= %f",mul_tst, asm_mul, mul_tst-asm_mull;if(count = write( ad_buf, buf, strlen(buf)) == - 1)perror("couldn't write");if((fabs((double)div_tst-(double)asm_div)) >error) {errcnt++;sprintf(buf,"\nmsc division says %f, I say %f, error= %f",div_tst, asm_div, div_tst-asm_div);if(count = write( ad_buf, buf, strlen(buf)) == - 1)perror("couldn't write");482MATH.Cif((fabs((double)sub_tst-(double)asm_sub)) >error) {errcnt++;sprintf(buf,"\nmsc subtraction says %f, I say %f, error= %f",sub_tst, asm_sub, sub_tst-asm_sub);if(count = write( ad_buf, buf, strlen(buf) ) == - 1)perror("couldn't write");if((fabs((double)add_tst-(double)asm_add)) >error) {errcnt++;sprintf(buf,"\nmsc addition says %f, I say %f, error= %f",add_tst, asm_add, add_tst-asm_add);if(count = write( ad_buf, buf, strlen(buf) ) == - 1perror("couldn't write");printf(".");sprintf(buf,"\n");if(count = write( ad_buf, buf, strlen(buf) ) == - 1perror("couldn't write");passes++;}while(!kbhit() && ! (passes == maxpass));cycle_cnt++;}while(!errcnt && !kbhit());printf("\nerrors: %d cycles: %d pass: %d", errcnt, cycle_cnt,passes);close( ad_buf );free( buf );483484Previous Home NextGlossaryabscissaalgorithmOn the Cartesian Axes, it is the distancefrom a point to the y axis.A set of guidelines or rules for solvinga problem in a finite number of steps.accumulatoralignA general purpose register on manymicroprocessors.