Arithmetic-geometric mean/Calculate Pi: Difference between revisions
Arithmetic-geometric mean/Calculate Pi (view source)
Revision as of 11:53, 12 September 2020
, 3 years ago→{{header|C++}}: added elapsed time
m (→{{header|C++}}: tweaked output to remove trailing zeros, added output (checked against C output), removed warning. removed minor whitespace) |
m (→{{header|C++}}: added elapsed time) |
||
Line 141:
{{libheader|GMP}}
<lang cpp>#include <gmpxx.h>
#include <chrono>
using namespace std;
using namespace chrono;
void agm(mpf_class& rop1, mpf_class& rop2, const mpf_class& op1,
Line 152 ⟶ 156:
int main(void)
{
auto st = steady_clock::now();
mpf_set_default_prec(300000);
mpf_class x0, y0, resA, resB, Z;
Line 172 ⟶ 177:
x0 = x0 * x0 / Z;
printf("Took %f ms for computation.\n", duration<double>(steady_clock::now() - st).count() * 1000.0);
st = steady_clock::now();
gmp_printf ("%.89412Ff\n", x0.get_mpf_t());
printf("Took %f ms for output.\n", duration<double>(steady_clock::now() - st).count() * 1000.0);
return 0;
}</lang>
{{out}}
<pre style="height:64ex;white-space: pre-wrap;">Took 60.726400 ms for computation.
Took 12.108100 ms for output.</pre>Compiler options: <code>-std=c++17 -O3 -lgmp</code> Timings on a core i7-7700 @ 3.6Ghz.
=={{header|Clojure}}==
|