Dear Monks,

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.

/* ------------------------------------------------------------------ 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 */ }
The results were better than I expected. YMMV.
~/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#
I had expected that the software only solution would be several times slower than the binary floating point hardware. Big Surprise!

Comments welcome!

Regards...Ed

"Well done is better than well said." - Benjamin Franklin


In reply to Re: Decimal Floating Point (DFP) and does Perl needs DFP? by flexvault
in thread Decimal Floating Point (DFP) and does Perl needs DFP? by flexvault

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.