├── .gitignore ├── CHANGES ├── INSTALL ├── LICENSE ├── README ├── README.md ├── TESTING ├── benchmk ├── README ├── hmatgen.c ├── linux_p2.tim ├── smatgen.c ├── timbes.c ├── timeigv.c ├── timeval.c ├── timfft2.c ├── timfftgc.c ├── timheval.c ├── timhevec.c ├── timhsrt.c ├── timintg.c ├── timlpac.c ├── timmiv.c ├── timmsrt.c ├── timmul.c ├── timnrml.c ├── timqsrt.c ├── timslpac.c └── timssrt.c ├── byteord.c ├── ccmath.h ├── cfit ├── chcof.c ├── chpade.c ├── csfit.c ├── cspl.c ├── csplp.c ├── dcspl.c ├── evpsq.c ├── evpsqv.c ├── fitval.c ├── ftch.c ├── gnlsq.c ├── lsqsv.c ├── orpol.h ├── plsq.c ├── pplsq.c ├── psqcf.c ├── psqvar.c ├── qrbdbv.c ├── qrlsq.c ├── qrvar.c ├── seqlsq.c ├── sv2lsq.c ├── svdlsq.c ├── test │ ├── README │ ├── data │ │ ├── cspin.dat │ │ ├── lsqsv.dat │ │ ├── tlsq1.dat │ │ ├── tqr1.dat │ │ └── tqr2.dat │ ├── tchcof.c │ ├── tchpade.c │ ├── tchpade2.c │ ├── tcspl.c │ ├── tcsplp.c │ ├── tevpsq.c │ ├── tfitval.c │ ├── tgnlsq.c │ ├── tlsqsv.c │ ├── tnlsq.c │ ├── tplsq.c │ ├── tpplsq.c │ ├── tqrlsq.c │ ├── tqrlsq2.c │ ├── tsv2lsq.c │ └── tsvdlsq.c └── tnsfit.c ├── complex ├── alt │ ├── README │ ├── cihypa.c │ └── complex.h ├── carith.c ├── cexp.c ├── chypb.c ├── cihyp.c ├── citrg.c ├── complex.h ├── csqrt.c ├── ctrig.c └── test │ ├── README │ ├── data │ ├── caop2.dat │ ├── carith.dat │ ├── chypb.dat │ ├── clog.dat │ ├── csqrt.dat │ └── ctrg.dat │ ├── tcacos.c │ ├── tcacosh.c │ ├── tcarith.c │ ├── tcarop2.c │ ├── tcasin.c │ ├── tcasinh.c │ ├── tcatan.c │ ├── tcatanh.c │ ├── tchypb.c │ ├── tclog.c │ ├── tcsqrt.c │ └── tctrig.c ├── fft ├── complex.h ├── fft2.c ├── fft2_d.c ├── fftgc.c ├── fftgr.c ├── ftuns.c ├── pfac.c ├── pshuf.c ├── pwspec.c ├── smoo.c └── test │ ├── README │ ├── data │ └── smoo.dat │ ├── t2dfft.c │ ├── tfft2.c │ ├── tfftgc.c │ ├── tfftgr.c │ ├── tfftiv.c │ ├── tftuns.c │ ├── tpfac.c │ ├── tpwspec.c │ └── tsmoo.c ├── geom ├── crossp.c ├── dotp.c ├── euler.c ├── htgaaa.c ├── htgarea.c ├── htgasa.c ├── htgsas.c ├── htgsss.c ├── leng.c ├── metpr.c ├── rotax.c ├── scalv.c ├── stgaaa.c ├── stgarea.c ├── stgasa.c ├── stgsas.c ├── stgsss.c ├── test │ ├── README │ ├── data │ │ ├── metp.dat │ │ ├── thtrg.dat │ │ ├── tptrg.dat │ │ ├── tptrg2.dat │ │ └── tstrg.dat │ ├── teuler.c │ ├── thtrgas.c │ ├── thtrgss.c │ ├── tmetpr.c │ ├── tptrgssa.c │ ├── tptrgtt.c │ ├── trotax.c │ ├── tstrgas.c │ ├── tstrgss.c │ └── tvops1.c ├── trgarea.c ├── trgasa.c ├── trgsas.c ├── trgssa.c ├── trgsss.c └── trvec.c ├── install.sh ├── intg ├── chintg.c ├── deqsy.c ├── fchb.c ├── fintg.c └── test │ ├── README │ ├── tchintg.c │ ├── tcnvx.c │ ├── tdeqsy.c │ └── tfintg.c ├── lgpl.license ├── makelibs.sh ├── manual ├── C00-intro ├── C01-matrix ├── C02-intg ├── C03-geom ├── C04-cfit ├── C05-roots ├── C06-fft ├── C07-simu ├── C08-statf ├── C09-sfunc ├── C10-sort ├── C11-tseries ├── C12-complex ├── C13-xarm └── C14-util ├── matrix ├── atou1.c ├── atovm.c ├── chouse.c ├── chousv.c ├── cmattr.c ├── cmcpy.c ├── cminv.c ├── cmmul.c ├── cmmult.c ├── cmprt.c ├── complex.h ├── csolv.c ├── cvmul.c ├── eigen.c ├── eigval.c ├── evmax.c ├── hconj.c ├── heigval.c ├── heigvec.c ├── hevmax.c ├── hmgen.c ├── house.c ├── housev.c ├── ldumat.c ├── ldvmat.c ├── matprt.c ├── mattr.c ├── matutl.h ├── mcopy.c ├── minv.c ├── mmul.c ├── ortho.c ├── otrma.c ├── otrsm.c ├── psinv.c ├── qrbdi.c ├── qrbdu1.c ├── qrbdv.c ├── qrecvc.c ├── qreval.c ├── qrevec.c ├── rmmult.c ├── ruinv.c ├── smgen.c ├── solv.s ├── solvps.c ├── solvru.c ├── solvtd.c ├── supp │ ├── README │ ├── solv.c │ └── solv.s ├── sv2u1v.c ├── sv2uv.c ├── sv2val.c ├── svdu1v.c ├── svduv.c ├── svdval.c ├── test │ ├── README │ ├── data │ │ ├── cm42.dat │ │ ├── hm4.bin │ │ ├── mat.dat │ │ ├── mop1.dat │ │ ├── mop2.dat │ │ ├── rumat.dat │ │ ├── sm5.bin │ │ ├── sm6.bin │ │ ├── sol.dat │ │ ├── solru.dat │ │ ├── spdm.dat │ │ ├── spsol.dat │ │ ├── std.dat │ │ ├── svd1.dat │ │ ├── svd2.dat │ │ ├── svd3.dat │ │ ├── svd4.dat │ │ ├── svd5.dat │ │ ├── svd6.dat │ │ ├── svd7.dat │ │ ├── tdatS1.bin │ │ └── tdatS23.bin │ ├── tchouse.c │ ├── tchousv.c │ ├── tcminv.c │ ├── tcmmul.c │ ├── tcmmult.c │ ├── tcmops.c │ ├── tcsolv.c │ ├── teigen.c │ ├── teval.c │ ├── tevmax.c │ ├── theigval.c │ ├── theigvec.c │ ├── thevmax.c │ ├── thmgen.c │ ├── thouse.c │ ├── thousev.c │ ├── tminv.c │ ├── tmmul.c │ ├── tmop1.c │ ├── tmop2.c │ ├── totrmat.c │ ├── tpsinv.c │ ├── trmmult.c │ ├── truinv.c │ ├── tsmgen.c │ ├── tsolv.c │ ├── tsolvps.c │ ├── tsolvru.c │ ├── tsolvtd.c │ ├── tsv2u1v.c │ ├── tsv2uv.c │ ├── tsv2val.c │ ├── tsvalS.c │ ├── tsvdu1v.c │ ├── tsvduv.c │ ├── tsvduvS.c │ ├── tsvdval.c │ ├── tunitar.c │ ├── tutrncm.c │ └── util │ │ ├── cmatgen.c │ │ ├── cmprt.c │ │ ├── hmatgen.c │ │ ├── matgen.c │ │ ├── rmprt.c │ │ └── smatgen.c ├── trncm.c ├── trnm.c ├── unitary.c ├── utrncm.c ├── utrnhm.c └── vmul.c ├── non_intel.sh ├── roots ├── complex.h ├── optmiz.c ├── optsch.c ├── plrt.c ├── polyc.c ├── secrt.c ├── solnl.c ├── solnx.c └── test │ ├── README │ ├── data │ ├── pol1.dat │ └── pol2.dat │ ├── op-test │ ├── f4d.c │ ├── fchqad.c │ ├── fhv.c │ ├── frb.c │ └── topth.c │ ├── toptmiz.c │ ├── toptsch.c │ ├── tplrt.c │ ├── tsecrt.c │ ├── tsolnl.c │ └── tsolnx.c ├── runtest ├── sfunc ├── airy.c ├── amelp.c ├── biry.c ├── drbes.c ├── drspbes.c ├── felp.c ├── g2elp.c ├── gaml.c ├── gelp.c ├── gsng.c ├── gsng2.c ├── ibes.c ├── jbes.c ├── jspbes.c ├── kbes.c ├── kspbes.c ├── nbes.c ├── nome.c ├── psi.c ├── rcbes.c ├── rcspbs.c ├── test │ ├── README │ ├── data │ │ ├── g2elp.dat │ │ ├── gel2a.dat │ │ ├── gel2b.dat │ │ ├── gel2c.dat │ │ ├── gel2d.dat │ │ └── gsng.dat │ ├── tairy.c │ ├── tamelp.c │ ├── tbes.c │ ├── tdrbes.c │ ├── tdrspbes.c │ ├── tfelp.c │ ├── tg2elp.c │ ├── tg2elps.c │ ├── tgaml.c │ ├── tgelp.c │ ├── tgsng.c │ ├── tgsng2.c │ ├── tjbes.c │ ├── tnome.c │ ├── tpsi.c │ ├── trcbes.c │ ├── trcspbs.c │ ├── tspbes.c │ └── ttheta.c ├── theta.c └── yspbes.c ├── simu ├── autcor.c ├── bran.c ├── bran2.c ├── hist.c ├── lran1.c ├── lrana.s ├── lranb.s ├── lrand.c ├── norm.c ├── norm2.c ├── nrml.c ├── sampl.c ├── shuffl.c ├── supp │ ├── README │ ├── lrana.asm │ ├── lrana.c │ ├── lrana.s │ ├── lranb.asm │ ├── lranb.c │ └── lranb.s ├── test │ ├── README │ ├── distribution │ │ ├── norm2dis.c │ │ ├── normdis.c │ │ ├── nrmldis.c │ │ ├── unfl2dis.c │ │ └── unfldis.c │ ├── tbran.c │ ├── tbran2.c │ ├── timing │ │ ├── timbran.c │ │ ├── timbran2.c │ │ ├── times.dat │ │ ├── timlran1.c │ │ ├── timlrand.c │ │ ├── timnorm.c │ │ ├── timnorm2.c │ │ ├── timnrml.c │ │ ├── timunfl.c │ │ └── timunfl2.c │ ├── tlran1.c │ ├── tlrand.c │ ├── tnorm.c │ ├── tnorm2.c │ ├── tnrml.c │ ├── tprand.c │ ├── tsampl.c │ ├── tsamshf.c │ ├── tshuffl.c │ ├── tunfl.c │ └── tunfl2.c ├── unfl.c └── unfl2.c ├── sort ├── batdel.c ├── batins.c ├── btdel.c ├── btins.c ├── btsearch.c ├── btsort.c ├── hash.h ├── hashdel.c ├── hashins.c ├── hfind.c ├── hsort.c ├── hval.c ├── merge.h ├── msort.c ├── numcmp.c ├── prbtree.c ├── prtree.c ├── qsrt.c ├── ssort.c ├── test │ ├── README │ ├── data │ │ ├── hash.dat │ │ └── ttree.dat │ ├── tbatree.c │ ├── tbtree.c │ ├── tbtree0.c │ ├── thash.c │ ├── thsort.c │ ├── tmsort.c │ ├── tqsrt.c │ └── tssort.c ├── tree.h ├── tsearch.c └── tsort.c ├── statf ├── gaml.c ├── pctb.c ├── pctbn.c ├── pctg.c ├── pctgn.c ├── pctn.c ├── qbeta.c ├── qbnc.c ├── qgama.c ├── qgnc.c ├── qnorm.c └── test │ ├── README │ ├── tbetanc.c │ ├── tdbeta.c │ ├── tdgama.c │ ├── tdnorm.c │ └── tgamanc.c ├── testex ├── tseries ├── arma.h ├── armaf.h ├── drfmod.c ├── drmod.c ├── evfmod.c ├── evmod.c ├── fixts.c ├── fixtsf.c ├── parma.c ├── resid.c ├── sany.c ├── sarma.c ├── sdiff.c ├── seqts.c ├── seqtsf.c ├── test │ ├── README │ ├── data │ │ ├── tfs0.b │ │ ├── tfs0.dat │ │ ├── tfs1.dat │ │ ├── tfs2.dat │ │ ├── tfs3.dat │ │ ├── tfs4.dat │ │ ├── tfs5.dat │ │ ├── ts0.b │ │ ├── ts0.dat │ │ ├── ts0.er │ │ ├── ts1.dat │ │ ├── ts2.dat │ │ ├── ts3.dat │ │ ├── ts4.dat │ │ ├── ts5.dat │ │ ├── ts6.b │ │ ├── ts6.dat │ │ ├── ts7.dat │ │ ├── ts8.dat │ │ └── ts9.dat │ ├── generators │ │ ├── README │ │ ├── garma.c │ │ └── gfarma.c │ ├── tdrfmod.c │ ├── tdrmod.c │ ├── tevfmod.c │ ├── tevmod.c │ ├── tfmest.c │ ├── tfsread.c │ ├── tmest.c │ ├── tparma.c │ ├── tresid.c │ ├── tsany.c │ ├── tsarma.c │ ├── tsdiff.c │ ├── tsread.c │ └── txmean.c └── xmean.c ├── util ├── bits.c ├── bpat.c ├── bpatx.c ├── lbits.c ├── pwr.c ├── test │ ├── README │ ├── tbits.c │ ├── tbpat.c │ ├── tbpatx.c │ ├── tlbits.c │ └── tpwr.c └── xpre.h └── xarm ├── atox.c ├── constant.h ├── prxpr.c ├── sfmod.c ├── shift.c ├── supp ├── big-end │ ├── README │ ├── xfmod.c │ ├── xpre.h │ └── xtodub.c ├── data │ ├── README │ ├── const07.h │ ├── const11.h │ ├── const15.h │ ├── const19.h │ ├── const23.h │ ├── const27.h │ ├── const31.h │ ├── xcon07.dat │ ├── xcon11.dat │ ├── xcon15.dat │ ├── xcon19.dat │ ├── xcon23.dat │ ├── xcon27.dat │ ├── xcon31.dat │ ├── xconz33.dat │ └── xpre.h └── little-end │ ├── README │ ├── xfmod.c │ ├── xpre.h │ └── xtodub.c ├── test ├── README ├── data │ ├── aop1.dat │ ├── atox.dat │ ├── xcmp.dat │ ├── xcvt.dat │ └── xfrex.dat ├── tatox.c ├── txaop1.c ├── txaop2.c ├── txchser.c ├── txconv.c ├── txdiv.c ├── txexp.c ├── txfmod.c ├── txfrex.c ├── txhypb.c ├── txivtrg.c ├── txlog.c ├── txprcmp.c ├── txpwr.c ├── txsqrt.c └── txtrig.c ├── xadd.c ├── xchcof.c ├── xdiv.c ├── xevtch.c ├── xexp.c ├── xfmod.c ├── xhypb.c ├── xivtrg.c ├── xlog.c ├── xmath.h ├── xmul.c ├── xneg.c ├── xprcmp.c ├── xpre.h ├── xpwr.c ├── xsqrt.c ├── xtodub.c └── xtrig.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /benchmk/timheval.c: -------------------------------------------------------------------------------- 1 | /* timheval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Time computation of eigenvalues of a Hermitian matrix. 10 | 11 | Input file: created by hmatgen.c 12 | */ 13 | #include 14 | #include "ccmath.h" 15 | void main(int na,char **av) 16 | { Cpx *a; double *ev; int n; 17 | clock_t st,en; double dt; 18 | FILE *fb; 19 | if(na!=2){ printf("para: input_file\n"); exit(1);} 20 | fb=fopen(*++av,"rb"); 21 | fread((void *)&n,sizeof(int),1,fb); 22 | printf(" hermitian e-val: dim=%d\n",n); 23 | a=(Cpx *)calloc(n*n,sizeof(Cpx)); 24 | ev=(double *)calloc(n,sizeof(double)); 25 | fread((void *)a,sizeof(Cpx),n*n,fb); 26 | st=clock(); 27 | heigval(a,ev,n); 28 | en=clock(); 29 | dt=(double)(en-st)/(double)CLOCKS_PER_SEC; 30 | printf(" time= %.2f sec.\n",dt); 31 | } 32 | -------------------------------------------------------------------------------- /benchmk/timnrml.c: -------------------------------------------------------------------------------- 1 | /* timnrml.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Time the generation of pseudorandom normals 10 | 11 | Input parameter: n -> number of normals generated 12 | */ 13 | #include 14 | #include "ccmath.h" 15 | void main(int na,char **av) 16 | { unsigned int i,n; double x; 17 | clock_t st,en; double dt; 18 | if(na!=2){ printf("para: count\n"); exit(1);} 19 | n=atoi(*++av); 20 | i=123456789; setnrml(i); 21 | printf(" Timing Random Normal Generator nrml()\n"); 22 | printf(" number generated= %ld\n",n); 23 | st=clock(); 24 | for(i=0; i 9 | void chcof(double *c,int m,double (*func)()) 10 | { double *p,*q,a,da,an,f; int j; 11 | ++m; q=c+m; a=1.570796326794897/m; da=a*2.; 12 | for(p=c; p 9 | void chpade(double *c,double *a,int m,double *b,int n) 10 | { double *mat,*ps; int r,s,k; 11 | mat=(double *)calloc(n*n,sizeof(double)); 12 | for(ps=mat,s=m+1,k=1; k<=n ;){ 13 | for(r=1; r<=n ;++r) *ps++ =(c[abs(s-r)]+c[s+r])/2.; 14 | b[k++]= -c[s++]; 15 | } 16 | solv(mat,b+1,n); b[0]=1.; 17 | for(s=0; s<=m ;++s){ a[s]=c[s]; 18 | for(r=1; r<=n ;++r) a[s]+=(c[abs(s-r)]+c[s+r])*b[r]/2.; 19 | } 20 | a[0]/=2.; free(mat); 21 | } 22 | -------------------------------------------------------------------------------- /cfit/csfit.c: -------------------------------------------------------------------------------- 1 | /* csfit.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double csfit(double w,double *x,double *y,double *z,int m) 9 | { double s,t; int j,k; 10 | if(wx[m]) return 0.; 11 | for(j=1; w>x[j] ;++j); k=j-1; 12 | s=(t=w-x[k])*(x[j]-w); t/=(x[j]-x[k]); 13 | return (t*y[j]+(1.-t)*y[k]-s*(z[j]*(1.+t)+z[k]*(2.-t))); 14 | } 15 | -------------------------------------------------------------------------------- /cfit/cspl.c: -------------------------------------------------------------------------------- 1 | /* cspl.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include 10 | void cspl(double *x,double *y,double *z,int m,double tn) 11 | { double h,s,t,*pa,*pb,*a,*b; int j; 12 | if(tn==0.) tn=2.; 13 | else{ h=sinh(tn); tn=(tn*cosh(tn)-h)/(h-tn);} 14 | pa=(double *)calloc(2*m,sizeof(double)); pb=pa+m; 15 | h=x[1]-x[0]; t=(y[1]-y[0])/h; 16 | for(j=1,a=pa,b=pb; j0 ;--j){ z[j]-= *b-- *z[j+1]; z[j]/= *a--;} 24 | free(pa); 25 | } 26 | -------------------------------------------------------------------------------- /cfit/dcspl.c: -------------------------------------------------------------------------------- 1 | /* dcspl.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double dcspl(double x,double *u,double *v,double *z,int m) 9 | { int i,k; double h,d; 10 | if(x>u[m] || xu[i] ;++i); 12 | k=i-1; h=u[i]-u[k]; 13 | x-=u[k]; x/=h; 14 | d=(v[i]-v[k])/h; 15 | return d-h*((z[i]-z[k])*(1.-3.*x*x)+z[k]*(3.-6.*x)); 16 | } 17 | -------------------------------------------------------------------------------- /cfit/evpsq.c: -------------------------------------------------------------------------------- 1 | /* evpsq.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "orpol.h" 9 | double evpsq(double x,Opol *c,int m) 10 | { int i; double f,s,t; 11 | f=s=c[m-1].cf; t=0.; 12 | for(i=m-2; i>=0 ;--i){ 13 | f=c[i].cf+(x-c[i].df)*s-c[i+1].hs*t; 14 | t=s; s=f; 15 | } 16 | return f; 17 | } 18 | -------------------------------------------------------------------------------- /cfit/evpsqv.c: -------------------------------------------------------------------------------- 1 | /* evpsqv.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "orpol.h" 10 | double evpsqv(double x,Opol *c,int m,double *v,double sig) 11 | { int i; double f,h,s,t,r,z; 12 | f=s=c[m-1].cf; t=0.; 13 | for(i=m-2; i>=0 ;--i){ 14 | f=c[i].cf+(x-c[i].df)*s-c[i+1].hs*t; 15 | t=s; s=f; 16 | } 17 | if(v!=0){ 18 | r=s=1.; t=z=0.; 19 | for(i=0; i 9 | #include 10 | static double *h,dl=1.e-8; 11 | double fitval(double x,double *s,double *par,double (*fun)(), 12 | double *v,int n) 13 | { double f,r,d; int i,j; 14 | f=(*fun)(x,par); 15 | for(i=0; ia ;){ nu= *p-- +y*t-tf; tf=t; t=nu;} 12 | nu= *p+x*t-tf; t=tf=0.; 13 | for(p=b+n; p>b ;){ de= *p-- +y*t-tf; tf=t; t=de;} 14 | de= *p+x*t-tf; 15 | return nu/de; 16 | } 17 | -------------------------------------------------------------------------------- /cfit/orpol.h: -------------------------------------------------------------------------------- 1 | /* orpol.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef OPOL 9 | struct orpol {double cf,hs,df;}; 10 | typedef struct orpol Opol; 11 | #define OPOL 1 12 | #endif 13 | -------------------------------------------------------------------------------- /cfit/pplsq.c: -------------------------------------------------------------------------------- 1 | /* pplsq.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "orpol.h" 10 | void plsq(double *x,double *y,int n,Opol *c,double *ss,int m); 11 | void psqcf(double *pc,Opol *cf,int m); 12 | double pplsq(double *x,double *y,int n,double *bc,int m) 13 | { Opol *c; double *ss,sq; 14 | c=(Opol *)calloc(m,sizeof(Opol)); 15 | ss=(double *)calloc(m,sizeof(double)); 16 | plsq(x,y,n,c,ss,m); 17 | psqcf(bc,c,m); 18 | sq=ss[m-1]; 19 | free(c); free(ss); 20 | return sq; 21 | } 22 | -------------------------------------------------------------------------------- /cfit/psqcf.c: -------------------------------------------------------------------------------- 1 | /* psqcf.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "orpol.h" 10 | void psqcf(double *b,Opol *c,int m) 11 | { int i,j,k; double *sm,*s,u,v; 12 | if(m>1){ 13 | sm=(double *)calloc(m*m,sizeof(double)); 14 | sm[0]=sm[m+1]=1.; sm[1]= -c[0].df; 15 | for(i=2; in) ssq/=(double)(m-n); 13 | ruinv(v,n); 14 | for(j=0,p=v; j 9 | double tnsfit(double w,double *x,double *y,double *z,int m,double tn) 10 | { double s,t,u,a=sinh(tn); int j,k; 11 | if(wx[m]) return 0.; 12 | for(j=1; w>x[j] ;++j); k=j-1; 13 | t=(w-x[k])/(s=x[j]-x[k]); s*=s/(a-tn); u=1.-t; 14 | return t*y[j]+u*y[k]+s*(z[j]*(sinh(tn*t)-t*a)+z[k]*(sinh(tn*u)-u*a)); 15 | } 16 | -------------------------------------------------------------------------------- /complex/alt/README: -------------------------------------------------------------------------------- 1 | The code in cihypa.c provides an alternate version of the 2 | complex inverse hyperbolic functions suitable for use in 3 | computations related to relativistic kinematics. The 4 | difference is 5 | -------------------------------------------------------------------------------- /complex/alt/complex.h: -------------------------------------------------------------------------------- 1 | /* complex.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef CPX 9 | struct complex {double re,im;}; 10 | typedef struct complex Cpx; 11 | #define CPX 1 12 | #endif 13 | #include 14 | struct complex cadd(),csub(),cmul(),cdiv(); 15 | struct complex crmu(),cimu(),ccng(),cdef(); 16 | double cabs(),cnrm(); 17 | struct complex csqrt(),cexp(),clog(); 18 | struct complex csin(),ccos(),ctan(); 19 | struct complex casin(),cacos(),catan(); 20 | struct complex csinh(),ccosh(),ctanh(); 21 | struct complex casinh(),cacosh(),catanh(); 22 | -------------------------------------------------------------------------------- /complex/cexp.c: -------------------------------------------------------------------------------- 1 | /* cexp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | struct complex cexp(Cpx z) 10 | { double s,c,u; 11 | /* s=sincos(z.im,&c); */ 12 | s=sin(z.im); c=cos(z.im); 13 | u=exp(z.re); 14 | z.re=u*c; z.im=u*s; 15 | return z; 16 | } 17 | struct complex clog(Cpx z) 18 | { double r; 19 | r=z.re*z.re+z.im*z.im; 20 | z.im=atan2(z.im,z.re); 21 | z.re=ldexp(log(r),-1); 22 | return z; 23 | } 24 | -------------------------------------------------------------------------------- /complex/chypb.c: -------------------------------------------------------------------------------- 1 | /* chypb.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | struct complex csinh(Cpx z) 10 | { double c,s,u,v; 11 | /* s=sincos(z.im,&c); */ 12 | s=sin(z.im); c=cos(z.im); 13 | u=exp(z.re); v=1./u; 14 | u=ldexp(u+v,-1); v=u-v; 15 | z.re=v*c; z.im=u*s; 16 | return z; 17 | } 18 | struct complex ccosh(Cpx z) 19 | { double c,s,u,v; 20 | /* s=sincos(z.im,&c); */ 21 | s=sin(z.im); c=cos(z.im); 22 | u=exp(z.re); v=1./u; 23 | u=ldexp(u+v,-1); v=u-v; 24 | z.re=c*u; z.im=v*s; 25 | return z; 26 | } 27 | struct complex ctanh(Cpx z) 28 | { double c,s,u,v,d; 29 | /* s=sincos(z.im,&c); */ 30 | s=sin(z.im); c=cos(z.im); 31 | u=exp(z.re); v=1./u; 32 | u=ldexp(u+v,-1); v=u-v; 33 | d=c*c+v*v; z.re=u*v/d; z.im=s*c/d; 34 | return z; 35 | } 36 | -------------------------------------------------------------------------------- /complex/complex.h: -------------------------------------------------------------------------------- 1 | /* complex.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef CPX 9 | struct complex {double re,im;}; 10 | typedef struct complex Cpx; 11 | #define CPX 1 12 | #endif 13 | #include 14 | struct complex cadd(Cpx a,Cpx b),csub(Cpx a,Cpx b); 15 | struct complex cmul(Cpx a,Cpx b),cdiv(Cpx a,Cpx b); 16 | struct complex crmu(double x,Cpx a),cimu(double y,Cpx a); 17 | struct complex ccng(Cpx c),cdef(double r,double i); 18 | double cabs(Cpx a),cnrm(Cpx a); 19 | struct complex csqrt(Cpx a),cexp(Cpx a),clog(Cpx a); 20 | struct complex csin(Cpx a),ccos(Cpx a),ctan(Cpx a); 21 | struct complex casin(Cpx f),cacos(Cpx f),catan(Cpx f); 22 | struct complex csinh(Cpx h),ccosh(Cpx h),ctanh(Cpx h); 23 | struct complex casinh(Cpx g),cacosh(Cpx g),catanh(Cpx g); 24 | -------------------------------------------------------------------------------- /complex/csqrt.c: -------------------------------------------------------------------------------- 1 | /* csqrt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | struct complex csqrt(Cpx z) 10 | { double r; 11 | r=sqrt(z.re*z.re+z.im*z.im); 12 | r=sqrt(ldexp(r+fabs(z.re),-1)); 13 | if(r==0.) z.re=z.im=0.; 14 | else{ 15 | if(z.re>=0.){ z.re=r; z.im=ldexp(z.im/r,-1);} 16 | else{ z.re=ldexp(fabs(z.im)/r,-1); 17 | if(z.im>=0.) z.im=r; else z.im= -r; 18 | } 19 | } 20 | return z; 21 | } 22 | -------------------------------------------------------------------------------- /complex/ctrig.c: -------------------------------------------------------------------------------- 1 | /* ctrig.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | struct complex csin(Cpx z) 10 | { double c,s,u,v; 11 | /* s=sincos(z.re,&c); */ 12 | s=sin(z.re); c=cos(z.re); 13 | u=exp(z.im); v=1./u; 14 | u=ldexp(u+v,-1); v=u-v; 15 | z.re=u*s; z.im=c*v; 16 | return z; 17 | } 18 | struct complex ccos(Cpx z) 19 | { double c,s,u,v; 20 | /* s=sincos(z.re,&c); */ 21 | s=sin(z.re); c=cos(z.re); 22 | u=exp(z.im); v=1./u; 23 | u=ldexp(u+v,-1); v=u-v; 24 | z.re=c*u; z.im= -s*v; 25 | return z; 26 | } 27 | struct complex ctan(Cpx z) 28 | { double c,s,u,v,d; 29 | /* s=sincos(z.re,&c); */ 30 | s=sin(z.re); c=cos(z.re); 31 | u=exp(z.im); v=1./u; 32 | u=ldexp(u+v,-1); v=u-v; 33 | d=c*c+v*v; z.re=s*c/d; z.im=u*v/d; 34 | return z; 35 | } 36 | -------------------------------------------------------------------------------- /complex/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'complex' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. Input data files, if any 4 | are named in the test code header, are in the 'data' sub-directory. 5 | 6 | The correspondence between test programs and data input files 7 | is indicated below. 8 | 9 | tcarith data/carith.dat 10 | tcarop2 data/caop2.dat 11 | tchypb data/chypb.dat 12 | tclog data/clog.dat 13 | tcsqrt data/csqrt.dat 14 | tctrig data/ctrg.dat 15 | -------------------------------------------------------------------------------- /complex/test/data/caop2.dat: -------------------------------------------------------------------------------- 1 | 2. 3. 2 | 1.5 -4.3 3 | -1.2 5.3 4 | -2.1 -1. 5 | -------------------------------------------------------------------------------- /complex/test/data/carith.dat: -------------------------------------------------------------------------------- 1 | 1. 1. 2. -.5 2 | 1. 3. -3. -1.6 3 | .2 -1. -.7 4. 4 | -------------------------------------------------------------------------------- /complex/test/data/chypb.dat: -------------------------------------------------------------------------------- 1 | 1. 1. 2 | -.8 .75 3 | -.3 -1.2 4 | 1.5 -.6 5 | -------------------------------------------------------------------------------- /complex/test/data/clog.dat: -------------------------------------------------------------------------------- 1 | 1. 2. 2 | 1. -.5 3 | .5 4. 4 | -1.2 3. 5 | -------------------------------------------------------------------------------- /complex/test/data/csqrt.dat: -------------------------------------------------------------------------------- 1 | 1. 1. 2 | -1. .5 3 | -1. -.5 4 | 2. -1. 5 | -------------------------------------------------------------------------------- /complex/test/data/ctrg.dat: -------------------------------------------------------------------------------- 1 | 1. 1. 2 | -1. 2. 3 | -2. 3. 4 | -.8 -1.2 5 | -------------------------------------------------------------------------------- /complex/test/tcacos.c: -------------------------------------------------------------------------------- 1 | /* tcacos.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: cacos ccos 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=cacos(z); z=ccos(f); 19 | printf("acos(z)=(%e, %e) cos(z)=(%e, %e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /complex/test/tcacosh.c: -------------------------------------------------------------------------------- 1 | /* tcacosh.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: cacosh ccosh 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=cacosh(z); z=ccosh(f); 19 | printf("acosh(z)=(%e,%e) cosh(f)=(%e,%e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /complex/test/tcasin.c: -------------------------------------------------------------------------------- 1 | /* tcasin.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: casin csin 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=casin(z); z=csin(f); 19 | printf("asin(z)=(%e, %e) sin(f)=(%e, %e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /complex/test/tcasinh.c: -------------------------------------------------------------------------------- 1 | /* tcasinh.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: casinh csinh 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=casinh(z); z=csinh(f); 19 | printf("asinh(z)=(%e,%e) sinh(f)=(%e,%e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /complex/test/tcatan.c: -------------------------------------------------------------------------------- 1 | /* tcatan.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: catan ctan 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=catan(z); z=ctan(f); 19 | printf("atan(z)=(%e, %e) tan(f)=(%e, %e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /complex/test/tcatanh.c: -------------------------------------------------------------------------------- 1 | /* tcatanh.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: catanh ctanh 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { Cpx z,f; 14 | while(1){ 15 | printf("z ? "); 16 | /* enter Ctrl-Z to terminate */ 17 | if(scanf("%lf %lf",&z.re,&z.im)==EOF) break; 18 | f=catanh(z); z=ctanh(f); 19 | printf("atanh(z)=(%e,%e) tanh(f)=(%e,%e)\n",f.re,f.im,z.re,z.im); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /fft/complex.h: -------------------------------------------------------------------------------- 1 | /* complex.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef CPX 9 | struct complex {double re,im;}; 10 | typedef struct complex Cpx; 11 | #define CPX 1 12 | #endif 13 | #include 14 | struct complex cadd(Cpx a,Cpx b),csub(Cpx a,Cpx b); 15 | struct complex cmul(Cpx a,Cpx b),cdiv(Cpx a,Cpx b); 16 | struct complex crmu(double x,Cpx a),cimu(double y,Cpx a); 17 | struct complex ccng(Cpx c),cdef(double r,double i); 18 | double cabs(Cpx a),cnrm(Cpx a); 19 | struct complex csqrt(Cpx a),cexp(Cpx a),clog(Cpx a); 20 | struct complex csin(Cpx a),ccos(Cpx a),ctan(Cpx a); 21 | struct complex casin(Cpx f),cacos(Cpx f),catan(Cpx f); 22 | struct complex csinh(Cpx h),ccosh(Cpx h),ctanh(Cpx h); 23 | struct complex casinh(Cpx g),cacosh(Cpx g),catanh(Cpx g); 24 | -------------------------------------------------------------------------------- /fft/fft2_d.c: -------------------------------------------------------------------------------- 1 | /* fft2_d.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void fft2(struct complex *ff,int k,int j); 11 | fft2_d(struct complex *a,int m,int n,int f) 12 | { register int md,nd,i,j; struct complex *p,*q; 13 | register struct complex *r,*s; 14 | md=1<re+(*q)->re)/h; y=((*p)->im-(*q)->im)/h; 15 | u=((*p)->im+(*q)->im)/h; v=((*p)->re-(*q)->re)/h; 16 | (*p)->re=x; (*p++)->im=y; 17 | (*q)->re=u; (*q--)->im=v; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /fft/pfac.c: -------------------------------------------------------------------------------- 1 | /* pfac.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static int kpf[26]={2,3,5,7,11,13,17,19,23,29,31,37, 9 | 41,43,47,53,59,61,67,71,73,79,83,89,97,101}; 10 | int pfac(int n,int *kk,int fe) 11 | { int num,j,k,dc=1; 12 | if(fe=='e'){ n-=(n%2); dc=2;} 13 | for(;;n-=dc){ num=n; j=k=0; 14 | while(j<31){ 15 | if(num%kpf[k]!=0){ if(k==25) break; ++k;} 16 | else{ kk[++j]=kpf[k]; num=num/kpf[k]; 17 | if(num==1){ kk[0]=j; return n; } } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fft/pshuf.c: -------------------------------------------------------------------------------- 1 | /* pshuf.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | pshuf(Cpx **pa,Cpx **pb,int *kk,int n) 11 | { int *mm,*m,i,j,k,jk; struct complex **p,**q; 12 | mm=(int *)malloc((kk[0]+1)*sizeof(int)); 13 | for(i=1,*mm=1,m=mm; i<=kk[0] ;++i,++m) *(m+1)= *m*kk[i]; 14 | for(j=0,p=pb; j 9 | int pwspec(double *x,int n,int m) 10 | { int j,kk[32]; double s; 11 | struct complex {double re,im;} *p,*q; 12 | n=pfac(n,kk,'e'); 13 | p=(struct complex *)malloc(n*sizeof(*p)); 14 | fftgr(x,p,n,kk,'d'); 15 | for(s=0.,j=0; jre*q->re+q->im*q->im)/s; 18 | if(m) smoo(x,n,m); 19 | free(p); return n; 20 | } 21 | -------------------------------------------------------------------------------- /fft/smoo.c: -------------------------------------------------------------------------------- 1 | /* smoo.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | smoo(double *x,int n,int m) 10 | { double *p,*q,*pmax,*pmin,*pa,*pb,*ph; 11 | int ms; double s,t; 12 | ms=2*m+1; ph=x+n/2; 13 | p=pmin=(double *)calloc(ms,sizeof(*pmin)); 14 | q=pmax=pmin+ms-1; s=t=0.; 15 | for(pa=x+m,pb=ph-m; pa>x ;){ 16 | t+=(*p++ = *q-- = *pa--); s+= *pb++;} 17 | *ph=s/m; t=ms*(*pa++ = *q=t/m); s=1./ms; 18 | for(p=pmax,q=pmin,pb=pa+m; papmax) q=pmin; 20 | if((++p)>pmax) p=pmin; 21 | t+=(*p= *pb++); *pa++ =s*t; 22 | } 23 | for(pa=ph-1,pb=ph+1; pa>x ;) *pb++ = *pa--; 24 | free(pmin); 25 | } 26 | -------------------------------------------------------------------------------- /fft/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'fft' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. Input data files, if any 4 | are named in the test code header, are in the 'data' sub-directory. 5 | 6 | Only the following three tests require command line inputs: 7 | 8 | t2dfft 3 0 9 | tpfac 63 120 175 10 | tsmoo 2 data/smoo.dat 11 | -------------------------------------------------------------------------------- /fft/test/data/smoo.dat: -------------------------------------------------------------------------------- 1 | 8. 3. 5. 2. 1. 4. 3. 4. 1. 2. 5. 3. 2 | -------------------------------------------------------------------------------- /geom/crossp.c: -------------------------------------------------------------------------------- 1 | /* crossp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | void crossp(double *h,double *u,double *v) 9 | { h[0]=u[1]*v[2]-u[2]*v[1]; 10 | h[1]=u[2]*v[0]-u[0]*v[2]; 11 | h[2]=u[0]*v[1]-u[1]*v[0]; 12 | } 13 | -------------------------------------------------------------------------------- /geom/dotp.c: -------------------------------------------------------------------------------- 1 | /* dotp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double dotp(double *u,double *v,int m) 9 | { double s,*umx; 10 | for(umx=u+m,s=0.; u 9 | void euler(double *pv,int m,double a,double b,double c) 10 | { double t,cn,sn,*p,*q; int j,k; 11 | for(k=0; k<3 ;++k){ 12 | switch(k){ 13 | case 0: cn=cos(c); sn=sin(c); p=pv; q=p+1; break; 14 | case 1: cn=cos(b); sn= -sin(b); p=pv; q=p+2; break; 15 | case 2: cn=cos(a); sn=sin(a); p=pv; q=p+1; 16 | } 17 | for(j=0; j 9 | int htgaaa(double a,double b,double c,double *as) 10 | { double y,sa,sb,sc; 11 | double pi=3.141592653589793; 12 | if(a+b+c>=pi) return -1; 13 | sa=sin(a); sb=sin(b); sc=sin(c); 14 | a=cos(a); b=cos(b); c=cos(c); 15 | y=a*b*c; y+=y; 16 | y=sqrt(y+a*a+b*b+c*c-1.); 17 | a=y/(sb*sc); as[0]=log(a+sqrt(a*a+1.)); 18 | b=y/(sa*sc); as[1]=log(b+sqrt(b*b+1.)); 19 | c=y/(sa*sb); as[2]=log(c+sqrt(c*c+1.)); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /geom/htgarea.c: -------------------------------------------------------------------------------- 1 | /* htgarea.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double htgarea(double a,double b,double c) 9 | { double pi=3.141592653589793; 10 | return pi-a-b-c; 11 | } 12 | -------------------------------------------------------------------------------- /geom/htgasa.c: -------------------------------------------------------------------------------- 1 | /* htgasa.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int htgasa(double a,double cc,double b,double *ans) 10 | { double sa,sb,x; 11 | double pi=3.141592653589793; 12 | if(a<0. || b<0.) return -1; 13 | sa=sin(a); a=cos(a); sb=sin(b); b=cos(b); 14 | x=sa*sb*cosh(cc)-a*b; 15 | ans[1]=atan2(sqrt(1.-x*x),x); 16 | cc=sinh(cc)*sa*sb/sin(ans[1]); 17 | x=cc/sb; ans[0]=log(x+sqrt(x*x+1.)); 18 | x=cc/sa; ans[2]=log(x+sqrt(x*x+1.)); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /geom/htgsas.c: -------------------------------------------------------------------------------- 1 | /* htgsas.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | void htgsas(double a,double g,double b,double *an) 10 | { double sa,sb,sg; 11 | double pi=3.141592653589793; 12 | g=.5*(pi-g); sg=sin(g); g=cos(g); 13 | b=.5*(a-b); a-=b; 14 | sa=sinh(a); a=cosh(a); sb=sinh(b); b=cosh(b); 15 | an[0]=atan2(sg*b,g*a); 16 | an[2]=atan2(sg*sb,g*sa); 17 | g=sg*b/sin(an[0]); 18 | an[1]=log(g+sqrt(g*g-1)); 19 | a=an[0]-an[2]; an[0]+=an[2]; an[2]=a; 20 | an[1]+=an[1]; 21 | } 22 | -------------------------------------------------------------------------------- /geom/htgsss.c: -------------------------------------------------------------------------------- 1 | /* htgsss.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int htgsss(double a,double b,double c,double *ang) 10 | { double s; 11 | s=.5*(a+b+c); 12 | if(s-a<0. || s-b<0. || s-c<0.) return -1; 13 | a=cosh(a); b=cosh(b); c=cosh(c); 14 | s=a*b*c; s+=s; 15 | s=sqrt(1.-a*a-b*b-c*c+s); 16 | ang[0]=atan2(s,b*c-a); 17 | ang[1]=atan2(s,c*a-b); 18 | ang[2]=atan2(s,a*b-c); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /geom/leng.c: -------------------------------------------------------------------------------- 1 | /* leng.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #define NULL ((void *)0) 10 | double leng(double *a,double *b,int n) 11 | { double s,t; int j; 12 | if(b!=NULL){ 13 | for(s=0.,j=0; j 9 | int stgaaa(double a,double b,double c,double *ang) 10 | { double s; 11 | double pi=3.141592653589793; 12 | if(a+b+c<=pi) return -1; 13 | a=cos(a); b=cos(b); c=cos(c); 14 | s=a*b*c; s+=s; 15 | s=sqrt(1.-a*a-b*b-c*c-s); 16 | ang[0]=atan2(s,b*c+a); 17 | ang[1]=atan2(s,a*c+b); 18 | ang[2]=atan2(s,a*b+c); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /geom/stgarea.c: -------------------------------------------------------------------------------- 1 | /* stgarea.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double stgarea(double a,double b,double c) 9 | { double pi=3.141592653589793; 10 | return (a+b+c-pi); 11 | } 12 | -------------------------------------------------------------------------------- /geom/stgasa.c: -------------------------------------------------------------------------------- 1 | /* stgasa.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int stgasa(double a,double c,double b,double *ang) 10 | { double sa,sb,sc; int f; 11 | double pi=3.141592653589793; 12 | if(a>=0. && b>=0.) f=0; 13 | else if(a<0. && b<0.){ a= -a; b= -b; f=1;} 14 | else return -1; 15 | c*=.5; sc=sin(c); c=cos(c); 16 | b=.5*(a-b); a-=b; 17 | sa=sin(a); a=cos(a); sb=sin(b); b=cos(b); 18 | ang[0]=atan2(sc*b,c*a); 19 | ang[2]=atan2(sc*sb,c*sa); 20 | ang[1]=atan2(sa/cos(ang[2]),a/cos(ang[0])); 21 | a=ang[0]-ang[2]; ang[0]+=ang[2]; ang[2]=a; 22 | ang[1]+=ang[1]; 23 | if(ang[1]>0.) ang[1]=pi-ang[1]; 24 | else ang[1]= -ang[1]-pi; 25 | if(f) ang[1]= -ang[1]; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /geom/stgsas.c: -------------------------------------------------------------------------------- 1 | /* stgsas.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | void stgsas(double a,double g,double b,double *ang) 10 | { double sa,sb,sg; 11 | double pi=3.141592653589793; 12 | if(g>0.) g=.5*(pi-g); else g= -.5*(pi+g); 13 | sg=sin(g); g=cos(g); 14 | b=.5*(a-b); a-=b; 15 | sa=sin(a); a=cos(a); sb=sin(b); b=cos(b); 16 | ang[0]=atan2(sg*b,g*a); 17 | ang[2]=atan2(sg*sb,g*sa); 18 | if((sg=g*sa/cos(ang[2]))<0.707) ang[1]=asin(sg); 19 | else ang[1]=acos(g*a/cos(ang[0])); 20 | a=ang[0]-ang[2]; ang[0]+=ang[2]; ang[2]=a; 21 | ang[1]+=ang[1]; 22 | } 23 | -------------------------------------------------------------------------------- /geom/stgsss.c: -------------------------------------------------------------------------------- 1 | /* stgsss.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int stgsss(double a,double b,double c,double *ang) 10 | { double s; 11 | s=.5*(a+b+c); 12 | if(s-a<0. || s-b<0. || s-c<0.) return -1; 13 | a=cos(a); b=cos(b); c=cos(c); 14 | s=a*b*c; s+=s; 15 | s=sqrt(1.-a*a-b*b-c*c+s); 16 | ang[0]=atan2(s,a-b*c); 17 | ang[1]=atan2(s,b-a*c); 18 | ang[2]=atan2(s,c-a*b); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /geom/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'geom' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. Input data files, if any 4 | are named in the test code header, are in the 'data' sub-directory. 5 | 6 | The following list gives the command line inputs for the 7 | standard tests. 8 | 9 | teuler 10 | thtrgas data/thtrg.dat 11 | thtrgss data/thtrg.dat 12 | tmetpr data/metp.dat 13 | tptrgssa data/tptrg2.dat 14 | tptrgtt data/tptrg.dat 15 | trotax 16 | tstrgas data/tstrg.dat 17 | tstrgss data/tstrg.dat 18 | tvops1 19 | -------------------------------------------------------------------------------- /geom/test/data/metp.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 6. 2. 1. 2. 3 | 2. 4. 3. 1. 4 | 1. 3. 3.5 -3. 5 | 2. 1. -3. 4. 6 | 2. -.5 .5 -1. 7 | -------------------------------------------------------------------------------- /geom/test/data/thtrg.dat: -------------------------------------------------------------------------------- 1 | 2. 40. 3. 2 | 1.3 135. .8 3 | -------------------------------------------------------------------------------- /geom/test/data/tptrg.dat: -------------------------------------------------------------------------------- 1 | 2. 38. 4. 2 | 1. 150. 1.8 3 | -------------------------------------------------------------------------------- /geom/test/data/tptrg2.dat: -------------------------------------------------------------------------------- 1 | 2. 38. 2. 2 | 1. 150. 1.8 3 | -------------------------------------------------------------------------------- /geom/test/data/tstrg.dat: -------------------------------------------------------------------------------- 1 | 20. 32. 70. 2 | 120. 125. 65. 3 | -------------------------------------------------------------------------------- /geom/trgarea.c: -------------------------------------------------------------------------------- 1 | /* trgarea.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double trgarea(double a,double b,double c) 10 | { double s; 11 | s=a+b+c; 12 | s=sqrt(s*(s-a-a)*(s-b-b)*(s-c-c)); 13 | return .25*s; 14 | } 15 | -------------------------------------------------------------------------------- /geom/trgasa.c: -------------------------------------------------------------------------------- 1 | /* trgasa.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int trgasa(double a,double ss,double b,double *asn) 10 | { double h; 11 | double pi=3.141592653589793; 12 | if(a<0. || b<0.) return -1; 13 | asn[1]=h=pi-a-b; 14 | h=sin(h); 15 | asn[0]=ss*sin(a)/h; 16 | asn[2]=ss*sin(b)/h; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /geom/trgsas.c: -------------------------------------------------------------------------------- 1 | /* trgsas.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | void trgsas(double a,double g,double b,double *ans) 10 | { double u,s; 11 | u=a*b; s=u*sin(g); 12 | u*=cos(g); u+=u; s+=s; 13 | a*=a; b*=b; 14 | u=a+b-u; ans[1]=sqrt(u); 15 | ans[0]=atan2(s,b+u-a); 16 | ans[2]=atan2(s,a+u-b); 17 | } 18 | -------------------------------------------------------------------------------- /geom/trgssa.c: -------------------------------------------------------------------------------- 1 | /* trgssa.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int trgssa(double a,double b,double ba,double *an) 10 | { double x,y,z,v; 11 | x=a*cos(ba); ba=a*sin(ba); 12 | a*=a; b*=b; 13 | if((y=b-ba*ba)<0.) return -1; 14 | else y=sqrt(y); 15 | an[0]=x+y; v=an[0]*an[0]; 16 | z=an[0]*ba; z+=z; 17 | an[1]=atan2(z,a+b-v); 18 | an[2]=atan2(z,b+v-a); 19 | if(x>y){ 20 | an[3]=x-y; v=an[3]*an[3]; 21 | z=an[3]*ba; z+=z; 22 | an[4]=atan2(z,a+b-v); 23 | an[5]=atan2(z,b+v-a); 24 | } 25 | else an[3]=an[4]=an[5]=0.; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /geom/trgsss.c: -------------------------------------------------------------------------------- 1 | /* trgsss.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int trgsss(double a,double b,double c,double *ang) 10 | { double s; 11 | s=.5*(a+b+c); 12 | if(s-a<0. || s-b<0. || s-c<0.) return -1; 13 | s+=s; 14 | s=sqrt(s*(s-a-a)*(s-b-b)*(s-c-c)); 15 | a*=a; b*=b; c*=c; 16 | ang[0]=atan2(s,b+c-a); 17 | ang[1]=atan2(s,a+c-b); 18 | ang[2]=atan2(s,a+b-c); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /geom/trvec.c: -------------------------------------------------------------------------------- 1 | /* trvec.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | void trvec(double *c,double *a,double *b,int n) 9 | { double *mx; 10 | for(mx=c+n; c 9 | #include 10 | double chintg(double *a,int m,double (*func)()) 11 | { double f,t,tf,aj,adel,*pf,*pe,*p,*ps; 12 | int j; 13 | pf=(double *)calloc(2*m,sizeof(double)); pe=pf+m; 14 | ++m; adel=3.1415926535897932/m; 15 | for(p=pf,ps=pe,j=1,aj=adel; p0 ;--ps,--j){ 20 | for(p=pe-1,t=tf=0.; p>=pf ;){ f= *ps*t-tf+ *p--; tf=t; t=f;} 21 | a[j]*=t*2./(j*m); 22 | } 23 | for(j=1,a[0]=0.; jm-4 ;--j) if((t=fabs(a[j]))>f) f=t; 26 | free(pf); return f; 27 | } 28 | -------------------------------------------------------------------------------- /intg/fchb.c: -------------------------------------------------------------------------------- 1 | /* fchb.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double fchb(double x,double *a,int m) 9 | { double *p,y,t,tf,de; 10 | y=2.*x; t=tf=0.; 11 | for(p=a+m; p>a ;){ de= *p-- +y*t-tf; tf=t; t=de;} 12 | return (*p+x*t-tf); 13 | } 14 | -------------------------------------------------------------------------------- /intg/fintg.c: -------------------------------------------------------------------------------- 1 | /* fintg.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double fintg(double a,double b,int n,double te,double (*func)()) 10 | { int j,k,m; double s,t,x,h,ap[10],*p; 11 | s=((*func)(b)+(*func)(a))/2.; 12 | h=(b-a)/n; x=a; 13 | for(j=1; jre*q->re-p->im*q->im; 17 | s.im+=p->im*q->re+p->re*q->im; ++p; ++q; 18 | } 19 | *c++ =s; 20 | } 21 | } 22 | trncm(b,n); 23 | } 24 | -------------------------------------------------------------------------------- /matrix/cmmult.c: -------------------------------------------------------------------------------- 1 | /* cmmult.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void cmmult(Cpx *cm,Cpx *a,Cpx *b,int n,int m,int l) 11 | { Cpx z,*q0,*p,*q; int i,j,k; 12 | q0=(Cpx *)calloc(m,sizeof(Cpx)); 13 | for(i=0; ire*q0[k].re-p->im*q0[k].im; 18 | z.im+=p->im*q0[k].re+p->re*q0[k].im; 19 | } 20 | *q=z; 21 | } 22 | } 23 | free(q0); 24 | } 25 | -------------------------------------------------------------------------------- /matrix/cmprt.c: -------------------------------------------------------------------------------- 1 | /* cmprt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | void cmprt(Cpx *a,int m,int n,char *f) 10 | { int i,j; Cpx *p; 11 | for(i=0,p=a; ire,p->im); 13 | printf("\n"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /matrix/complex.h: -------------------------------------------------------------------------------- 1 | /* complex.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef CPX 9 | struct complex {double re,im;}; 10 | typedef struct complex Cpx; 11 | #define CPX 1 12 | #endif 13 | #include 14 | struct complex cadd(Cpx a,Cpx b),csub(Cpx a,Cpx b); 15 | struct complex cmul(Cpx a,Cpx b),cdiv(Cpx a,Cpx b); 16 | struct complex crmu(double x,Cpx a),cimu(double y,Cpx a); 17 | struct complex ccng(Cpx c),cdef(double r,double i); 18 | double cabs(Cpx a),cnrm(Cpx a); 19 | struct complex csqrt(Cpx a),cexp(Cpx a),clog(Cpx a); 20 | struct complex csin(Cpx a),ccos(Cpx a),ctan(Cpx a); 21 | struct complex casin(Cpx f),cacos(Cpx f),catan(Cpx f); 22 | struct complex csinh(Cpx h),ccosh(Cpx h),ctanh(Cpx h); 23 | struct complex casinh(Cpx g),cacosh(Cpx g),catanh(Cpx g); 24 | -------------------------------------------------------------------------------- /matrix/cvmul.c: -------------------------------------------------------------------------------- 1 | /* cvmul.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | void cvmul(Cpx *u,Cpx *a,Cpx *v,int n) 10 | { Cpx *q; int i,j; 11 | for(i=0; ire=u->im=0.; 13 | for(j=0,q=v; jre+=a->re*q->re-a->im*q->im; 15 | u->im+=a->im*q->re+a->re*q->im; 16 | } 17 | } 18 | } 19 | Cpx cvnrm(Cpx *u,Cpx *v,int n) 20 | { int k; Cpx z; 21 | z.re=z.im=0.; 22 | for(k=0; kre*v->re+u->im*v->im; 24 | z.im+=u->re*v->im-u->im*v->re; 25 | } 26 | return z; 27 | } 28 | -------------------------------------------------------------------------------- /matrix/eigen.c: -------------------------------------------------------------------------------- 1 | /* eigen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "matutl.h" 10 | void eigen(double *a,double *ev,int n) 11 | { double *dp; 12 | dp=(double *)calloc(n,sizeof(double)); 13 | housev(a,ev,dp,n); 14 | qrevec(ev,a,dp,n); trnm(a,n); 15 | free(dp); 16 | } 17 | -------------------------------------------------------------------------------- /matrix/eigval.c: -------------------------------------------------------------------------------- 1 | /* eigval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "matutl.h" 10 | void eigval(double *a,double *ev,int n) 11 | { double *dp; 12 | dp=(double *)calloc(n,sizeof(double)); 13 | house(a,ev,dp,n); 14 | qreval(ev,dp,n); 15 | free(dp); 16 | } 17 | -------------------------------------------------------------------------------- /matrix/evmax.c: -------------------------------------------------------------------------------- 1 | /* evmax.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include 10 | double evmax(double *a,double *u,int n) 11 | { double *p,*q,*qm,*r,*s,*t; 12 | double ev,evm,c,h; int kc; 13 | q=(double *)calloc(n,sizeof(double)); qm=q+n; 14 | *(qm-1)=1.; ev=0.; 15 | for(kc=0; kc<200 ;++kc){ h=c=0.; evm=ev; 16 | for(p=u,r=a,s=q; sre=q->re; 15 | (p++)->im= -q->im; *q=s; q+=n; 16 | } 17 | a->im= -a->im; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /matrix/heigval.c: -------------------------------------------------------------------------------- 1 | /* heigval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void heigval(Cpx *a,double *ev,int n) 12 | { double *dp; 13 | dp=(double *)calloc(n,sizeof(double)); 14 | chouse(a,ev,dp,n); 15 | qreval(ev,dp,n); 16 | free(dp); 17 | } 18 | -------------------------------------------------------------------------------- /matrix/heigvec.c: -------------------------------------------------------------------------------- 1 | /* heigvec.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void heigvec(Cpx *a,double *ev,int n) 12 | { double *dp; 13 | dp=(double *)calloc(n,sizeof(double)); 14 | chousv(a,ev,dp,n); 15 | qrecvc(ev,a,dp,n); hconj(a,n); 16 | free(dp); 17 | } 18 | -------------------------------------------------------------------------------- /matrix/hevmax.c: -------------------------------------------------------------------------------- 1 | /* hevmax.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | double hevmax(Cpx *a,Cpx *u,int n) 11 | { Cpx *x,*p,h; 12 | double e,ep,s,t,te=1.e-12; 13 | int k,j; 14 | x=(Cpx *)calloc(n,sizeof(Cpx)); 15 | x[0].re=1.; e=0.; 16 | do{ 17 | for(k=0,p=a,s=t=0.; kre*x[j].re-p->im*x[j].im; 20 | h.im+=p->im*x[j].re+p->re*x[j].im; 21 | } 22 | s+=h.re*h.re+h.im*h.im; 23 | t+=h.re*x[k].re+h.im*x[k].im; 24 | u[k]=h; 25 | } 26 | ep=e; e=s/t; s=1./sqrt(s); 27 | for(k=0; kfabs(te*e)); 31 | free(x); 32 | return e; 33 | } 34 | -------------------------------------------------------------------------------- /matrix/hmgen.c: -------------------------------------------------------------------------------- 1 | /* hmgen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void hmgen(Cpx *h,double *ev,Cpx *u,int n) 12 | { Cpx *v,*p; 13 | int i,j; double e; 14 | v=(Cpx *)calloc(n*n,sizeof(Cpx)); 15 | cmcpy(v,u,n*n); hconj(v,n); 16 | for(i=0,p=v; ire*=e; p->im*=e; 19 | } 20 | } 21 | cmmul(h,u,v,n); 22 | free(v); 23 | } 24 | -------------------------------------------------------------------------------- /matrix/matprt.c: -------------------------------------------------------------------------------- 1 | /* matprt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | void matprt(double *a,int n,int m,char *fmt) 10 | { int i,j; double *p; 11 | for(i=0,p=a; i 9 | static double tpi=6.28318530717958647; 10 | void ortho(double *e,int n) 11 | { int i,j,k,m; 12 | double *p,*q,c,s,a,unfl(); 13 | for(i=0,p=e; i 9 | void otrma(double *c,double *a,double *b,int n) 10 | { double z,*q0,*p,*s,*t; 11 | int i,j,k; 12 | q0=(double *)calloc(n,sizeof(double)); 13 | for(i=0; i 9 | void otrsm(double *sm,double *a,double *b,int n) 10 | { double z,*q0,*p,*s,*t; 11 | int i,j,k; 12 | q0=(double *)calloc(n,sizeof(double)); 13 | for(i=0; i 9 | void rmmult(double *rm,double *a,double *b,int n,int m,int l) 10 | { double z,*q0,*p,*q; int i,j,k; 11 | q0=(double *)calloc(m,sizeof(double)); 12 | for(i=0; itt) tt=z; 12 | tt*=1.e-16; 13 | for(j=0,p=a; j 9 | int solvps(double *a,double *b,int n) 10 | { double *p,*q,*r,*s,t; 11 | int j,k; 12 | for(j=0,p=a; j=0 ;--j,p-=n+1){ 26 | for(k=j+1,q=p+n; ks) s=t; 12 | s*=1.e-16; 13 | for(j=n-1,p=a+n*n-1; j>=0 ;--j,p-=n+1){ 14 | for(k=j+1,q=p+1; k=0 ;--j){ 13 | x[j]-=s*c[j]; s=(x[j]/=a[j]);} 14 | } 15 | -------------------------------------------------------------------------------- /matrix/supp/README: -------------------------------------------------------------------------------- 1 | The linear system solver assembly code 'solv.s' used in the 'matrix' 2 | segment of the library must be replaced by the corresponding C code 3 | 'solv.c' when the target platform is not an Intel based processor. 4 | 5 | For some reason the GNU-C optimization of solv.c code produced 6 | unnecessary saves and restores in the innermost loop of this 7 | linear system solver code. This severly degraded performance, 8 | so the assembly code 'solv.s' was introduced. I believe that 9 | this problem is unique to Intel patforms using the GNU-C 10 | compiler. 11 | -------------------------------------------------------------------------------- /matrix/test/data/cm42.dat: -------------------------------------------------------------------------------- 1 | 4 2 2 | -0.542 1.345 -0.830 -1.434 3 | -2.256 0.567 -1.018 -0.849 4 | -0.832 0.843 -0.999 -1.059 5 | 0.147 0.758 0.673 -0.536 6 | -------------------------------------------------------------------------------- /matrix/test/data/hm4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/matrix/test/data/hm4.bin -------------------------------------------------------------------------------- /matrix/test/data/mat.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 6. 3. 1. 2. 3 | 3. 5. 2. -1. 4 | 1. 2. 3. -2. 5 | 2. -1. -2. 4. 6 | -------------------------------------------------------------------------------- /matrix/test/data/mop1.dat: -------------------------------------------------------------------------------- 1 | 6 2 | 6. 4. -2. -3. 1. -4. 3 | 3. -7. 2. 4. -2. 1. 4 | 0. 3. 5. -4. 2. -1. 5 | 2. -1. 0. 4. 2. -3. 6 | 1. 0. 2. 5. -3. 4. 7 | -4. 2. -6. 3. 0. 8. 8 | 1. 1. 1. 1. 1. 1. 9 | -------------------------------------------------------------------------------- /matrix/test/data/mop2.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 4. 2. 1. .5 3 | .5 .5 -.5 .5 4 | .5 -.5 -.5 -.5 5 | .5 -.5 .5 .5 6 | .5 .5 .5 -.5 7 | -------------------------------------------------------------------------------- /matrix/test/data/rumat.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 4. -3. 1. -2. 3 | 0. -2. 2. -1. 4 | 0. 0. 3. -2. 5 | 0. 0. 0. 3. 6 | -------------------------------------------------------------------------------- /matrix/test/data/sm5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/matrix/test/data/sm5.bin -------------------------------------------------------------------------------- /matrix/test/data/sm6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/matrix/test/data/sm6.bin -------------------------------------------------------------------------------- /matrix/test/data/sol.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 6. 2. 1. 2. 3 | 3. -1. 5. -2. 4 | 1. 3. 0. 3. 5 | 0. 1. -4. -3. 6 | 8. -8.5 9.5 -1. 7 | -------------------------------------------------------------------------------- /matrix/test/data/solru.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 4. -3. 1. -2. 3 | 0. -2. 2. -1. 4 | 0. 0. 3. -2. 5 | 0. 0. 0. 3. 6 | 7 | 1. .5 -1. -2. -------------------------------------------------------------------------------- /matrix/test/data/spdm.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 1.875 .625 .375 1.125 3 | .625 1.875 1.125 .375 4 | .375 1.125 1.875 .625 5 | 1.125 .375 .625 1.875 6 | -------------------------------------------------------------------------------- /matrix/test/data/spsol.dat: -------------------------------------------------------------------------------- 1 | 4 2 | 3 | 1.875 .625 .375 1.125 4 | .625 1.875 1.125 .375 5 | .375 1.125 1.875 .625 6 | 1.125 .375 .625 1.875 7 | 8 | .5 1.5 -2. 2.5 -------------------------------------------------------------------------------- /matrix/test/data/std.dat: -------------------------------------------------------------------------------- 1 | 6 2 | 1. 2. 3. 6. -2. 7. 3 | 3. -1. 4. -3. 2. 4 | 2. 1. -2. -1. 5. 5 | 3. 6. 0. 9. 0. 9. 6 | -------------------------------------------------------------------------------- /matrix/test/data/svd1.dat: -------------------------------------------------------------------------------- 1 | 6 3 2 | 3 | 1.5 .5 8.2 4 | 2. 1. -3. 5 | 1. -2. -6. 6 | 4.5 -3. 2. 7 | .7 11. -1. 8 | 1.2 -.5 1. 9 | 10 | .5 -1. -.7 3. -1.7 .8 11 | -------------------------------------------------------------------------------- /matrix/test/data/svd2.dat: -------------------------------------------------------------------------------- 1 | 3 3 2 | 3 | 1.5 .5 8.2 4 | 2. 1. -3. 5 | 1. -2. -6. 6 | 7 | .5 -.5 1. 8 | -------------------------------------------------------------------------------- /matrix/test/data/svd3.dat: -------------------------------------------------------------------------------- 1 | 4 4 2 | 3 | 1. -.9 -2.3 1.7 4 | .5 -3.1 -1. .7 5 | .6 -.9 .35 -1. 6 | 1.8 -1.2 .75 3. 7 | -------------------------------------------------------------------------------- /matrix/test/data/svd4.dat: -------------------------------------------------------------------------------- 1 | 5 4 2 | 3 | 1. -.9 -2.3 1.7 4 | .5 -3.1 -1. .7 5 | .6 -.9 .35 -1. 6 | 1.8 -1.2 .75 3. 7 | 2. 1.2 -.9 2.7 8 | 9 | -------------------------------------------------------------------------------- /matrix/test/data/svd5.dat: -------------------------------------------------------------------------------- 1 | 6 4 2 | 3 | 1. .5 0. 0. 4 | 0. 1.5 0. 0. 5 | 0. 0. 2. 1.3 6 | 0. 0. 0. 1.9 7 | 0. 0. 0. 0. 8 | 0. 0. 0. 0. 9 | -------------------------------------------------------------------------------- /matrix/test/data/svd6.dat: -------------------------------------------------------------------------------- 1 | 6 4 2 | 3 | 1. .5 0. 0. 4 | 0. 1.5 .7 0. 5 | 0. 0. 0. 1.3 6 | 0. 0. 0. 1.9 7 | 0. 0. 0. 0. 8 | 0. 0. 0. 0. 9 | -------------------------------------------------------------------------------- /matrix/test/data/svd7.dat: -------------------------------------------------------------------------------- 1 | 7 5 2 | 3 | 2. .4 -1. -3.2 .8 4 | .3 -2. 1.3 2.7 -1.6 5 | -.4 .5 1. -3.1 1.5 6 | 1.2 .38 .88 -1. .7 7 | -.25 2. .6 -.5 -1.8 8 | .75 1. -2. 3.5 2. 9 | 1. .5 1. .5 6. 10 | 11 | .5 -.5 1. -2. .88 -1.25 .47 12 | -------------------------------------------------------------------------------- /matrix/test/data/tdatS1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/matrix/test/data/tdatS1.bin -------------------------------------------------------------------------------- /matrix/test/data/tdatS23.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/matrix/test/data/tdatS23.bin -------------------------------------------------------------------------------- /matrix/test/util/cmatgen.c: -------------------------------------------------------------------------------- 1 | /* cmatgen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { Cpx *a,*p; double nrml(); 12 | int n,m,j; unsigned int seed; 13 | FILE *fp; 14 | if(na!=3){ printf("para: dim o_file\n"); exit(1);} 15 | n=atoi(*++av); m=n*n; 16 | fp=fopen(*++av,"wb"); 17 | a=(Cpx *)calloc(m,sizeof(Cpx)); 18 | seed=(unsigned int)time(NULL); setnrml(seed); 19 | for(j=0,p=a; jre=nrml(); (p++)->im=nrml();} 20 | fwrite((void *)&n,sizeof(int),1,fp); 21 | fwrite((void *)a,sizeof(Cpx),m,fp); 22 | } 23 | -------------------------------------------------------------------------------- /matrix/test/util/cmprt.c: -------------------------------------------------------------------------------- 1 | /* cmprt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "ccmath.h" 9 | char fmt[]="(%7.3f,%7.3f)"; 10 | void main(int na,char **av) 11 | { Cpx *a; int n; 12 | FILE *fb; 13 | if(na!=2){ printf("para: input_file\n"); exit(1);} 14 | fb=fopen(*++av,"rb"); 15 | fread((void *)&n,sizeof(int),1,fb); 16 | a=(Cpx *)calloc(n*n,sizeof(Cpx)); 17 | fread((void *)a,sizeof(Cpx),n*n,fb); 18 | printf(" %d\n",n); 19 | cmprt(a,n,n,fmt); 20 | } 21 | -------------------------------------------------------------------------------- /matrix/test/util/hmatgen.c: -------------------------------------------------------------------------------- 1 | /* hmatgen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { Cpx *h,*u; FILE *fp; 12 | int i,n,m; unsigned int seed; double *e,s; 13 | if(na!=3){ printf("para: size o_file\n"); exit(1);} 14 | n=atoi(*++av); m=n*n; 15 | fp=fopen(*++av,"wb"); 16 | fwrite((void *)&n,sizeof(int),1,fp); 17 | h=(Cpx *)calloc(2*m,sizeof(Cpx)); u=h+m; 18 | e=(double *)calloc(n,sizeof(double)); 19 | for(i=0,s=1.; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { double *a,*p; 12 | int n,m,j; unsigned int seed; 13 | FILE *fp; 14 | if(na!=3){ printf("para: dim o_file\n"); exit(1);} 15 | n=atoi(*++av); m=n*n; 16 | fp=fopen(*++av,"wb"); 17 | a=(double *)calloc(m,sizeof(double)); 18 | seed=(unsigned int)time(NULL); setnrml(seed); 19 | for(j=0,p=a; j 9 | #include "complex.h" 10 | void utrncm(Cpx *cm,Cpx *a,Cpx *b,int n) 11 | { Cpx z,*q0,*p,*s,*t; 12 | int i,j,k; 13 | q0=(Cpx *)calloc(n,sizeof(Cpx)); 14 | for(i=0; ire*s->re+t->im*s->im; 19 | z.im+=t->im*s->re-t->re*s->im; 20 | } 21 | q0[j]=z; 22 | } 23 | for(j=0,p=cm,t=a; jre*s->re-t->im*s->im; 27 | z.im+=t->im*s->re+t->re*s->im; 28 | } 29 | *p=z; 30 | } 31 | } 32 | free(q0); 33 | } 34 | -------------------------------------------------------------------------------- /matrix/utrnhm.c: -------------------------------------------------------------------------------- 1 | /* utrnhm.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void utrnhm(Cpx *hm,Cpx *a,Cpx *b,int n) 11 | { Cpx z,*q0,*p,*s,*t; 12 | int i,j,k; 13 | q0=(Cpx *)calloc(n,sizeof(Cpx)); 14 | for(i=0; ire*s->re+t->im*s->im; 19 | z.im+=t->im*s->re-t->re*s->im; 20 | } 21 | q0[j]=z; 22 | } 23 | for(j=0,p=hm+i,t=a; j<=i ;++j,p+=n){ 24 | z.re=z.im=0.; 25 | for(k=0,s=q0; kre*s->re-t->im*s->im; 27 | z.im+=t->im*s->re+t->re*s->im; 28 | } 29 | *p=z; if(j 14 | struct complex cadd(Cpx a,Cpx b),csub(Cpx a,Cpx b); 15 | struct complex cmul(Cpx a,Cpx b),cdiv(Cpx a,Cpx b); 16 | struct complex crmu(double x,Cpx a),cimu(double y,Cpx a); 17 | struct complex ccng(Cpx c),cdef(double r,double i); 18 | double cabs(Cpx a),cnrm(Cpx a); 19 | struct complex csqrt(Cpx a),cexp(Cpx a),clog(Cpx a); 20 | struct complex csin(Cpx a),ccos(Cpx a),ctan(Cpx a); 21 | struct complex casin(Cpx f),cacos(Cpx f),catan(Cpx f); 22 | struct complex csinh(Cpx h),ccosh(Cpx h),ctanh(Cpx h); 23 | struct complex casinh(Cpx g),cacosh(Cpx g),catanh(Cpx g); 24 | -------------------------------------------------------------------------------- /roots/optsch.c: -------------------------------------------------------------------------------- 1 | /* optsch.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double optsch(double (*func)(),double a,double b,double test) 9 | { double x,y,f1,f2,r=.61803399,s; 10 | s=b-a; x=a+r*s; y=b-r*s; 11 | f1=(*func)(x); f2=(*func)(y); 12 | while(1){ s*=r; 13 | if(f2>f1){ if(s=0 ;--i){ 12 | s=py.re*z.re-py.im*z.im; 13 | py.im=py.im*z.re+py.re*z.im; py.re=s+cof[i]; 14 | } 15 | return py; 16 | } 17 | -------------------------------------------------------------------------------- /roots/secrt.c: -------------------------------------------------------------------------------- 1 | /* secrt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double secrt(double (*func)(),double x,double dx,double test) 9 | { double f,fp,y; int k; 10 | y=x-dx; fp=(*func)(y); 11 | for(k=0;;++k){ f=(*func)(x); 12 | dx=f*(x-y)/(f-fp); fp=f; y=x; x-=dx; 13 | if(((dx<0.)?-dx:dx) 12 | #define Tpi 6.283185308 13 | double fhv(double *x) 14 | { double r,an; extern int count; 15 | ++count; 16 | r=x[0]*x[0]+x[1]*x[1]; r=sqrt(r)-1.; 17 | an=x[2]-10.*atan2(x[1],x[0])/Tpi; 18 | return (100.*(an*an+r*r)+x[2]*x[2]); 19 | } 20 | -------------------------------------------------------------------------------- /roots/test/op-test/frb.c: -------------------------------------------------------------------------------- 1 | /* frb.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* Rosenbrock function: 9 | minimum = 0 at x[0]=1.0 x[1]=1.0 10 | */ 11 | double frb(double *x) 12 | { double f,y; extern int count; 13 | ++count; 14 | y=x[0]; f=1.0-y; y=x[1]-y*y; 15 | return 100.0*y*y+f*f; 16 | } 17 | -------------------------------------------------------------------------------- /runtest: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # script to compare test code output with the sample 4 | # output appended as a comment to the test source code 5 | # parameters: $1 = name of test source 6 | # $2 to $n = command line parameters for test (if any) 7 | 8 | f=$1; shift 9 | cc -O2 $f -lccm -lm # compile test program 10 | testex $f >tt0 # extract sample output -> tt0 11 | a.out $* >tt1 # run test with output -> tt1 12 | diff tt0 tt1 # compare output to sample output 13 | -------------------------------------------------------------------------------- /sfunc/amelp.c: -------------------------------------------------------------------------------- 1 | /* amelp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double amelp(double u,double k) 10 | { double a,b,cs[10]; int m,n=1; 11 | a=1.; b=sqrt(1.-k*k); 12 | for(m=0; (k=a-b)>4.e-15 ;++m){ 13 | cs[m]=k/2.; k=a+b; b=sqrt(a*b); 14 | a=k/2.; cs[m]/=a; n*=2; 15 | } 16 | for(u*=n*a,--m; m>=0 ;--m) 17 | u=(u+asin(cs[m]*sin(u)))/2.; 18 | return u; 19 | } 20 | -------------------------------------------------------------------------------- /sfunc/felp.c: -------------------------------------------------------------------------------- 1 | /* felp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #ifndef NULL 10 | #define NULL ((void *)0) 11 | #endif 12 | double felp(double an,double k,double *pk,double *pz,double *ph) 13 | { double a,b,c,s,h; int m=1; 14 | double pi=3.14159265358979; 15 | a=1.; b=sqrt(1.-k*k); s=h=0.; 16 | while((c=(a-b)/2.)>.5e-15){ m*=2; 17 | if((k=atan(b*tan(an)/a))<0.) k+=pi; 18 | if((k-=fmod(an,pi))>2.) k-=pi; 19 | an+=an+k; k=a+b; b=sqrt(a*b); a=k/2.; 20 | h+=c*a*m; s+=c*sin(an); 21 | } 22 | *pk=pi/(2.*a); an/=m*a; 23 | if(pz!=NULL){ 24 | *pz=s+(h=1.-h)*an; *ph=h* *pk;} 25 | return an; 26 | } 27 | -------------------------------------------------------------------------------- /sfunc/gaml.c: -------------------------------------------------------------------------------- 1 | /* gaml.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double gaml(double x) 10 | { double g,h; 11 | for(g=1.; x<30. ;g*=x,x+=1.); h=x*x; 12 | g=(x-.5)*log(x)-x+.918938533204672-log(g); 13 | g+=(1.-(1./6.-(1./3.-1./(4.*h))/(7.*h))/(5.*h))/(12.*x); 14 | return g; 15 | } 16 | -------------------------------------------------------------------------------- /sfunc/gsng.c: -------------------------------------------------------------------------------- 1 | /* gsng.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double gsng(double *pa,double *pb,double *pc,double b,double an) 10 | { double r,s,t,u; 11 | r= *pa- *pb; u=b* *pc; s=1.-u; t=b*b-u; 12 | *pc= *pa; *pa= *pb+r/s; *pb= *pc+r*u/t; 13 | *pc=(t/=s)/b; t=sqrt(-u*t); r*=(-u/(2.*s*t)); 14 | s=sin(an); u=(1.-b*b)*s*s; t*=tan(an)/sqrt(1.-u); 15 | if(fabs(1.-t)<1.e-15) return HUGE_VAL; 16 | return r*log(fabs((1.+t)/(1.-t))); 17 | } 18 | -------------------------------------------------------------------------------- /sfunc/gsng2.c: -------------------------------------------------------------------------------- 1 | /* gsng2.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static double ze=1.e-15; 10 | double gsng2(double *pa,double *pb,double *pc,double b, 11 | double an,double bn) 12 | { double r,s,t,ta,tb,u; 13 | r= *pa- *pb; u=b* *pc; s=1.-u; t=b*b-u; 14 | *pc= *pa; *pa= *pb+r/s; *pb= *pc+r*u/t; 15 | *pc=(t/=s)/b; t=sqrt(-u*t); r*=(-u/(2.*s*t)); 16 | u=1.-b*b; 17 | s=sin(bn); tb=t*tan(bn)/sqrt(1.-u*s*s); 18 | s=sin(an); ta=t*tan(an)/sqrt(1.-u*s*s); 19 | if(fabs(1.-ta) 9 | double ibes(double v,double x) 10 | { double y,s,t,tp,gaml(double w); int p,m; 11 | y=x-9.; if(y>0.) y*=y; tp=v*v*.2+25.; 12 | if(y0.) s=t=exp(v*log(x)-gaml(v+1.)); 14 | else{ if(v>0.) return 0.; else if(v==0.) return 1.;} 15 | for(p=1,x*=x;;++p){ t*=x/(p*(v+=1.)); s+=t; 16 | if(p>m && t<1.e-13*s) break; 17 | } 18 | } 19 | else{ double u,a0=1.57079632679490; 20 | s=t=1./sqrt(x*a0); x*=2.; u=0.; 21 | for(p=1,y=.5; (tp=fabs(t))>1.e-14 ;++p,y+=1.){ 22 | t*=(v+y)*(v-y)/(p*x); if(y>v && fabs(t)>=tp) break; 23 | if(!(p&1)) s+=t; else u-=t; 24 | } 25 | x/=2.; s=cosh(x)*s+sinh(x)*u; 26 | } 27 | return s; 28 | } 29 | -------------------------------------------------------------------------------- /sfunc/jbes.c: -------------------------------------------------------------------------------- 1 | /* jbes.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double jbes(double v,double x) 10 | { double y,s,t,tp,gaml(double z); int p,m; 11 | y=x-8.5; if(y>0.) y*=y; tp=v*v/4.+13.69; 12 | if(y0.) s=t=exp(v*log(x)-gaml(v+1.)); 14 | else{ if(v>0.) return 0.; else if(v==0.) return 1.;} 15 | for(p=1,x*= -x;;++p){ t*=x/(p*(v+=1.)); s+=t; 16 | if(p>m && fabs(t)<1.e-13) break; 17 | } 18 | } 19 | else{ double u,a0=1.57079632679490; 20 | s=t=1./sqrt(x*a0); x*=2.; u=0.; 21 | for(p=1,y=.5; (tp=fabs(t))>1.e-14 ;++p,y+=1.){ 22 | t*=(v+y)*(v-y)/(p*x); if(y>v && fabs(t)>=tp) break; 23 | if(!(p&1)){ t= -t; s+=t;} else u-=t; 24 | } 25 | y=x/2.-(v+.5)*a0; s=cos(y)*s+sin(y)*u; 26 | } 27 | return s; 28 | } 29 | -------------------------------------------------------------------------------- /sfunc/jspbes.c: -------------------------------------------------------------------------------- 1 | /* jspbes.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double jspbes(int n,double x) 10 | { double y,s,t,v,u,a0=1.57079632679490; 11 | double gaml(double a); int p,m; 12 | if(x==0.){ if(n==0) return 1.; else return 0.;} 13 | v=n+.5; y=1.+.68*n; 14 | if(xm && fabs(t)<1.e-13*fabs(s)) break; } 19 | } 20 | else{ s=t=1./x; x*=2.; u=0.; 21 | for(p=1,y=.5; y 9 | double kspbes(int n,double x) 10 | { double y,s,t,v; int p; 11 | if(x==0.) return HUGE_VAL; 12 | s=t=exp(-x)/x; x*=2.; v=n+.5; 13 | for(p=1,y=.5; y 9 | double nome(double k,double *pk,double *pkp) 10 | { double a,b,s,r,pi2=1.57079632679490; 11 | a=s=1.; b=sqrt(1.-k*k); 12 | while(a-b>4.e-15 || s-k>4.e-15){ 13 | r=a+b; b=sqrt(a*b); a=r/2.; 14 | r=s+k; k=sqrt(s*k); s=r/2.; 15 | } 16 | *pk=pi2/a; a*=(*pkp=pi2/s); 17 | return exp(-2.*a); 18 | } 19 | -------------------------------------------------------------------------------- /sfunc/psi.c: -------------------------------------------------------------------------------- 1 | /* psi.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double psi(int m) 9 | { double s= -.577215664901533; int k; 10 | for(k=1; k 9 | static double q,qq,kf; 10 | double theta(double u,int n) 11 | { double c,s,c0,s0,f,r,z; 12 | u*=kf; c0=cos(2.*u); s0=sin(2.*u); 13 | switch(n){ 14 | case 0: 15 | case 3: f=1.; r=2.*q; z=q; 16 | c=c0; s=s0; break; 17 | case 1: 18 | case 2: f=0.; r=2.*pow(q,.25); z=1.; 19 | c=cos(u); s=sin(u); 20 | } 21 | if(n==0){ r= -r; z= -z;} if(n==1) z= -z; 22 | while(fabs(r)>1.e-16){ 23 | if(n==1) f+=r*s; else f+=r*c; 24 | u=c*c0-s*s0; s=s*c0+c*s0; c=u; 25 | z*=qq; r*=z; 26 | } 27 | return f; 28 | } 29 | void stheta(double k) 30 | { double nome(double k,double *pk,double *pkp); 31 | double pi2=1.57079632679490; 32 | q=nome(k,&kf,&qq); qq=q*q; kf=pi2/kf; 33 | } 34 | -------------------------------------------------------------------------------- /sfunc/yspbes.c: -------------------------------------------------------------------------------- 1 | /* yspbes.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double yspbes(int n,double x) 10 | { double v,y,s,t,u,a0=1.57079632679490; int p; 11 | v=n+.5; if(x==0.) return HUGE_VAL; 12 | s=t=1./x; x*=2.; u=0.; 13 | for(p=1,y=.5; y 9 | double *autcor(double *x,int n,int lag) 10 | { double *p,*q,*pmax,*cf; int j; 11 | cf=(double *)calloc(lag+1,sizeof(double)); 12 | for(p=x,pmax=x+n; p=x ;) *(cf+j++)+= *p* *q--; 14 | for(j=1; j<=lag ;) *(cf+j++)/= *cf; 15 | return cf; 16 | } 17 | -------------------------------------------------------------------------------- /simu/bran.c: -------------------------------------------------------------------------------- 1 | /* bran.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static unsigned int s,h,sbuf[256]; 9 | static unsigned int a=1664525U,c=4098479U; 10 | static unsigned int r=0xffff; 11 | int bran(int n) 12 | { register int i,j; 13 | i=(int)(s>>24); s=sbuf[i]; 14 | h=h*a+c; sbuf[i]=h; 15 | i=n*(s>>16); j=n*(s&r); i+=(j>>16); 16 | return (i>>16); 17 | } 18 | void setbran(unsigned int sa) 19 | { int c; 20 | for(h=sa,c=0; c<=256 ;++c){ 21 | h=h*a+c; 22 | if(c<256) sbuf[c]=h; else s=h; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /simu/bran2.c: -------------------------------------------------------------------------------- 1 | /* bran2.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static unsigned int s,h,sbuf[256]; 9 | static unsigned int a=69069U,c=4098479U; 10 | static unsigned int r=0xffff; 11 | unsigned int lrana(unsigned int); 12 | int bran2(int n) 13 | { register int i,j,k; 14 | unsigned int u; 15 | s=lrana(s); h=h*a+c; k=(h>>24); 16 | u=sbuf[k]; sbuf[k]=s; 17 | i=n*(u>>16); j=n*(u&r); i+=(j>>16); 18 | return (i>>15); 19 | } 20 | void setbran2(unsigned int sa) 21 | { int k; 22 | for(s=sa,k=0; k<=256 ;++k){ 23 | s=lrana(s); 24 | if(k<256) sbuf[k]=s; else h=s; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /simu/hist.c: -------------------------------------------------------------------------------- 1 | /* hist.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int *hist(double *x,int n,double xmin,double xmax,int kbin,double *bin) 10 | { int k,*p; double *pm,u; 11 | p=(int *)calloc(kbin+2,sizeof(int)); ++p; 12 | *bin=(xmax-xmin)/kbin; 13 | for(pm=x+n; x xmax) k=kbin; 15 | else if ((u=(*x-xmin))<0.) k= -1; 16 | else k=u / *bin; 17 | *(p+k)+=1; 18 | } 19 | return p; 20 | } 21 | -------------------------------------------------------------------------------- /simu/lran1.c: -------------------------------------------------------------------------------- 1 | /* lran1.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static unsigned int s,h,sbuf[256]; 9 | static unsigned int a=1664525U,c=244045795; 10 | unsigned int lran1() 11 | { register int i; 12 | i=(int)(s>>24); s=sbuf[i]; 13 | h=h*a+c; sbuf[i]=h; 14 | return s; 15 | } 16 | void setlran1(unsigned int sa) 17 | { int k; 18 | for(h=sa,k=0; k<=256 ;++k){ 19 | h=h*a+c; 20 | if(k<256) sbuf[k]=h; else s=h; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /simu/lrana.s: -------------------------------------------------------------------------------- 1 | .data 2 | .align 4 3 | .type m,@object 4 | .size m,4 5 | m: 6 | .long 16807 7 | .text 8 | .align 16 9 | .globl lrana 10 | .type lrana,@function 11 | lrana: 12 | movl 4(%esp),%eax 13 | movl m,%ecx 14 | mull %ecx 15 | shldl $1,%eax,%edx 16 | btrl $31,%eax 17 | addl %edx,%eax 18 | btl $31,%eax 19 | jnc .A 20 | addl $1,%eax 21 | btrl $31,%eax 22 | .A: 23 | ret 24 | -------------------------------------------------------------------------------- /simu/lranb.s: -------------------------------------------------------------------------------- 1 | .data 2 | .align 4 3 | .type m,@object 4 | .size m,4 5 | m: 6 | .long 48271 7 | .text 8 | .align 16 9 | .globl lranb 10 | .type lranb,@function 11 | lranb: 12 | movl 4(%esp),%eax 13 | movl m,%ecx 14 | mull %ecx 15 | shldl $1,%eax,%edx 16 | btrl $31,%eax 17 | addl %edx,%eax 18 | btl $31,%eax 19 | jnc .A 20 | addl $1,%eax 21 | btrl $31,%eax 22 | .A: 23 | ret 24 | -------------------------------------------------------------------------------- /simu/lrand.c: -------------------------------------------------------------------------------- 1 | /* lrand.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static unsigned int s; 9 | unsigned int lrana(unsigned int); 10 | unsigned int lrand() 11 | { return (s=lrana(s)); 12 | } 13 | void setlrand(unsigned int u) 14 | { s=u; 15 | } 16 | -------------------------------------------------------------------------------- /simu/norm.c: -------------------------------------------------------------------------------- 1 | /* norm.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static unsigned int s,h,sbuf[256]; 10 | static unsigned int a=69069,c=244045795; 11 | static double g=4.6566128730773925e-10; 12 | void norm(double *err) 13 | { double x,y,r; 14 | register int i; 15 | do{ i=(s>>24); s=sbuf[i]; 16 | h=h*a+c; sbuf[i]=h; x=s*g-1.; 17 | i=(s>>24); s=sbuf[i]; 18 | h=h*a+c; sbuf[i]=h; y=s*g-1.; 19 | r=x*x+y*y; 20 | } while(r>=1.); 21 | r=sqrt(-2.*log(r)/r); 22 | err[0]=x*r; err[1]=y*r; 23 | } 24 | void setnorm(unsigned int sa) 25 | { int k; 26 | for(h=sa,k=0; k<=256 ;++k){ 27 | h=h*a+c; 28 | if(k<256) sbuf[k]=h; else s=h; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /simu/norm2.c: -------------------------------------------------------------------------------- 1 | /* norm2.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static unsigned int s,h,ss[256]; 10 | static unsigned int a=1664525U,c=244045795U; 11 | static double rc=9.313225750491594e-10; 12 | unsigned int lranb(unsigned int); 13 | void norm2(double *err) 14 | { double x,y,r; 15 | register int i; 16 | do{ s=lranb(s); h=h*a+c; i=(h>>24); 17 | x=rc*ss[i]-1.; ss[i]=s; 18 | s=lranb(s); h=h*a+c; i=(h>>24); 19 | y=rc*ss[i]-1.; ss[i]=s; 20 | r=x*x+y*y; 21 | } while(r>=1.); 22 | r=sqrt(-2.*log(r)/r); 23 | err[0]=x*r; err[1]=y*r; 24 | } 25 | void setnorm2(unsigned int sa) 26 | { int k; 27 | for(s=sa,k=0; k<=256 ;++k){ 28 | s=lranb(s); 29 | if(k<256) ss[k]=s; else h=s; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /simu/nrml.c: -------------------------------------------------------------------------------- 1 | /* nrml.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static unsigned int a=1664525U,c=907633387U; 10 | static unsigned int s,h,sbuf[256]; 11 | static int kf; 12 | static double rc=4.6566128730773926e-10,e; 13 | double nrml() 14 | { double x,y,r; int i; 15 | if(kf){ 16 | do{ i=(int)(s>>24); s=sbuf[i]; 17 | h=a*h+c; sbuf[i]=h; 18 | x=rc*s-1.; 19 | i=(int)(s>>24); s=sbuf[i]; 20 | h=a*h+c; sbuf[i]=h; 21 | y=rc*s-1.; r=x*x+y*y; 22 | } while(r>=1.); 23 | r=sqrt(-2.*log(r)/r); 24 | x*=r; e=y*r; 25 | } 26 | else x=e; 27 | kf^=1; return x; 28 | } 29 | void setnrml(unsigned int sa) 30 | { int j; 31 | for(h=sa,j=0; j<=256 ;++j){ 32 | h=a*h+c; 33 | if(j<256) sbuf[j]=h; else s=h; 34 | } 35 | kf=1; 36 | } 37 | -------------------------------------------------------------------------------- /simu/sampl.c: -------------------------------------------------------------------------------- 1 | /* sampl.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | sampl(void **s,int n,void **d,int m) 9 | { int k; 10 | for(k=0; k0 ;){ 11 | i=bran(j--); 12 | t=s[i]; s[i]=s[j]; s[j]=t; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /simu/supp/README: -------------------------------------------------------------------------------- 1 | The functions 'lrana,c' and 'lranb.c' are c-code versions of 2 | congruential generators that perform arithmetic modulo the 3 | prime number 2^31 -1. The assembly code '.s' source modules 4 | in the 'simu' directory should be replaced by this C code 5 | when the installation target is a non-Intel platform. 6 | 7 | The '.asm' modules are an alternative for 80x86 platforms 8 | that can be assembled with the 'nasm' assembler. This 9 | assembler employs an Intel type code format, rather than 10 | the odd AT&T format employed by GNU C.\ 11 | -------------------------------------------------------------------------------- /simu/supp/lrana.asm: -------------------------------------------------------------------------------- 1 | ;; unsigned long lrana(unsigned long s) 2 | ;; generation employs a congruential method mod 2^31-1 3 | 4 | [global lrana] 5 | 6 | [section .data] 7 | mm dd 16807 8 | 9 | [section .text] 10 | 11 | lrana 12 | mov eax,dword [esp+4] 13 | mul dword [mm] 14 | shld edx,eax,1 15 | btr eax,31 16 | add eax,edx 17 | bt eax,31 18 | jnc .A 19 | add eax,1 20 | btr eax,31 21 | .A 22 | ret 23 | 24 | end 25 | -------------------------------------------------------------------------------- /simu/supp/lrana.c: -------------------------------------------------------------------------------- 1 | /* lrana.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | C version of the routine for a multiplicative 10 | generator modulo 2^31-1. 11 | */ 12 | 13 | static unsigned int m=16807U,k=0xffffU,j=0xfffeU; 14 | static unsigned int u=0x80000000U,v=0x7fffffffU; 15 | unsigned int lrana(unsigned int s) 16 | { register unsigned int z,f; 17 | z=m*(s&k); f=(s>>16)*m; f+=(z>>16); 18 | z=(z&k)+(f<<16); f=(f>>15)&j; 19 | if(z&u) f|=1L; 20 | s=f+(z&v); 21 | if(s&u) s=(s+1)&v; 22 | return s; 23 | } 24 | -------------------------------------------------------------------------------- /simu/supp/lrana.s: -------------------------------------------------------------------------------- 1 | .data 2 | .align 4 3 | .type m,@object 4 | .size m,4 5 | m: 6 | .long 16807 7 | .text 8 | .align 16 9 | .globl lrana 10 | .type lrana,@function 11 | lrana: 12 | movl 4(%esp),%eax 13 | movl m,%ecx 14 | mull %ecx 15 | shldl $1,%eax,%edx 16 | btrl $31,%eax 17 | addl %edx,%eax 18 | btl $31,%eax 19 | jnc .A 20 | addl $1,%eax 21 | btrl $31,%eax 22 | .A: 23 | ret 24 | -------------------------------------------------------------------------------- /simu/supp/lranb.asm: -------------------------------------------------------------------------------- 1 | ;; unsigned long lranb(unsigned long s) 2 | ;; generation employs a congruential method mod 2^31-1 3 | 4 | [global lranb] 5 | 6 | [section .data] 7 | mm dd 48271 8 | 9 | [section .text] 10 | 11 | lranb 12 | mov eax,dword [esp+4] 13 | mul dword [mm] 14 | shld edx,eax,1 15 | btr eax,31 16 | add eax,edx 17 | bt eax,31 18 | jnc .A 19 | add eax,1 20 | btr eax,31 21 | .A 22 | ret 23 | 24 | end 25 | -------------------------------------------------------------------------------- /simu/supp/lranb.c: -------------------------------------------------------------------------------- 1 | /* lranb.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | C version of the routine for a multiplicative 10 | generator modulo 2^31-1. 11 | */ 12 | 13 | static unsigned int m=48271U,k=0xffffU,j=0xfffeU; 14 | static unsigned int u=0x80000000U,v=0x7fffffffU; 15 | unsigned int lranb(unsigned int s) 16 | { register unsigned int z,f; 17 | z=m*(s&k); f=(s>>16)*m; f+=(z>>16); 18 | z=(z&k)+(f<<16); f=(f>>15)&j; 19 | if(z&u) f|=1L; 20 | s=f+(z&v); 21 | if(s&u) s=(s+1)&v; 22 | return s; 23 | } 24 | -------------------------------------------------------------------------------- /simu/supp/lranb.s: -------------------------------------------------------------------------------- 1 | .data 2 | .align 4 3 | .type m,@object 4 | .size m,4 5 | m: 6 | .long 48271 7 | .text 8 | .align 16 9 | .globl lranb 10 | .type lranb,@function 11 | lranb: 12 | movl 4(%esp),%eax 13 | movl m,%ecx 14 | mull %ecx 15 | shldl $1,%eax,%edx 16 | btrl $31,%eax 17 | addl %edx,%eax 18 | btl $31,%eax 19 | jnc .A 20 | addl $1,%eax 21 | btrl $31,%eax 22 | .A: 23 | ret 24 | -------------------------------------------------------------------------------- /simu/test/timing/timbran.c: -------------------------------------------------------------------------------- 1 | /* timbran.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n,m,k; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; m=256; 17 | setbran(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n,m,k; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; m=256; 17 | setbran2(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setlran1(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setlrand(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; double err[2]; 12 | int i,n; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setnorm(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; double err[2]; 12 | int i,n; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setnorm2(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; double e; 12 | int i,n; clock_t st,en; 13 | double dt,tms; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setnrml(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n; clock_t st,en; 13 | double dt,tms,h; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setunfl(s); 18 | st=clock(); 19 | for(i=0; i 9 | #include "ccmath.h" 10 | void main(int na,char **av) 11 | { unsigned int s; 12 | int i,n; clock_t st,en; 13 | double dt,tms,h; 14 | if(na!=2){ printf("para: count\n"); exit(1);} 15 | n=atoi(*++av); 16 | s=0x5a7d3b28; 17 | setunfl2(s); 18 | st=clock(); 19 | for(i=0; i>24); s=sbuf[i]; 13 | h=a*h+c; sbuf[i]=h; 14 | return s*2.328306436538696e-10; 15 | } 16 | void setunfl(unsigned int k) 17 | { int j; 18 | for(h=k,j=0; j<=256 ;++j){ 19 | h=a*h+c; 20 | if(j<256) sbuf[j]=h; else s=h; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /simu/unfl2.c: -------------------------------------------------------------------------------- 1 | /* unfl2.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | static unsigned int s,h,ss[256]; 9 | unsigned int lranb(unsigned int); 10 | double unfl2() 11 | { register int i; unsigned int c; 12 | s=lranb(s); 13 | h=h*69069U+4098479U; 14 | i=(h>>24); c=ss[i]; ss[i]=s; 15 | return (double)c*4.656612875245797e-10; 16 | } 17 | void setunfl2(unsigned int sa) 18 | { int k; 19 | for(s=sa,k=0; k<=256 ;++k){ 20 | s=lranb(s); 21 | if(k<256) ss[k]=s; else h=s; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sort/btdel.c: -------------------------------------------------------------------------------- 1 | /* btdel.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "tree.h" 9 | int btdel(char *kin,struct tnode *hd) 10 | { struct tnode *r,*s,**f; int ef; 11 | while(hd!=NULL){ 12 | if((ef=strcmp(kin,hd->key))==0) break; 13 | else if(ef<0) f= &(hd->pl); else f= &(hd->pr); 14 | hd= *f; 15 | } 16 | if(hd==NULL) return 0; 17 | if(hd->pr==NULL) *f=hd->pl; 18 | else if(hd->pl==NULL) *f=hd->pr; 19 | else if((r=hd->pr)->pl==NULL){ r->pl=hd->pl; *f=r;} 20 | else{ for(s=r->pl; s->pl!=NULL ;){ r=s; s=r->pl;} 21 | s->pl=hd->pl; r->pl=s->pr; s->pr=hd->pr; *f=s; 22 | } 23 | free(hd); return 1; 24 | } 25 | -------------------------------------------------------------------------------- /sort/btins.c: -------------------------------------------------------------------------------- 1 | /* btins.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "tree.h" 9 | #include 10 | struct tnode *btins(char *kin,struct tnode *hd) 11 | { struct tnode **v; int ef; 12 | while(hd!=NULL){ 13 | if((ef=strcmp(kin,hd->key))==0) return hd; 14 | else if(ef<0) v= &(hd->pl); else v= &(hd->pr); 15 | hd= *v; 16 | } 17 | hd= *v=(struct tnode *)malloc(sizeof(*hd)); 18 | hd->key=kin; hd->pr=hd->pl=NULL; 19 | return hd; 20 | } 21 | -------------------------------------------------------------------------------- /sort/btsearch.c: -------------------------------------------------------------------------------- 1 | /* btsearch.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define BAL 1 9 | #include "tree.h" 10 | struct tnode *btsearch(char *kin,struct tnode *hd) 11 | { int ef; 12 | while(hd!=NULL){ 13 | if((ef=strcmp(kin,hd->key))==0) return hd; 14 | if(ef<0) hd=hd->pl; else hd=hd->pr; 15 | } 16 | return hd; 17 | } 18 | -------------------------------------------------------------------------------- /sort/btsort.c: -------------------------------------------------------------------------------- 1 | /* btsort.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define BAL 1 9 | #include "tree.h" 10 | static int k; 11 | void btsort(struct tnode *hd,struct tnode **ar) 12 | { if(hd!=NULL){ 13 | btsort(hd->pl,ar); 14 | ar[k++]=hd; 15 | btsort(hd->pr,ar); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sort/hash.h: -------------------------------------------------------------------------------- 1 | /* hash.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef NULL 9 | #define NULL ((void *)0) 10 | #endif 11 | struct tabl {char *key,*val; struct tabl *pt;}; 12 | int hval(char *k,int m); 13 | -------------------------------------------------------------------------------- /sort/hashdel.c: -------------------------------------------------------------------------------- 1 | /* hashdel.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "hash.h" 9 | int hashdel(char *kin,struct tabl **harr,int mh) 10 | { int hv,m; struct tabl *pe,*ps; 11 | hv=hval(kin,mh); pe=harr[hv]; ps=NULL; 12 | while(pe!=NULL){ 13 | if((m=strcmp(kin,pe->key))==0) break; 14 | if(m<0) return 0; 15 | ps=pe; pe=pe->pt; 16 | } 17 | if(pe==NULL) return 0; 18 | if(ps!=NULL) ps->pt=pe->pt; else harr[hv]=pe->pt; 19 | free(pe); return 1; 20 | } 21 | -------------------------------------------------------------------------------- /sort/hashins.c: -------------------------------------------------------------------------------- 1 | /* hashins.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "hash.h" 9 | #include 10 | struct tabl *hashins(char *kin,struct tabl **harr,int mh) 11 | { int hv,m; struct tabl *pe,*ps,*pc; 12 | hv=hval(kin,mh); pe=harr[hv]; ps=NULL; 13 | while(pe!=NULL){ 14 | if((m=strcmp(kin,pe->key))==0) return pe; 15 | if(m<0) break; ps=pe; pe=pe->pt; 16 | } 17 | pc=(struct tabl *)malloc(sizeof(*pe)); 18 | pc->key=kin; pc->pt=pe; 19 | if(ps==NULL) harr[hv]=pc; else ps->pt=pc; 20 | return pc; 21 | } 22 | -------------------------------------------------------------------------------- /sort/hfind.c: -------------------------------------------------------------------------------- 1 | /* hfind.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "hash.h" 9 | struct tabl *hfind(char *kin,struct tabl **harr,int mh) 10 | { int hv,m; struct tabl *pe; 11 | hv=hval(kin,mh); pe=harr[hv]; 12 | while(pe!=NULL){ 13 | if((m=strcmp(kin,pe->key))==0) return pe; 14 | if(m<0) return NULL; pe=pe->pt; 15 | } 16 | return NULL; 17 | } 18 | -------------------------------------------------------------------------------- /sort/hsort.c: -------------------------------------------------------------------------------- 1 | /* hsort.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define Swap(x,y) (tmp=(x),(x)=(y),(y)=tmp) 9 | static void rheap(void **v,int k,int n,int (*comp)()); 10 | void hsort(void **v,int n,int (*comp)()) 11 | { int k; char *tmp; 12 | for(k=n/2-1; k>=0 ;) rheap(v,k--,n,comp); 13 | for(--n; n>0 ;){ Swap(v[0],v[n]); rheap(v,0,n--,comp);} 14 | } 15 | static void rheap(void **v,int k,int n,int (*comp)()) 16 | { int m=n-1,j; char *tmp; 17 | for(j=2*k+1; j0) ++j; 19 | if((*comp)(v[j],v[k])>0) Swap(v[k],v[j]); 20 | else break; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sort/hval.c: -------------------------------------------------------------------------------- 1 | /* hval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | int hval(char *key,int mh) 9 | { int hv; 10 | for(hv=0; *key!='\0' ;) hv+= *key++; 11 | return hv%mh; 12 | } 13 | -------------------------------------------------------------------------------- /sort/merge.h: -------------------------------------------------------------------------------- 1 | /* merge.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef NULL 9 | #define NULL 0L 10 | #endif 11 | struct llst {char *pls; struct llst *pt;}; 12 | -------------------------------------------------------------------------------- /sort/msort.c: -------------------------------------------------------------------------------- 1 | /* msort.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "merge.h" 9 | static struct llst *merge(struct llst *a,struct llst *b,int (*comp)()); 10 | struct llst *msort(struct llst *st,int dim,int (*comp)()) 11 | { struct llst *a,*b; int i,m=dim/2; 12 | if(st->pt==NULL) return st; 13 | a=st; for(i=1; ipt); 14 | b=st->pt; st->pt=NULL; 15 | return merge(msort(a,m,comp),msort(b,dim-m,comp),comp); 16 | } 17 | static struct llst *merge(struct llst *a,struct llst *b,int (*comp)()) 18 | { struct llst *t,hd; 19 | if(b==NULL) return a; t= &hd; 20 | while(1){ 21 | if((*comp)(a->pls,b->pls)<=0){ 22 | t->pt=a; t=a; if((a=a->pt)==NULL){ t->pt=b; break;} } 23 | else{ t->pt=b; t=b; if((b=b->pt)==NULL){ t->pt=a; break;} } 24 | } 25 | return hd.pt; 26 | } 27 | -------------------------------------------------------------------------------- /sort/numcmp.c: -------------------------------------------------------------------------------- 1 | /* numcmp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | int dubcmp(double *x,double *y) 9 | { if(*x > *y) return 1; 10 | if(*x < *y) return -1; 11 | return 0; 12 | } 13 | int intcmp(int *x,int *y) 14 | { if(*x > *y) return 1; 15 | if(*x < *y) return -1; 16 | return 0; 17 | } 18 | int unicmp(unsigned *x,unsigned *y) 19 | { if(*x > *y) return 1; 20 | if(*x < *y) return -1; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /sort/prbtree.c: -------------------------------------------------------------------------------- 1 | /* prbtree.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define BAL 1 9 | #include "tree.h" 10 | static struct tnode *pspb[129]; 11 | static char pstrb[131]; 12 | int puts(char *s); 13 | void prbtree(struct tnode *hd,int m) 14 | { int n=2,i,k,ks; 15 | for(n<<=m,i=0; i<=n ;) pspb[i++]=NULL; 16 | ks=n/2+1; pspb[ks]=hd; pstrb[n+1]='\n'; pstrb[n+2]='\0'; 17 | for(k=ks/2,m=n; m>1 ;m/=2,k/=2){ 18 | for(i=0; i<=n ;) pstrb[i++]=' '; 19 | for(i=ks; i<=n ;i+=m){ 20 | if(pspb[i]!=NULL){ pstrb[i]= *(pspb[i]->key); 21 | if(k){ pspb[i-k]=pspb[i]->pl; pspb[i+k]=pspb[i]->pr;} 22 | } 23 | } 24 | puts(pstrb); ks-=k; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sort/prtree.c: -------------------------------------------------------------------------------- 1 | /* prtree.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "tree.h" 9 | static struct tnode *psp[129]; 10 | static char pstr[131]; 11 | int puts(char *c); 12 | void prtree(struct tnode *hd,int m) 13 | { int n=2,i,k,ks; 14 | for(n<<=m,i=0; i<=n ;) psp[i++]=NULL; 15 | ks=n/2+1; psp[ks]=hd; pstr[n+1]='\n'; pstr[n+2]='\0'; 16 | for(k=ks/2,m=n; m>1 ;m/=2,k/=2){ 17 | for(i=0; i<=n ;) pstr[i++]=' '; 18 | for(i=ks; i<=n ;i+=m){ 19 | if(psp[i]!=NULL){ pstr[i]= *(psp[i]->key); 20 | if(k){ psp[i-k]=psp[i]->pl; psp[i+k]=psp[i]->pr;} 21 | } 22 | } 23 | puts(pstr); ks-=k; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sort/qsrt.c: -------------------------------------------------------------------------------- 1 | /* qsrt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define Swap(x,y) (tmp=(x),(x)=(y),(y)=tmp) 9 | void qsrt(void **v,int i,int j,int (*comp)()) 10 | { int up=j,lw=i; char *tmp,*pa; 11 | if(i>=j) return; 12 | --i; pa=v[up]; 13 | while(ii && (*comp)(v[j],pa)>0 ;--j); 16 | if(iup-i){ qsrt(v,i+1,up,comp); qsrt(v,lw,i-1,comp);} 20 | else{ qsrt(v,lw,i-1,comp); qsrt(v,i+1,up,comp);} 21 | } 22 | -------------------------------------------------------------------------------- /sort/ssort.c: -------------------------------------------------------------------------------- 1 | /* ssort.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | void ssort(void **v,int n,int (*comp)()) 9 | { int gap,i,j; char *tem; 10 | for(gap=1; gap<=n ; gap=3*gap+1); 11 | for(gap/=3; gap>0 ;gap/=3){ 12 | for(i=gap; i=0 && (*comp)(v[j],tem)>0 ;j-=gap) 14 | v[j+gap]=v[j]; 15 | v[j+gap]=tem; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sort/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'sort' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. Input data files, if any 4 | are named in the test code header, are in the 'data' sub-directory. 5 | 6 | The following list specifies the input for standard tests, whose 7 | output is appended to the test source code as a comment. 8 | 9 | tbatree data/ttree.dat 10 | tbtree data/ttree.dat 11 | tbtree0 data/ttree.dat 12 | thash data/hash.dat 13 | thsort 25 14 | tmsort 25 15 | tqsrt 25 16 | tssort 25 17 | -------------------------------------------------------------------------------- /sort/test/data/hash.dat: -------------------------------------------------------------------------------- 1 | ab 15 cat -7 dmm 13 fc 99 gh 23 fik 123 mss 37 pff -22 2 | -------------------------------------------------------------------------------- /sort/test/data/ttree.dat: -------------------------------------------------------------------------------- 1 | X T B F K M Q A C B H Z P J E R I D M S G U L U O Y P V 2 | -------------------------------------------------------------------------------- /sort/tree.h: -------------------------------------------------------------------------------- 1 | /* tree.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef NULL 9 | #define NULL 0L 10 | #endif 11 | #ifdef BAL 12 | struct tnode {char *key,*rec; int bal; struct tnode *pr,*pl;}; 13 | #else 14 | struct tnode {char *key,*rec; struct tnode *pr,*pl;}; 15 | #endif 16 | -------------------------------------------------------------------------------- /sort/tsearch.c: -------------------------------------------------------------------------------- 1 | /* tsearch.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "tree.h" 9 | struct tnode *tsearch(char *kin,struct tnode *hd) 10 | { int ef; 11 | while(hd!=NULL){ 12 | if((ef=strcmp(kin,hd->key))==0) return hd; 13 | if(ef<0) hd=hd->pl; else hd=hd->pr; 14 | } 15 | return hd; 16 | } 17 | -------------------------------------------------------------------------------- /sort/tsort.c: -------------------------------------------------------------------------------- 1 | /* tsort.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "tree.h" 9 | static int k; 10 | void tsort(struct tnode *hd,struct tnode **ar) 11 | { if(hd!=NULL){ 12 | tsort(hd->pl,ar); 13 | ar[k++]=hd; 14 | tsort(hd->pr,ar); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /statf/gaml.c: -------------------------------------------------------------------------------- 1 | /* gaml.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double gaml(x) 10 | double x; 11 | { double g,h; 12 | for(g=1.; x<30. ;g*=x,x+=1.); h=x*x; 13 | g=(x-.5)*log(x)-x+.918938533204672-log(g); 14 | g+=(1.-(1./6.-(1./3.-1./(4.*h))/(7.*h))/(5.*h))/(12.*x); 15 | return g; 16 | } 17 | -------------------------------------------------------------------------------- /statf/pctbn.c: -------------------------------------------------------------------------------- 1 | /* pctbn.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static double te=1.e-9,tb=1.e-12; 10 | double pctbn(double pc,double a,double b,double d) 11 | { double x,y,t,df,dx; int k; 12 | double qbnc(double,double,double,double),pctb(double,double,double); 13 | if(pc1.-te) return -1.; 14 | dx=df=b+d; df*=(dx/=b+2.*d); 15 | y=pctb(pc,a,df); x=y/(y+(1.-y)/dx); 16 | if((y=x+1.e-4)>1.) y=1.-te; 17 | t=qbnc(y,a,b,d); dx=x-y; k=0; 18 | do{ df=qbnc(x,a,b,d)-t; t+=df; 19 | y=pc-t; dx*=y/df; x+=dx; ++k; 20 | if(x<=0.) x=tb; else if(x>=1.) x=1.-tb; 21 | }while(fabs(y)>te && k<200); 22 | if(k>=200) return -1.; else return x; 23 | } 24 | -------------------------------------------------------------------------------- /statf/pctg.c: -------------------------------------------------------------------------------- 1 | /* pctg.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static double te=1.e-9; 10 | double pctg(double pc,double a) 11 | { double x,y,s,t; int k; 12 | double qgama(double,double),gaml(double),pctn(double); 13 | if(pc1.-te) return -1.; 14 | if(a<.5){ 15 | x=exp((gaml(a+1.)+log(1.-pc))/a); 16 | if(x==0.) return -1.; 17 | } 18 | else{ 19 | y=pctn(pc); s=1./(9.*a); 20 | s=pow(1.-s+y*sqrt(s),3.); x=a*s; 21 | if(xte && k<200); 27 | if(k>=200) return -1.; else return x; 28 | } 29 | -------------------------------------------------------------------------------- /statf/pctgn.c: -------------------------------------------------------------------------------- 1 | /* pctgn.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | static double te=1.e-9,tb=1.e-32; 10 | double pctgn(double pc,double a,double d) 11 | { double x,y,t,df,dx; int k; 12 | double qgnc(double,double,double),pctg(double,double); 13 | if(pc1.-te) return -1.; 14 | dx=df=a+d; df*=(dx/=a+2.*d); 15 | y=pctg(pc,df); x=y/dx; dx=sqrt(a+2.*d)/4.; 16 | if((y=x-dx)<=0.) y=te; 17 | t=qgnc(y,a,d); dx=x-y; k=0; 18 | do{ df=qgnc(x,a,d)-t; t+=df; y=pc-t; ++k; 19 | dx*=y/df; x+=dx; if(x<=0.) x=tb; 20 | }while(fabs(y)>te && k<200); 21 | if(k>=200) return -1.; else return x; 22 | } 23 | -------------------------------------------------------------------------------- /statf/pctn.c: -------------------------------------------------------------------------------- 1 | /* pctn.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double pctn(double pc) 10 | { double t,z,qnorm(double),te=1.e-9; int nf; 11 | if(pc1.-te) return HUGE_VAL; 12 | if(pc>.5){ pc=1.-pc; nf=0;} else nf=1; 13 | t=sqrt(-log(pc*pc)); 14 | z=t-(2.30753+.27061*t)/(1.+(.99229+.04481*t)*t); 15 | do{ if(z>37.5) break; t=pc-qnorm(z); 16 | z-=2.506628274631*t*exp(z*z/2.); } 17 | while(fabs(t)>te); 18 | if(nf) return z; else return -z; 19 | } 20 | -------------------------------------------------------------------------------- /statf/qbeta.c: -------------------------------------------------------------------------------- 1 | /* qbeta.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double qbeta(double x,double a,double b) 10 | { double ro,t,ts,f,gaml(double); int nf; 11 | ro=gaml(a)+gaml(b)-gaml(a+b); 12 | if(x<.5) nf=1; else{ x=1.-x; t=a; a=b; b=t; nf=0;} 13 | f=t=exp(a*log(x)+b*log(1.-x)-ro)/a; 14 | for(ts=0.,b+=a-1.; t>1.e-12 || t>ts ;){ 15 | b+=1.; a+=1.; ts=t; t*=x*b/a; f+=t; } 16 | if(nf) return f; else return 1.-f; 17 | } 18 | -------------------------------------------------------------------------------- /statf/qbnc.c: -------------------------------------------------------------------------------- 1 | /* qbnc.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double qbnc(double x,double a,double b,double d) 10 | { double r,s,t,f,sp; int k; 11 | double qbeta(double,double,double),gaml(double); 12 | r=exp(-d); t=gaml(a)+gaml(b)-gaml(a+b); 13 | t=exp(a*log(x)+b*log(1.-x)-t)/b; 14 | f=s=qbeta(1.-x,b,a); a-=1.; 15 | for(k=1,sp=0.; s*r>1.e-12 || s>sp ;++k){ 16 | sp=s; s=d*(s-t)/k; f+=s; t*=d*(1.-x)*(1.+a/(b+k))/k; } 17 | return 1.-r*f; 18 | } 19 | -------------------------------------------------------------------------------- /statf/qgama.c: -------------------------------------------------------------------------------- 1 | /* qgama.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double qgama(double x,double a) 10 | { double ap,ro,f,t,gaml(double); int k; 11 | ro=a*log(x)-x-gaml(a); 12 | ap=6.25; if(a>ap) ap=a; t=(x-ap)/(f=sqrt(2.*ap)); 13 | if(x<4.5 || t< -1. || (t< -.5 && a<10.)){ 14 | for(f=t=1.,ap=a; t>1.e-14 ;){ t*=x/(ap+=1.); f+=t;} 15 | return 1.-exp(ro)*f/a; 16 | } 17 | else{ 18 | if(t<0. && a<10.) k=18; 19 | else if(t>3.){ k=ceil(19.-3.*t); if(k<4) k=4;} 20 | else k=6+ceil(f*(2.05-.8*t+.091*t*t)); 21 | for(f=x; k>0 ;){ t=k--; f=x+(t-a)/(1.+t/f);} 22 | return exp(ro)/f; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /statf/qgnc.c: -------------------------------------------------------------------------------- 1 | /* qgnc.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double qgnc(double x,double a,double d) 10 | { double r,s,t,f,sp,qgama(double,double),gaml(double); int k; 11 | r=exp(-d); t=exp(a*log(x)-x-gaml(a))/a; 12 | f=s=qgama(x,a); 13 | for(k=1,sp=0.; s*r>1.e-12 || s>sp ;++k){ 14 | sp=s; s=d*(t+s)/k; f+=s; t*=d*x/(k*(a+k)); } 15 | return r*f; 16 | } 17 | -------------------------------------------------------------------------------- /statf/qnorm.c: -------------------------------------------------------------------------------- 1 | /* qnorm.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | double qnorm(double x) 10 | { double y,ro,f,t; int k,nf; 11 | if(x<0.){ x= -x; nf=0;} else nf=1; 12 | y=x*x; ro=exp(-y/2.)/2.506628274631; 13 | if(x<3.){ f=t=1.; 14 | for(k=1; t>1.e-14 ;){ t*=y/(k+=2); f+=t;} 15 | f=.5-x*ro*f; } 16 | else{ f=x; k=ceil(250./y); if(k<3) k=3; 17 | for(; k>0 ;) f=x+(k--)/f; 18 | f=ro/f; } 19 | if(nf) return f; else return 1.-f; 20 | } 21 | -------------------------------------------------------------------------------- /statf/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'statf' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. 4 | 5 | The following list specifies the inputs used in the standard 6 | tests, whose output is appended to the test source code as a 7 | comment. 8 | 9 | tbetanc 1.5 3.2 2.0 10 | tdbeta 1.2 5.7 11 | tdgama 4.33 12 | tdnorm no input 13 | tgamanc 3.1 4.2 14 | 15 | -------------------------------------------------------------------------------- /testex: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # Perl script to extract sample test output appended as a 4 | # comment to the test source code. 5 | # syntax: testex < source.c 6 | 7 | $pp = 0; 8 | while($ln=<>){ 9 | if($ln =~ m[Test output] ){ $pp=1; } 10 | if($pp == 1){ print $ln; } 11 | } 12 | -------------------------------------------------------------------------------- /tseries/arma.h: -------------------------------------------------------------------------------- 1 | /* arma.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef NULL 9 | #define NULL ((void *)0) 10 | #endif 11 | struct mcof {double cf; int lag;}; 12 | -------------------------------------------------------------------------------- /tseries/armaf.h: -------------------------------------------------------------------------------- 1 | /* armaf.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef NULL 9 | #define NULL ((void *)0) 10 | #endif 11 | struct mcof {double cf; int lag;}; 12 | struct fmod {int fac; double val;}; 13 | 14 | -------------------------------------------------------------------------------- /tseries/parma.c: -------------------------------------------------------------------------------- 1 | /* parma.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "arma.h" 9 | extern struct mcof *par,*pma; 10 | extern int nar,nma; 11 | double parma(double *x,double *e) 12 | { struct mcof *p,*q; double y; 13 | for(y=0.,p=par,q=p+nar; pcf * *(x-(p->lag+1)); 15 | for(p=pma,q=p+nma; pcf * *(e-(p->lag+1)); 17 | *x=y; *e=0.; 18 | return y; 19 | } 20 | -------------------------------------------------------------------------------- /tseries/resid.c: -------------------------------------------------------------------------------- 1 | /* resid.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int resid(double *x,int n,int lag,double **pau,int nbin, 10 | double xa,double xb,int **phs,int *cks) 11 | { int j,m,*hist(double *,int,double,double,int,double *); 12 | double y,f,s,d,*autcor(double *,int,int),bin; 13 | *pau=autcor(x,n,lag); 14 | *phs=hist(x,n,xa,xb,nbin,&bin); 15 | n=pwspec(x,n,0); 16 | m=n/2; f=2./n; s=m-1; s=sqrt(s); 17 | xa=1.02/s; xb=1.36/s; cks[0]=cks[1]=0; 18 | for(s=y=0.,j=0; jxa){ 21 | ++cks[0]; if(d>xb) ++cks[1]; 22 | } 23 | } 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /tseries/sarma.c: -------------------------------------------------------------------------------- 1 | /* sarma.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "arma.h" 9 | #include 10 | extern struct mcof *par,*pma; 11 | extern int nar,nma; 12 | static int kst,max; static double *pz,*pm; 13 | double sarma(double er) 14 | { struct mcof *p,*q; double y; 15 | for(y=er,p=par,q=p+nar; pcf * *(pz+(kst+p->lag)%max); 17 | for(p=pma,q=p+nma; pcf * *(pm+(kst+p->lag)%max); 19 | kst=(kst+max-1)%max; *(pm+kst)=er; *(pz+kst)=y; 20 | return y; 21 | } 22 | void setsim(int k) 23 | { int m; 24 | if(k){ kst=max=m=0; 25 | if(nar) max=(par+nar-1)->lag+1; 26 | if(nma && (m=(pma+nma-1)->lag+1)>max) max=m; 27 | pz=(double *)calloc(2*max,sizeof(double)); 28 | pm=pz+max; 29 | } 30 | else free(pz); 31 | } 32 | -------------------------------------------------------------------------------- /tseries/sdiff.c: -------------------------------------------------------------------------------- 1 | /* sdiff.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #define MXD 6 9 | static double f[MXD]; 10 | double sdiff(double y,int nd,int k) 11 | { double s; 12 | if(k==0) for(k=0; k=0 ;){ 21 | s=f[k]; f[k--]+=y; y=s; } 22 | return f[0]; 23 | } 24 | -------------------------------------------------------------------------------- /tseries/test/data/tfs0.b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/tseries/test/data/tfs0.b -------------------------------------------------------------------------------- /tseries/test/data/tfs0.dat: -------------------------------------------------------------------------------- 1 | 2 2 1 0 2 | 0. 0 3 | 1. 0 4 | .8 1 5 | -.4 2 6 | -.5 1 7 | 123456789 8 | -------------------------------------------------------------------------------- /tseries/test/data/tfs1.dat: -------------------------------------------------------------------------------- 1 | 2 1 0 0 2 | 0. 0 3 | 1. 0 4 | .9 1 5 | 123456789 6 | -------------------------------------------------------------------------------- /tseries/test/data/tfs2.dat: -------------------------------------------------------------------------------- 1 | 2 0 1 1 2 | 0. 0 3 | -1. 0 4 | -.7 1 5 | 132465798 6 | -------------------------------------------------------------------------------- /tseries/test/data/tfs3.dat: -------------------------------------------------------------------------------- 1 | 3 1 1 0 2 | -1. 0 3 | 0. 0 4 | 1. 0 5 | .7 1 6 | .4 2 7 | 3173265123 8 | -------------------------------------------------------------------------------- /tseries/test/data/tfs4.dat: -------------------------------------------------------------------------------- 1 | 3 1 1 1 2 | -1. 0 3 | 0. 0 4 | 1. 0 5 | .7 1 6 | .4 2 7 | 3173265123 8 | -------------------------------------------------------------------------------- /tseries/test/data/tfs5.dat: -------------------------------------------------------------------------------- 1 | 3 3 1 0 2 | 0. 0 3 | 1. 0 4 | -1. 0 5 | 1.2 1 6 | -.6 2 7 | .3 3 8 | -.8 1 9 | 123456789 10 | -------------------------------------------------------------------------------- /tseries/test/data/ts0.b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/tseries/test/data/ts0.b -------------------------------------------------------------------------------- /tseries/test/data/ts0.dat: -------------------------------------------------------------------------------- 1 | 2 1 2 | .8 1 3 | -.6 2 4 | .3 1 5 | 123456789 6 | -------------------------------------------------------------------------------- /tseries/test/data/ts0.er: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/tseries/test/data/ts0.er -------------------------------------------------------------------------------- /tseries/test/data/ts1.dat: -------------------------------------------------------------------------------- 1 | 2 1 2 | .6 1 3 | -.2 2 4 | -.5 1 5 | 123456789 6 | -------------------------------------------------------------------------------- /tseries/test/data/ts2.dat: -------------------------------------------------------------------------------- 1 | 1 1 2 | .8 1 3 | .4 1 4 | 2137714571 5 | -------------------------------------------------------------------------------- /tseries/test/data/ts3.dat: -------------------------------------------------------------------------------- 1 | 1 0 2 | .9 1 3 | 123456789 4 | -------------------------------------------------------------------------------- /tseries/test/data/ts4.dat: -------------------------------------------------------------------------------- 1 | 0 1 2 | -.7 1 3 | 132465798 4 | -------------------------------------------------------------------------------- /tseries/test/data/ts5.dat: -------------------------------------------------------------------------------- 1 | 2 1 2 | .8 1 3 | -.2 2 4 | .3 1 5 | 3173265123 6 | # estimation yields incorrect coefficients 7 | -------------------------------------------------------------------------------- /tseries/test/data/ts6.b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adis300/ccmath/4be71d0447609319bfbb79f84398ca76cb68e1fe/tseries/test/data/ts6.b -------------------------------------------------------------------------------- /tseries/test/data/ts6.dat: -------------------------------------------------------------------------------- 1 | 2 1 2 | .7 1 3 | .2 2 4 | .3 1 5 | 123456789 6 | -------------------------------------------------------------------------------- /tseries/test/data/ts7.dat: -------------------------------------------------------------------------------- 1 | 2 1 2 | .8 1 3 | -.2 2 4 | -.4 1 5 | 3173265123 6 | -------------------------------------------------------------------------------- /tseries/test/data/ts8.dat: -------------------------------------------------------------------------------- 1 | 2 3 2 | .6 1 3 | .4 3 4 | .7 1 5 | .4 2 6 | -.3 3 7 | 123456789 8 | -------------------------------------------------------------------------------- /tseries/test/data/ts9.dat: -------------------------------------------------------------------------------- 1 | 5 0 2 | .9 1 3 | .4 2 4 | -.7 3 5 | .4 4 6 | -.3 5 7 | 987654321 8 | -------------------------------------------------------------------------------- /tseries/xmean.c: -------------------------------------------------------------------------------- 1 | /* xmean.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double xmean(double *x,int n) 9 | { double xm; int j; 10 | for(j=0,xm=0.; j>=1)==0){ t=u; ++k;} 18 | } 19 | printf("\n"); 20 | } 21 | -------------------------------------------------------------------------------- /util/lbits.c: -------------------------------------------------------------------------------- 1 | /* lbits.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | unsigned int lbset(unsigned int x,int n) 9 | { unsigned int t=01; 10 | t<<=n; return (x|t); 11 | } 12 | int lbget(unsigned int x,int n) 13 | { unsigned int t=01L; 14 | t<<=n; if(x&t) return 1; else return 0; 15 | } 16 | int lbcnt(unsigned int x) 17 | { int c=0; 18 | if(x) ++c; 19 | while((x=x&(x-1))!=0) ++c; 20 | return c; 21 | } 22 | -------------------------------------------------------------------------------- /util/pwr.c: -------------------------------------------------------------------------------- 1 | /* pwr.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | double pwr(double y,int n) 9 | { double s=1.; unsigned m,j; 10 | if(n){ if(n<0){ m= -n; y=1./y;} else m=n; 11 | for(j=1; j<=m ;j<<=1){ if(j&m) s*=y; y*=y;} 12 | } 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /util/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'util' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. 4 | 5 | No command line parameters are required for these tests. 6 | -------------------------------------------------------------------------------- /util/test/tbits.c: -------------------------------------------------------------------------------- 1 | /* tbits.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | /* 9 | Test: bset bget bcnt 10 | */ 11 | #include "ccmath.h" 12 | void main(void) 13 | { unsigned short n,x,m; 14 | m=sizeof(m)<<3; 15 | /* set bits */ 16 | for(x=n=0; n15){ *p= -1; return s;} else if(e<0){ *p=0; return s;} 14 | *p= *pb>>(15-e); lshift(++e,pb,XDIM); *pa-=e; 15 | for(e=0; *pb==0 && e>n;} 12 | *pm++ = *pa<pm ;){ *pc=(*pa--)>>m; *pc-- |= *pa<>m; 20 | } 21 | while(pc>=pm) *pc-- =0; 22 | } 23 | -------------------------------------------------------------------------------- /xarm/supp/big-end/README: -------------------------------------------------------------------------------- 1 | The C-code and header files in this directory is used 2 | in the 'xarm' library segment on a platform with 3 | big-endian byte ordering (such as most UNIX workstations). 4 | Simply replace the little-endian source files with these 5 | source files if your target is a big-endian machine. 6 | -------------------------------------------------------------------------------- /xarm/supp/big-end/xfmod.c: -------------------------------------------------------------------------------- 1 | /* xfmod.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xfmod(struct xpr s,struct xpr t,int *p) 10 | { struct xpr h; unsigned short *q,*ph; short k; 11 | h=xdiv(s,t); ph=(unsigned short *)&h; k=(*ph&m_exp)-bias; 12 | if(k>=0){ rshift(31-k,ph+1,2); 13 | q=(unsigned short *)p; 14 | *q= *(ph+1); *(q+1)= *(ph+2); 15 | } 16 | else *p=0; 17 | if(*p){ if(*ph&m_sgn) s=xadd(s,xmul(t,inttox(*p)),0); 18 | else s=xadd(s,xmul(t,inttox(*p)),1); 19 | } 20 | return s; 21 | } 22 | struct xpr xfrex(struct xpr s,int *p) 23 | { unsigned short *ps=(unsigned short *)&s,u; 24 | *p=(*ps&m_exp)-bias+1; u= *ps&m_sgn; 25 | *ps=bias-1; *ps|=u; return s; 26 | } 27 | -------------------------------------------------------------------------------- /xarm/supp/data/README: -------------------------------------------------------------------------------- 1 | The files in this directory support an increase in the precision 2 | of the functions in the 'xarm' library segment. This is accomplished 3 | by increasing the size of the mantissa. Possible enhanced mantissa 4 | sizes are 11, 15, 19, 23, 27, and 31 sixteen bit words. First 5 | redefine XDIM in 'xpre.h' to be equal to one of these values, 6 | then replace the 'constant.h' header with the corresponding 7 | 'const[nn].h' from this directory, and recompile the segment code 8 | with these new header files. 9 | -------------------------------------------------------------------------------- /xarm/supp/data/xcon07.dat: -------------------------------------------------------------------------------- 1 | Constants with x_dim= 7 (correctly rounded) 2 | 3 | 7.8539816339744830961566084582e-1 4 | struct xpr pi4={ 5 | 0x3ffe,0xc90f,0xdaa2,0x2168,0xc234,0xc4c6,0x628b,0x80dc 6 | }; 7 | 8 | 2.7182818284590452353602874714e+0 9 | struct xpr ee={ 10 | 0x4000,0xadf8,0x5458,0xa2bb,0x4a9a,0xafdc,0x5620,0x273d 11 | }; 12 | 13 | 6.9314718055994530941723212146e-1 14 | struct xpr ln2={ 15 | 0x3ffe,0xb172,0x17f7,0xd1cf,0x79ab,0xc9e3,0xb398,0x03f3 16 | }; 17 | 18 | 1.4142135623730950488016887242e+0 19 | struct xpr srt2={ 20 | 0x3fff,0xb504,0xf333,0xf9de,0x6484,0x597d,0x89b3,0x754b 21 | }; 22 | -------------------------------------------------------------------------------- /xarm/supp/data/xcon11.dat: -------------------------------------------------------------------------------- 1 | Constants with x_dim= 11 (correctly rounded) 2 | 3 | 7.85398163397448309615660845819875721049292350e-1 4 | struct xpr pi4={ 5 | 0x3ffe,0xc90f,0xdaa2,0x2168,0xc234,0xc4c6,0x628b,0x80dc,0x1cd1,0x2902, 6 | 0x4e08,0x8a68 7 | }; 8 | 9 | 2.71828182845904523536028747135266249775724709e+0 10 | struct xpr ee={ 11 | 0x4000,0xadf8,0x5458,0xa2bb,0x4a9a,0xafdc,0x5620,0x273d,0x3cf1,0xd8b9, 12 | 0xc583,0xce2d 13 | }; 14 | 15 | 6.93147180559945309417232121458176568075500134e-1 16 | struct xpr ln2={ 17 | 0x3ffe,0xb172,0x17f7,0xd1cf,0x79ab,0xc9e3,0xb398,0x03f2,0xf6af,0x40f3, 18 | 0x4326,0x7299 19 | }; 20 | 21 | 1.41421356237309504880168872420969807856967188e+0 22 | struct xpr srt2={ 23 | 0x3fff,0xb504,0xf333,0xf9de,0x6484,0x597d,0x89b3,0x754a,0xbe9f,0x1d6f, 24 | 0x60ba,0x893c 25 | }; 26 | -------------------------------------------------------------------------------- /xarm/supp/data/xcon15.dat: -------------------------------------------------------------------------------- 1 | Constants with x_dim= 15 (correctly rounded) 2 | 3 | 7.853981633974483096156608458198757210492923498437764552437361e-1 4 | struct xpr pi4={ 5 | 0x3ffe,0xc90f,0xdaa2,0x2168,0xc234,0xc4c6,0x628b,0x80dc,0x1cd1,0x2902, 6 | 0x4e08,0x8a67,0xcc74,0x020b,0xbea6,0x3b14 7 | }; 8 | 9 | 2.718281828459045235360287471352662497757247093699959574966968e+0 10 | struct xpr ee={ 11 | 0x4000,0xadf8,0x5458,0xa2bb,0x4a9a,0xafdc,0x5620,0x273d,0x3cf1,0xd8b9, 12 | 0xc583,0xce2d,0x3695,0xa9e1,0x3641,0x1464 13 | }; 14 | 15 | 6.931471805599453094172321214581765680755001343602552541206800e-1 16 | struct xpr ln2={ 17 | 0x3ffe,0xb172,0x17f7,0xd1cf,0x79ab,0xc9e3,0xb398,0x03f2,0xf6af,0x40f3, 18 | 0x4326,0x7298,0xb62d,0x8a0d,0x175b,0x8bab 19 | }; 20 | 21 | 1.414213562373095048801688724209698078569671875376948073176680e+0 22 | struct xpr srt2={ 23 | 0x3fff,0xb504,0xf333,0xf9de,0x6484,0x597d,0x89b3,0x754a,0xbe9f,0x1d6f, 24 | 0x60ba,0x893b,0xa84c,0xed17,0xac85,0x8334 25 | }; 26 | -------------------------------------------------------------------------------- /xarm/supp/little-end/README: -------------------------------------------------------------------------------- 1 | The C-code and header files in this directory must be used 2 | to install the 'xarm' library segment on a platform with 3 | little-endian byte ordering (for example Intel 80x86). 4 | This is the default configuration currently installed in 5 | the 'xarm' directory. 6 | -------------------------------------------------------------------------------- /xarm/supp/little-end/xfmod.c: -------------------------------------------------------------------------------- 1 | /* xfmod.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xfmod(struct xpr s,struct xpr t,int *p) 10 | { struct xpr h; unsigned short *q,*ph; short k; 11 | h=xdiv(s,t); ph=(unsigned short *)&h; k=(*ph&m_exp)-bias; 12 | if(k>=0){ rshift(31-k,ph+1,2); 13 | q=(unsigned short *)p; 14 | *(q+1)= *(ph+1); *q= *(ph+2); 15 | } 16 | else *p=0; 17 | if(*p){ if(*ph&m_sgn) s=xadd(s,xmul(t,inttox(*p)),0); 18 | else s=xadd(s,xmul(t,inttox(*p)),1); 19 | } 20 | return s; 21 | } 22 | struct xpr xfrex(struct xpr s,int *p) 23 | { unsigned short *ps=(unsigned short *)&s,u; 24 | *p=(*ps&m_exp)-bias+1; u= *ps&m_sgn; 25 | *ps=bias-1; *ps|=u; return s; 26 | } 27 | -------------------------------------------------------------------------------- /xarm/test/README: -------------------------------------------------------------------------------- 1 | This directory contains test code for the functions of the 'xarm' 2 | segment of the CCM math library. Each test code file has a sample 3 | of the correct output appended to it. Input data files, if any 4 | are named in the test code header, are in the 'data' sub-directory. 5 | 6 | The list below specifies the test input parameters required 7 | for the standard tests whose output is appended as a comment 8 | to the test source code. The absence of an entry indicates 9 | that no input parameters are required. 10 | 11 | 12 | tatox data/atox.dat 13 | txaop1 data/aop1.dat 14 | txaop2 -1.24e-3 15 | txchser 12 16 | txconv data/xcvt.dat 17 | txdiv 18 | prompt sequence: 1 3 : 4 7 : 2 16 : 0 0 19 | txexp 20 | txfmod 12.5 3 21 | txfrex data/xfrex.dat 22 | txhypb 23 | txivtrg 24 | txlog 25 | txprcmp data/xcmp.dat 26 | txpwr -.7 6 27 | txsqrt 28 | txtrig 29 | -------------------------------------------------------------------------------- /xarm/test/data/aop1.dat: -------------------------------------------------------------------------------- 1 | 1. 4. 2 | -2.3 3.147159 3 | 27.5 -33.6 4 | -11.1 -0.4 5 | -------------------------------------------------------------------------------- /xarm/test/data/atox.dat: -------------------------------------------------------------------------------- 1 | 1.25 2 | 1.234567890123456789012345678901 3 | 1.326457891245678800213456789012e+512 4 | -9.876543210123456789098765432108e-70 5 | 0.3333333333333333333333333333333 6 | 1.10e-3 7 | -------------------------------------------------------------------------------- /xarm/test/data/xcmp.dat: -------------------------------------------------------------------------------- 1 | 1.25 27.3 2 | -12.1e-2 0.05431 3 | 11.1 -27.654 4 | -1.03e-3 -0.00103 -------------------------------------------------------------------------------- /xarm/test/data/xcvt.dat: -------------------------------------------------------------------------------- 1 | d 1.375 2 | d 1.5707963267948966 3 | d 2. 4 | d 153.7e+23 5 | i 1 6 | i 123 7 | i 214675321 8 | -------------------------------------------------------------------------------- /xarm/test/data/xfrex.dat: -------------------------------------------------------------------------------- 1 | 1.2345 2 | -2.123450987654321 3 | -------------------------------------------------------------------------------- /xarm/xchcof.c: -------------------------------------------------------------------------------- 1 | /* xchcof.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | static struct xpr cs[52]; 10 | void xchcof(struct xpr *c,int m,struct xpr (*xfunc)()) 11 | { struct xpr a,b; int i,j,k,n; 12 | ++m; n=2*m; 13 | a=xdiv(pi2,inttox(m)); b=a; cs[0]=one; 14 | for(j=0; jn) i=2*n-i; 20 | c[k]=xadd(c[k],xmul(a,cs[i]),0); 21 | } 22 | } 23 | b=xpr2(xdiv(one,inttox(m)),1); 24 | for(j=0; ja ;){ 13 | f=xadd(*p--,xadd(xmul(w,t),tp,1),0); 14 | tp=t; t=f; 15 | } 16 | return xadd(*p,xadd(xmul(z,t),tp,1),0); 17 | } 18 | -------------------------------------------------------------------------------- /xarm/xexp.c: -------------------------------------------------------------------------------- 1 | /* xexp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xexp(struct xpr z) 10 | { struct xpr s,d,f; int m,k; 11 | if(neg(&z)) m=1; else m=0; 12 | z=sfmod(z,&k); if(m) k= -k; 13 | if(xex(&z)> -bias){ 14 | z=xpr2(z,-1); s=xmul(z,z); f=zero; 15 | for(d=inttox(m=ms_exp); m>1 ;){ 16 | f=xdiv(s,xadd(d,f,0)); d=inttox(m-=2); } 17 | f=xdiv(z,xadd(d,f,0)); 18 | f=xdiv(xadd(d,f,0),xadd(d,f,1)); 19 | } 20 | else f=one; 21 | if(k) return xmul(f,xpwr(ee,k)); else return f; 22 | } 23 | -------------------------------------------------------------------------------- /xarm/xfmod.c: -------------------------------------------------------------------------------- 1 | /* xfmod.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xfmod(struct xpr s,struct xpr t,int *p) 10 | { struct xpr h; unsigned short *q,*ph; short k; 11 | h=xdiv(s,t); ph=(unsigned short *)&h; k=(*ph&m_exp)-bias; 12 | if(k>=0){ rshift(31-k,ph+1,2); 13 | q=(unsigned short *)p; 14 | *(q+1)= *(ph+1); *q= *(ph+2); 15 | } 16 | else *p=0; 17 | if(*p){ if(*ph&m_sgn) s=xadd(s,xmul(t,inttox(*p)),0); 18 | else s=xadd(s,xmul(t,inttox(*p)),1); 19 | } 20 | return s; 21 | } 22 | struct xpr xfrex(struct xpr s,int *p) 23 | { unsigned short *ps=(unsigned short *)&s,u; 24 | *p=(*ps&m_exp)-bias+1; u= *ps&m_sgn; 25 | *ps=bias-1; *ps|=u; return s; 26 | } 27 | -------------------------------------------------------------------------------- /xarm/xlog.c: -------------------------------------------------------------------------------- 1 | /* xlog.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xlog(struct xpr z) 10 | { struct xpr f,h; int k,m; 11 | if(neg(&z) || xex(&z)== -bias){ 12 | printf("xlog range error\n"); return zero;} 13 | if(xprcmp(&z,&one)==0) return zero; 14 | z=xfrex(z,&m); z=xmul(z,srt2); 15 | z=xdiv(xadd(z,one,1),xadd(z,one,0)); 16 | h=xpr2(z,1); z=xmul(z,z); 17 | for(f=h,k=1; xex(&h)> -max_p ;){ 18 | h=xmul(h,z); f=xadd(f,xdiv(h,inttox(k+=2)),0); 19 | } 20 | return xadd(f,xmul(ln2,dubtox(m-.5)),0); 21 | } 22 | -------------------------------------------------------------------------------- /xarm/xmath.h: -------------------------------------------------------------------------------- 1 | /* xmath.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | #include "constant.h" 10 | -------------------------------------------------------------------------------- /xarm/xmul.c: -------------------------------------------------------------------------------- 1 | /* xmul.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xmul(struct xpr s,struct xpr t) 10 | { unsigned short pe[XDIM+2],*pa,*pb,*pc,*q0,*q1,h; 11 | unsigned int m,n,p; short k,e; 12 | q0=(unsigned short *)&s; q1=(unsigned short *)&t; 13 | e=(*q0&m_exp)-bias; k=(*q1&m_exp)+1; 14 | if(e>(short)m_exp-k) return x_huge; if((e+=k)<=0) return zero; 15 | h=(*q0 ^ *q1)&m_sgn; 16 | for(++q1,k=XDIM,p=n=0L,pc=pe+XDIM+1; k>0 ;--k){ 17 | for(pa=q0+k,pb=q1; pa>q0 ;){ 18 | m= *pa--; m*= *pb++; n+=(m&0xffffL); p+=(m>>16); } 19 | *pc-- =n; n=p+(n>>16); p=0L; 20 | } 21 | *pc=n; 22 | if(!(*pc&m_sgn)){ --e; if(e<=0) return zero; lshift(1,pc,XDIM+1);} 23 | if(e==(short)m_exp) return x_huge; 24 | *pe=e; *pe|=h; return *(struct xpr *)pe; 25 | } 26 | -------------------------------------------------------------------------------- /xarm/xneg.c: -------------------------------------------------------------------------------- 1 | /* xneg.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xneg(struct xpr s) 10 | { unsigned short *p=(unsigned short *)&s; 11 | *p^=m_sgn; return s; 12 | } 13 | struct xpr xabs(struct xpr s) 14 | { unsigned short *p=(unsigned short *)&s; 15 | *p&=m_exp; return s; 16 | } 17 | int xex(struct xpr *ps) 18 | { unsigned short *q=(unsigned short *)ps; 19 | return (*q&m_exp)-bias; 20 | } 21 | int neg(struct xpr *ps) 22 | { unsigned short *q=(unsigned short *)ps; 23 | return (*q&m_sgn); 24 | } 25 | -------------------------------------------------------------------------------- /xarm/xprcmp.c: -------------------------------------------------------------------------------- 1 | /* xprcmp.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | int xprcmp(struct xpr *pa,struct xpr *pb) 10 | { unsigned short e,k,*p,*q; int m; 11 | p=(unsigned short *)pa; e= *p&m_sgn; 12 | q=(unsigned short *)pb; k= *q&m_sgn; 13 | if(e && !k) return -1; if(!e && k) return 1; 14 | if(e) m= -1; else m=1; 15 | e= *p&m_exp; k= *q&m_exp; 16 | if(e>k) return m; if(e *q) return m; else return -m;} 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /xarm/xpwr.c: -------------------------------------------------------------------------------- 1 | /* xpwr.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | struct xpr xpwr(struct xpr s,int n) 10 | { struct xpr t; unsigned k,m; 11 | t=one; 12 | if(n<0){ m= -n; s=xdiv(one,s);} else m=n; 13 | if(m){ for(k=1; k<=m ;k<<=1){ 14 | if((k&m)) t=xmul(s,t); s=xmul(s,s); } 15 | } 16 | return t; 17 | } 18 | struct xpr xpr2(struct xpr s,int m) 19 | { unsigned short *p=(unsigned short *)&s; 20 | *p+=m; return s; 21 | } 22 | -------------------------------------------------------------------------------- /xarm/xsqrt.c: -------------------------------------------------------------------------------- 1 | /* xsqrt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "xpre.h" 9 | #include 10 | struct xpr xsqrt(struct xpr z) 11 | { struct xpr s,h; short m,e; unsigned short *pc; 12 | if(neg(&z)){ printf("xsqrt range error\n"); return zero;} 13 | pc=(unsigned short *)&z; 14 | if(*pc==0) return zero; 15 | e= *pc-bias; *pc=bias+(e%2); e/=2; 16 | s=dubtox(sqrt(xtodub(z))); 17 | for(m=0; m