|
楼主 |
发表于 2010-11-6 15:04:00
|
显示全部楼层
这个也能用C编程
C programmable
Since I already had a PB-2000C calculator in my possession, it was easy to trace the origins of this Casio Z-1. Like its predecessor, the Z-1 is designed with the student programmer in mind, and contains, in addition to a BASIC interpreter, an implementation of the C-language.
The name of this machine is highly unusual, and doesn't fit with Casio's usual product nomenclature. Could it be that they named this handheld computer after Konrad Zus's Z-1, the first electromechanical (relay) computer built in 1935?
As with the PB-2000C, the Z-1's C implementation is robust. It runs flawlessly idiosyncratic programs like the one below computing to an arbitrary number of digits. The main difference from the PB-2000C is that the Z-1 is much faster: this program takes several minutes to compute 50 digits of on the PB-2000C, but on the Z-1, it takes only a few seconds.
long a=10000,b,c,d,e,*f,g;main(){printf("digits?");scanf("%ld",&c);c*=3.5;c-=c%14;f=malloc(4*c+4);for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f*a,f=d%--g,d/=g--,--b;d*=b);} (This code is not of my own creation. I downloaded the original version ages ago from the Internet. I have no idea as to the identity of its original author.)
I have, of course, also written a Gamma function program for the Z-1. This is the same code I wrote for the PB-2000C. This beast computes the logarithm of the Gamma function for any real argument to 10+ digits of precision:
double lg(x)double x;{ double g; double pi = 3.14159265359; int s; s = x<0; x = s ? -x : x; g = 2.506628283501; g += 92.20704845211 / x++; g -= 83.17763708288 / x++; g += 14.80283193078 / x++; g -= .2208497079533 / x; g = log(g) + (x-3.5)*log(x + .85) - x - .85; return s ? log(pi/(3-x)/sin(180*(x-3))) - g : g;}main(){ double g, x; printf("%lf", &x); g = lg(x); printf("lnG(%g)=%14.12g\n", x, g); printf("G(%g)=%14.12g", x, exp(g));} |
|