正在加载图片...
914 Chapter 20.Less-Numerical Algorithms jh=JTRY(acode->jdif,acode->ncumfq[*ich+2],acode->ncum); jl=JTRY(acode->jdif,acode->ncumfq[*ich+1],acode->ncum); acode->idif=jh-il; arcsum(acode->ilob,acode->iupb,jh,NWK,acode->nrad,acode->nc); arcsum(acode->ilob,acode->ilob,jl,NWK,acode->nrad,acode->nc); How many leading digits to output (if encoding)or skip over? for (j=acode->nc;j<=NWK;j++) if (*ich !acode->nch acode->iupb[j]!acode->ilob[j])break; if (*lcd *lcode){ fprintf(stderr,"Reached the end of the 'code'array.\n"); fprintf(stderr,"Attempting to expand its size.\n"); *lcode +=*lcode/2; if ((*codep=(unsigned char *)realloc(*codep, (unsigned)(*lcode*sizeof(unsigned char))))==NULL){ nrerror("Size expansion failed"); 18881892 if (isign 0)(*codep)[*lcd]=(unsigned char)acode->ilob[j]; 100 ++(*1cd); if (j>NWK) return; Ran out of message.Did someone forget to encode a from NUMERICAL RECIPESI acode->nc=j; terminating ncd? for(j=0;acode->jdif<acode->minint;j++) How many digits to shift? acode->jdif *=acode->nrad; if (acode->nc-j 1)nrerror("NWK too small in arcode."); if (j){ Shift them. for (k=acode->nc;k<=NWK;k++){ (North America server computer, to make one paper e University Press. THE acode->iupb [k-j]=acode->iupb[k]; ART acode->ilob[k-j]=acode->ilob[k]; Programs acode->nc -j; strictly proh for (k=NWK-j+1;k<=NWK;k++)acode->iupb[k]=acode->ilob [k]=0; return; Normal return. 2 to dir rectcustser OF SCIENTIFIC COMPUTING(ISBN void arcsum(unsigned long iin[],unsigned long iout []unsigned long ja, int nwk,unsigned long nrad,unsigned long nc) Used by arcode.Add the integer ja to the radix nrad multiple-precision integer iin [nc..nwk]. v@cam Return the result in iout [nc..nwk]. 10-621 int j,karry=0; 1988-1992 by Numerical Recipes 43108 unsigned long jtmp; for (j=nwk;j>nc;j--){ jtmp=ja; ja /nrad; Software. iout [j]=iin[j]+(jtmp-ja*nrad)+karry; if (iout[i]>=nrad){ ying of iout[j]-=nrad; (outside North America) karry=1; else karry=0; iout [nc]=iin[nc]+ja+karry; If radix-changing,rather than compression,is your primary aim (for example to convert an arbitrary file into printable characters)then you are of course free to set all the components of nfreq equal,say,to 1.914 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). jh=JTRY(acode->jdif,acode->ncumfq[*ich+2],acode->ncum); jl=JTRY(acode->jdif,acode->ncumfq[*ich+1],acode->ncum); acode->jdif=jh-jl; arcsum(acode->ilob,acode->iupb,jh,NWK,acode->nrad,acode->nc); arcsum(acode->ilob,acode->ilob,jl,NWK,acode->nrad,acode->nc); How many leading digits to output (if encoding) or skip over? for (j=acode->nc;j<=NWK;j++) { if (*ich != acode->nch && acode->iupb[j] != acode->ilob[j]) break; if (*lcd > *lcode) { fprintf(stderr,"Reached the end of the ’code’ array.\n"); fprintf(stderr,"Attempting to expand its size.\n"); *lcode += *lcode/2; if ((*codep=(unsigned char *)realloc(*codep, (unsigned)(*lcode*sizeof(unsigned char)))) == NULL) { nrerror("Size expansion failed"); } } if (isign > 0) (*codep)[*lcd]=(unsigned char)acode->ilob[j]; ++(*lcd); } if (j > NWK) return; Ran out of message. Did someone forget to encode a acode->nc=j; terminating ncd? for(j=0;acode->jdif<acode->minint;j++) How many digits to shift? acode->jdif *= acode->nrad; if (acode->nc-j < 1) nrerror("NWK too small in arcode."); if (j) { Shift them. for (k=acode->nc;k<=NWK;k++) { acode->iupb[k-j]=acode->iupb[k]; acode->ilob[k-j]=acode->ilob[k]; } } acode->nc -= j; for (k=NWK-j+1;k<=NWK;k++) acode->iupb[k]=acode->ilob[k]=0; } return; Normal return. } void arcsum(unsigned long iin[], unsigned long iout[], unsigned long ja, int nwk, unsigned long nrad, unsigned long nc) Used by arcode. Add the integer ja to the radix nrad multiple-precision integer iin[nc..nwk]. Return the result in iout[nc..nwk]. { int j,karry=0; unsigned long jtmp; for (j=nwk;j>nc;j--) { jtmp=ja; ja /= nrad; iout[j]=iin[j]+(jtmp-ja*nrad)+karry; if (iout[j] >= nrad) { iout[j] -= nrad; karry=1; } else karry=0; } iout[nc]=iin[nc]+ja+karry; } If radix-changing, rather than compression, is your primary aim (for example to convert an arbitrary file into printable characters) then you are of course free to set all the components of nfreq equal, say, to 1
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有