正在加载图片...
Utility Routines (nrutil.c) 941 Strictly speaking,this scheme is not blessed by the ANSI C standard.The problem is not the fact that b-1 points to unallocated storage:location b-1 will never be referenced without an increment back into the allocated region.Rather,the problem is that it might happen in rare cases(and probably only on a segmented machine)that the expression b-1 has no representation at all.If this occurs,then there is no guarantee that the relation b=(b-1)+1 is satisfied. In practice,this is much less of a problem than one might think.We are not aware of any compiler or machine on which b=(b-n)+n fails to be true for small integer n.Even on a segmented machine,what typically happens is that the compiler stores some(perhaps illegal) representation of b-n,and that b is recovered whenn is added back to this representation.The http://www memory allocation routines in the First Edition of Numerical Recipes in C,in wide use since 1988,all have this"problem",and we have had not even a single report of their failure in this respect (notwithstanding the many readers who have told us that theoretically it could fail). 83 We have also communicated to standards bodies the desirability of blessing "b=(b-n)+n"(at granted for 18881992 least for some range of n,say n representable as type short)in a future standard,since there would seem to be no conflict with existing compilers in doing so. 1800 Despite the absence of any experimental (as opposed to theoretical)problem,we have taken some steps in this edition to make our vector and matrix allocation routines more ANSI compliant.In the listing that follows,the parameter NR_END is used as a number ofextra storage locations allocated at the beginning of every vector or matrix block,simply for the purpose by Cambridge University Press. from NUMERICAL RECIPES IN of making offset pointer references guaranteed-representable.We set NR_END to a default value of 1.This has the effect of making all unit-ofset allocations (e.g.,b=vector(1,7); server computer, (Nor or a=matrix(1,128,1,128);)be strictly ANSI compliant.With NR_END 1,the number of storage locations wasted is fairly negligible.Allocations with offsets other than 1 (e.g., America to make one paper THE b=vector(2,10))are still theoretically non-compliant,but are virtually unknown in our ART routines.If you need to make such allocations,you may wish to consider increasing the value of NR_END (noting that larger values increase the amount of wasted storage). Programs Here is a listing of nrutil.h st st #ifndef _NR_UTILS_H_ #define_NR_UTILS_H to dir static float sqrarg; #define SQR(a)((sqrarg=(a))==0.0 0.0 sqrarg*sgrarg) rectcustsen 1988-1992 by Numerical Recipes OF SCIENTIFIC COMPUTING(ISBN 0-521- static double dsgrarg; #define DSQR(a)((dsgrarg=(a))==0.0 0.0 dsgrarg*dsgrarg) static double dmaxarg1,dmaxarg2; #define DMAX(a,b)(dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1)>(dmaxarg2)?\ @cambridge.org (dmaxarg1):(dmaxarg2)) -43106 static double dminarg1,dminarg2; #define DMIN(a,b)(dminarg1=(a),dminarg2=(b),(dminarg1)<(dminarg2)?\ (dminarg1):(dminarg2)) (outside North Software. static float maxargi,maxarg2; #define FMAX(a,b)(maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)?\ Amer (maxarg1):(maxarg2)) ,visit website machine static float minarg1,minarg2; #define FMIN(a,b)(minarg1=(a),minarg2=(b),(minarg1)<(minarg2)?\ (minarg1):(minarg2)) static long lmaxarg1,lmaxarg2; #define LMAX(a,b)(lmaxarg1=(a),lmaxarg2=(b),(1maxarg1)>(Imaxarg2)?\ (Imaxarg1):(Imaxarg2)) static long lminarg1,lminarg2Utility Routines (nrutil.c) 941 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). Strictly speaking, this scheme is not blessed by the ANSI C standard. The problem is not the fact that b-1 points to unallocated storage: location b-1 will never be referenced without an increment back into the allocated region. Rather, the problem is that it might happen in rare cases (and probably only on a segmented machine) that the expression b-1 has no representation at all. If this occurs, then there is no guarantee that the relation b=(b-1)+1 is satisfied. In practice, this is much less of a problem than one might think. We are not aware of any compiler or machine on which b=(b-n)+n fails to be true for small integer n. Even on a segmented machine, what typically happens is that the compiler stores some (perhaps illegal) representation of b-n, and that b is recovered when n is added back to this representation. The memory allocation routines in the First Edition of Numerical Recipes in C, in wide use since 1988, all have this “problem”, and we have had not even a single report of their failure in this respect (notwithstanding the many readers who have told us that theoretically it could fail). We have also communicated to standards bodies the desirability of blessing “b=(b-n)+n” (at least for some range of n, say n representable as type short) in a future standard, since there would seem to be no conflict with existing compilers in doing so. Despite the absence of any experimental (as opposed to theoretical) problem, we have taken some steps in this edition to make our vector and matrix allocation routines more ANSI compliant. In the listing that follows, the parameter NR_END is used as a number of extra storage locations allocated at the beginning of every vector or matrix block, simply for the purpose of making offset pointer references guaranteed-representable. We set NR_END to a default value of 1. This has the effect of making all unit-offset allocations (e.g., b=vector(1,7); or a=matrix(1,128,1,128);) be strictly ANSI compliant. With NR_END = 1, the number of storage locations wasted is fairly negligible. Allocations with offsets other than 1 (e.g., b=vector(2,10)) are still theoretically non-compliant, but are virtually unknown in our routines. If you need to make such allocations, you may wish to consider increasing the value of NR_END (noting that larger values increase the amount of wasted storage). Here is a listing of nrutil.h: #ifndef _NR_UTILS_H_ #define _NR_UTILS_H_ static float sqrarg; #define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg) static double dsqrarg; #define DSQR(a) ((dsqrarg=(a)) == 0.0 ? 0.0 : dsqrarg*dsqrarg) static double dmaxarg1,dmaxarg2; #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1) > (dmaxarg2) ?\ (dmaxarg1) : (dmaxarg2)) static double dminarg1,dminarg2; #define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1) < (dminarg2) ?\ (dminarg1) : (dminarg2)) static float maxarg1,maxarg2; #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\ (maxarg1) : (maxarg2)) static float minarg1,minarg2; #define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1) < (minarg2) ?\ (minarg1) : (minarg2)) static long lmaxarg1,lmaxarg2; #define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1) > (lmaxarg2) ?\ (lmaxarg1) : (lmaxarg2)) static long lminarg1,lminarg2;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有