Hallo,<br><br>I´m currently evaluating GMP against libraries from other languages (such as from java). I´ve already tried to write a program which multiplies two numbers, but I´m experiencing various problems. Also I´m not very experienced in C++, so I cant tell if its me if I´m using GMP wrong. Thus I need your help, in order to make sure that my function is written correctly and as efficient as possible.
<br><br>This are the conditions:<br>1) precision must be presetup and set to 999999999<br>2) generate a decimal from a string := number (I hava already the method which generates the string / const char)<br>3) calculate number*number
<br>4) show elapsed time in milliseconds for that operation<br><br>Here is my code (using C):<br><br><br>int main() {<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; long precision = 9999999;<br><br>&nbsp;&nbsp;&nbsp; mpf_set_default_prec(precision);<br><br>&nbsp;&nbsp;&nbsp; mpf_t x, result;
<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; mpf_init(result);<br><br>&nbsp;&nbsp;&nbsp; mpf_init_set_str(x, createStringDecimal(10000), 0); <br>&nbsp;//createStringDecimal is already implemented, it returns a floating point number of the given length<br><br>&nbsp;&nbsp;&nbsp; clock_t t1, t2;
<br>&nbsp;&nbsp;&nbsp; t1 = clock();<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //action<br>&nbsp;&nbsp;&nbsp; mpf_mul(result, x, x);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; t2 = clock();<br>&nbsp;&nbsp;&nbsp; printf(&quot;\nFinished in %.2f seconds.\n\n&quot;, (t2-t1)*1.0/CLOCKS_PER_SEC);<br><br>&nbsp;&nbsp;&nbsp; int n = 1000;<br>&nbsp;&nbsp;&nbsp; gmp_printf (&quot;fixed point mpf %.*Ff with %d digits\n&quot;, n, x, n);
<br>&nbsp;&nbsp;&nbsp; gmp_printf (&quot;fixed point mpf %.*Ff with %d digits\n&quot;, n, result, n);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>