in reply to Decimal Floating Point (DFP) and does Perl needs DFP?
Just an update on this thread. I ran the following testcase on a Debian system w/o hardware DFP. I then did a Perl one-liner, that I believe does the same thing. I needed some printf statements to help figure out what I was doing, so I left them in to help any one else.
The results were better than I expected. YMMV./* ------------------------------------------------------------------ To compile: gcc -o dfpal2 dfpal2.c -L . -lDFPAL ------------------------------------------------------------------ +*/ #include <stdio.h> #include <stdlib.h> #include "dfpal.h" int main(int32_t argc, char **argv) { int i, count; char mystring[100]; char sn1[100]; char sn2[100]; int32_t init_err, init_os_err; char *err_str = NULL; dfpalflag_t st; decimal128 n1, n2; /* Declare the decimal floin +ting point numbers */ printf("Start:\n"); if (dfpalInit((void *)malloc(dfpalMemSize())) /* start the lib +rary */ != DFPAL_ERR_NO_ERROR) { fprintf(stderr,"DFPAL init error\n"); printf("Error:\n"); dfpalEnd(free); return (1); } n1 = dec128FromString(argv[1]); n2 = dec128FromString(argv[2]); /* assign a value by co +nverting the input string to a demical */ count = 60000000; printf("Initialized: %s \t %s\n",dec128ToString(n1,sn1),dec128ToSt +ring(n2,sn2) ); printf("for loop:\n"); for (i = 0; i < count; i++) { // printf("Step %d: %s \t %s\n",i,dec128ToString(n1,sn1),dec1 +28ToString(n2,sn2) ); n1 = dec128Multiply(n1, n2); /* do the maths */ // printf("Step %d: %d \t %d\n",i,i,i ); } printf("Final amount=%s\n",dec128ToString(n1,mystring)); /* pri +nt the results */ dfpalEnd(free); /* end the library cleanly */ }
I had expected that the software only solution would be several times slower than the binary floating point hardware. Big Surprise!~/dfpal# time ./dfpal2 10. 1.000001 Start: Initialized: 10 1.000001 for loop: Final amount=1141973130130727445029596475.971760 real 0m10.722s user 0m10.725s sys 0m0.000s ~/dfpal# time perl -e '$n1=10;$n2=1.000001;for ($i=0;$i<60_000_000;$i+ ++) { $n1=$n1*$n2;} print "Final amount=$n1\t$n2\n";' Final amount=1.14197312449358e+27 1.000001 real 0m8.698s user 0m8.701s sys 0m0.000s ~/dfpal#
Comments welcome!
Regards...Ed
"Well done is better than well said." - Benjamin Franklin
|
|---|