/* ------------------------------------------------------------------ To compile: gcc -o dfpal2 dfpal2.c -L . -lDFPAL ------------------------------------------------------------------ */ #include #include #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 flointing point numbers */ printf("Start:\n"); if (dfpalInit((void *)malloc(dfpalMemSize())) /* start the library */ != 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 converting the input string to a demical */ count = 60000000; printf("Initialized: %s \t %s\n",dec128ToString(n1,sn1),dec128ToString(n2,sn2) ); printf("for loop:\n"); for (i = 0; i < count; i++) { // printf("Step %d: %s \t %s\n",i,dec128ToString(n1,sn1),dec128ToString(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)); /* print the results */ dfpalEnd(free); /* end the library cleanly */ } #### ~/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#