// Simply run g++ sample.cpp -lgmp to compile #include #include #define PRECISION 1024 int main() { unsigned long n = 1000000000000000000; mpf_t result, r, s, root5; mpf_init2(root5, PRECISION); mpf_sqrt_ui(root5, 5); mpf_init2(r, PRECISION); mpf_add_ui(r, root5, 1); mpf_div_2exp(r, r, 1); mpf_pow_ui(r, r, n); mpf_init2(s, PRECISION); mpf_ui_sub(s, 1, root5); mpf_div_2exp(s, s, 1); mpf_pow_ui(s, s, n); mpf_init2(result, PRECISION); mpf_sub(result, r, s); mpf_div(result, result, root5); mpf_out_str(stdout, 10, 10, result); putchar('\n'); mpf_out_str(stdout, 10, 50, result); putchar('\n'); mpf_out_str(stdout, 10, 100, result); return 0; }