正在加载图片...
894 Chapter 20.Less-Numerical Algorithms point at extreme right of mantissa. if (*ibeta ==2&li)--(*maxexp); 1f(1>20) --(*maxexp) if (a !y)*maxexp -=2 *xmax=one-(*epsneg); if ((*xmax)*one !*xmax)*xmax=one-beta*(tepsneg); *xmax /(*xmin*beta*beta*beta); i=(*maxexp)+(*minexp)+3; for(j=1;j<=1;j++){ if (*ibeta ==2)*xmax +*xmax; els日*xmax*=beta; 83 Some typical values returned by machar are given in the table,above.IEEE- 鱼 18881892 compliant machines referred to in the table include most UNIX workstations(SUN, DEC,MIPS),and Apple Macintosh IIs.IBM PCs with floating co-processors are generally IEEE-compliant,except that some compilers underflow intermediate results ungracefully,yielding irnd =2 rather than 5.Notice,as in the case of a VAX from NUMERICAL RECIPES I (fourth column),that representations with a"phantom"leading I bit in the mantissa achieve a smaller eps for the same wordlength,but cannot underflow gracefully. CITED REFERENCES AND FURTHER READING: 、门 Press. Goldberg,D.1991,ACM Computing Surveys,vol.23,pp.5-48. Cody,W.J.1988,ACM Transactions on Mathematical Software,vol.14,pp.303-311.[1] Malcolm,M.A.1972,Communications of the ACM,vol.15,pp.949-951.[2] IEEE Standard for Binary Floating-Point Numbers,ANSI/IEEE Std 754-1985(New York:IEEE 1985).[3] 、学爱 SCIENTIFIC 20.2 Gray Codes A Gray code is a function G(i)of the integers i,that for each integer N>0 G Numerical Recipes 10621 is one-to-one for 0<i<2N-1,and that has the following remarkable property: The binary representation of G(i)and G(i+1)differ in exactly one bit.An example 43106 of a Gray code (in fact,the most commonly used one)is the sequence 0000.0001 0011,0010,0110.0111,0101,0100.1100,1101.1111,1110,1010.1011,1001 and 1000,fori=0,...,15.The algorithm for generating this code is simply to (outside form the bitwise exclusive-or(XOR)of i with i/2 (integer part).Think about how North the carries work when you add one to a number in binary,and you will be able to see why this works.You will also see that G(i)and G(i+1)differ in the bit position of the rightmost zero bit of i(prefixing a leading zero if necessary). The spelling is "Gray,"not"gray:The codes are named after one Frank Gray, who first patented the idea for use in shaft encoders.A shaft encoder is a wheel with concentric coded stripes each of which is"read"by a fixed conducting brush.The idea is to generate a binary code describing the angle of the wheel.The obvious, but wrong,way to build a shaft encoder is to have one stripe (the innermost,say) conducting on half the wheel,but insulating on the other half,the next stripe is conducting in quadrants I and 3;the next stripe is conducting in octants 1,3,5,894 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). point at extreme right of mantissa. if (*ibeta == 2 && !i) --(*maxexp); if (i > 20) --(*maxexp); if (a != y) *maxexp -= 2; *xmax=one-(*epsneg); if ((*xmax)*one != *xmax) *xmax=one-beta*(*epsneg); *xmax /= (*xmin*beta*beta*beta); i=(*maxexp)+(*minexp)+3; for (j=1;j<=i;j++) { if (*ibeta == 2) *xmax += *xmax; else *xmax *= beta; } } Some typical values returned by machar are given in the table, above. IEEE￾compliant machines referred to in the table include most UNIX workstations (SUN, DEC, MIPS), and Apple Macintosh IIs. IBM PCs with floating co-processors are generally IEEE-compliant, except that some compilers underflow intermediate results ungracefully, yielding irnd = 2 rather than 5. Notice, as in the case of a VAX (fourth column), that representations with a “phantom” leading 1 bit in the mantissa achieve a smaller eps for the same wordlength, but cannot underflow gracefully. CITED REFERENCES AND FURTHER READING: Goldberg, D. 1991, ACM Computing Surveys, vol. 23, pp. 5–48. Cody, W.J. 1988, ACM Transactions on Mathematical Software, vol. 14, pp. 303–311. [1] Malcolm, M.A. 1972, Communications of the ACM, vol. 15, pp. 949–951. [2] IEEE Standard for Binary Floating-Point Numbers, ANSI/IEEE Std 754–1985 (New York: IEEE, 1985). [3] 20.2 Gray Codes A Gray code is a function G(i) of the integers i, that for each integer N ≥ 0 is one-to-one for 0 ≤ i ≤ 2N − 1, and that has the following remarkable property: The binary representation of G(i) and G(i + 1) differ in exactly one bit. An example of a Gray code (in fact, the most commonly used one) is the sequence 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, and 1000, for i = 0,..., 15. The algorithm for generating this code is simply to form the bitwise exclusive-or (XOR) of i with i/2 (integer part). Think about how the carries work when you add one to a number in binary, and you will be able to see why this works. You will also see that G(i) and G(i + 1) differ in the bit position of the rightmost zero bit of i (prefixing a leading zero if necessary). The spelling is “Gray,” not “gray”: The codes are named after one Frank Gray, who first patented the idea for use in shaft encoders. A shaft encoder is a wheel with concentric coded stripes each of which is “read” by a fixed conducting brush. The idea is to generate a binary code describing the angle of the wheel. The obvious, but wrong, way to build a shaft encoder is to have one stripe (the innermost, say) conducting on half the wheel, but insulating on the other half; the next stripe is conducting in quadrants 1 and 3; the next stripe is conducting in octants 1, 3, 5
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有