正在加载图片...
892 Chapter2o】 Less-Numerical Algorithms #include <math.h> #define CONV(i)((float)(i)) Change float to double here and in declarations below to find double precision parameters. void machar(int *ibeta,int *it,int *irnd,int *ngrd,int *machep,int *negep, int iexp,int *minexp,int *maxexp,float eps,float *epsneg, float *xmin,float *xmax) Determines and returns machine-specific parameters affecting floating-point arithmetic.Re- turned values include ibeta,the floating-point radix:it,the number of base-ibeta digits in the floating-point mantissa;eps,the smallest positive number that,added to 1.0,is not equal to 1.0:epsneg,the smallest positive number that,subtracted from 1.0,is not equal to 1.0; xmin,the smallest representable positive number;and xmax,the largest representable positive http://www.nr Permission is read able files number.See text for description of other returned parameters. int i,itemp,iz,j,k,mx,nxres 83g float a,b,beta,betah,betain,one,t,temp,temp1,tempa,two,y,z,zero; one=CONV(1); 11-600 (including this one) two=one+one; zerosone-one; 872 asone; Determine ibeta and beta by the method of M. do Malcolm 7423 from NUMERICAL RECIPES IN a+=a; temp=atone; templ-temp-a; while (templ-one =zero); (North America to any server computer,is strictly prohibited. tusers to make one paper 1988-1992 by Cambridge University Press.Programs Copyright(C)1988-1992 by Numerical Recipes THE b=one; do b+=b; temp=a+b; itemp=(int)(temp-a); while (itemp ==0); copy for their *ibeta=itemp; beta=CONV(*ibeta); *1t=0; Determine it and irnd. b=one; do ++(*1t); b*=beta; temp=b+one; only),orsend email to directcustserv@cambridge.org personal use.Further reproduction,or ART OF SCIENTIFIC COMPUTING(ISBN 0-521- tempistemp-b; while (templ-one =zero); *irnd=0; betah=beta/two: temp=a+betah; if (temp-a ! zero)*irnd=1; tempa=a+beta; -431085 temp-tempa+betah; if (*irnd ==0&&temp-tempa !zero)tirnd=2; *negep=(*it)+3; Determine negep and epsneg. betain=one/beta: Software. a=one; for (i=1;i<=(*negep);i++)a *=betain; (outside North America) b=ai for(;;)[ temp=one-a; if (temp-one !zero)break; a *beta: --(*negep)i *negep =-(*negep) 米epsneg=a; *machep =-(*it)-3; Determine machep and eps a-b;892 Chapter 20. Less-Numerical Algorithms Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). #include <math.h> #define CONV(i) ((float)(i)) Change float to double here and in declarations below to find double precision parameters. void machar(int *ibeta, int *it, int *irnd, int *ngrd, int *machep, int *negep, int *iexp, int *minexp, int *maxexp, float *eps, float *epsneg, float *xmin, float *xmax) Determines and returns machine-specific parameters affecting floating-point arithmetic. Re￾turned values include ibeta, the floating-point radix; it, the number of base-ibeta digits in the floating-point mantissa; eps, the smallest positive number that, added to 1.0, is not equal to 1.0; epsneg, the smallest positive number that, subtracted from 1.0, is not equal to 1.0; xmin, the smallest representable positive number; and xmax, the largest representable positive number. See text for description of other returned parameters. { int i,itemp,iz,j,k,mx,nxres; float a,b,beta,betah,betain,one,t,temp,temp1,tempa,two,y,z,zero; one=CONV(1); two=one+one; zero=one-one; a=one; Determine ibeta and beta by the method of M. do { Malcolm. a += a; temp=a+one; temp1=temp-a; } while (temp1-one == zero); b=one; do { b += b; temp=a+b; itemp=(int)(temp-a); } while (itemp == 0); *ibeta=itemp; beta=CONV(*ibeta); *it=0; Determine it and irnd. b=one; do { ++(*it); b *= beta; temp=b+one; temp1=temp-b; } while (temp1-one == zero); *irnd=0; betah=beta/two; temp=a+betah; if (temp-a != zero) *irnd=1; tempa=a+beta; temp=tempa+betah; if (*irnd == 0 && temp-tempa != zero) *irnd=2; *negep=(*it)+3; Determine negep and epsneg. betain=one/beta; a=one; for (i=1;i<=(*negep);i++) a *= betain; b=a; for (;;) { temp=one-a; if (temp-one != zero) break; a *= beta; --(*negep); } *negep = -(*negep); *epsneg=a; *machep = -(*it)-3; Determine machep and eps. a=b;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有