正在加载图片...
14 Chapter 1.Preliminaries hrs after midnight (EST)"); break; Part of the break-structure,a match. else Didn't hit it. 1c=(jday>=jd?1:-1); if (ic ==(-icon))break; Another break,case of no match. icon=ic; n +ic; return 0; If you are merely curious,there were (or will be)occurrences of a full moon on Friday the13th(time zone GMT-5)on:3/13/1903,10/13/1905,6/13/1919, 1/13/1922,11/13/1970.2/13/1987,10/13/2000.9/13/2019,and8/13/2049 Other "standard"structures.Our advice is to avoid them.Every pro- gramming language has some number of"goodies"that the designer just couldn't resist throwing in.They seemed like a good idea at the time.Unfortunately they 令 don't stand the test of time!Your program becomes difficult to translate into other languages,and difficult to read(because rarely used structures are unfamiliar to the reader).You can almost always accomplish the supposed conveniences of these 会以州 structures in other ways. In C,the most problematic control structure is the switch...case...default construction(see Figure 1.1.1),which has historically been burdened by uncertainty, s0云 from compiler to compiler,about what datatypes are allowed in its control expression. Data types char and int are universally supported.For other data types,e.g.,float or double,the structure should be replaced by a more recognizable and translatable if...else construction.ANSI C allows the control expression to be of type long, but many older compilers do not. The continue;construction,while benign,can generally be replaced by an if construction with no loss of clarity. About "Advanced Topics" Numerica 10621 Material set in smaller type,like this,signals an"advanced topic,"either one outside of 43106 the main argument of the chapter,or else one requiring of you more than the usual assumed mathematical background,or else (in a few cases)a discussion that is more speculative or an algorithm that is less well-tested.Nothing important will be lost if you skip the advanced (outside Recipes topics on a first reading of the book. Software. You may have noticed that,by its looping over the months and years,the program badluk North avoids using any algorithm for converting a Julian Day Number back into a calendar date.A routine for doing just this is not very interesting structurally,but it is occasionally useful: #include <math.h> #define IGREG 2299161 void caldat(long julian,int *mm,int *id,int *iyyy) Inverse of the function julday given above.Here julian is input as a Julian Day Number, and the routine outputs mm,id,and iyyy as the month,day,and year on which the specified Julian Day started at noon. long ja,jalpha,jb,jc,jd,je;14 Chapter 1. Preliminaries 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). " hrs after midnight (EST)"); break; Part ofthe break-structure, a match. } else { Didn’t hit it. ic=(jday >= jd ? 1 : -1); if (ic == (-icon)) break; Another break, case ofno match. icon=ic; n += ic; } } } } } return 0; } If you are merely curious, there were (or will be) occurrences of a full moon on Friday the 13th (time zone GMT−5) on: 3/13/1903, 10/13/1905, 6/13/1919, 1/13/1922, 11/13/1970, 2/13/1987, 10/13/2000, 9/13/2019, and 8/13/2049. Other “standard” structures. Our advice is to avoid them. Every pro￾gramming language has some number of “goodies” that the designer just couldn’t resist throwing in. They seemed like a good idea at the time. Unfortunately they don’t stand the test of time! Your program becomes difficult to translate into other languages, and difficult to read (because rarely used structures are unfamiliar to the reader). You can almost always accomplish the supposed conveniences of these structures in other ways. In C, the most problematic control structure is the switch...case...default construction (see Figure 1.1.1), which has historically been burdened by uncertainty, from compiler to compiler, about what data types are allowed in its control expression. Data types char and int are universally supported. For other data types, e.g., float or double, the structure should be replaced by a more recognizable and translatable if...else construction. ANSI C allows the control expression to be of type long, but many older compilers do not. The continue; construction, while benign, can generally be replaced by an if construction with no loss of clarity. About “Advanced Topics” Material set in smaller type, like this, signals an “advanced topic,” either one outside of the main argument of the chapter, or else one requiring of you more than the usual assumed mathematical background, or else (in a few cases) a discussion that is more speculative or an algorithm that is less well-tested. Nothing important will be lost if you skip the advanced topics on a first reading of the book. You may have noticed that, by its looping over the months and years, the program badluk avoids using any algorithm for converting a Julian Day Number back into a calendar date. A routine for doing just this is not very interesting structurally, but it is occasionally useful: #include <math.h> #define IGREG 2299161 void caldat(long julian, int *mm, int *id, int *iyyy) Inverse ofthe function julday given above. Here julian is input as a Julian Day Number, and the routine outputs mm,id, and iyyy as the month, day, and year on which the specified Julian Day started at noon. { long ja,jalpha,jb,jc,jd,je;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有