~fmac/f292

f292/main.c -rw-r--r-- 1.0 KiB
9f6a6c18 — Francesco Camuffo Rename README -> README.md 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gmp.h>

char c_str[] = "2.920050977316134712092562917112019";

void
gen_primes(mpf_t start, unsigned int count)
{
	mpf_t n, flr, n_flr, n_flr_1;
	mpf_init_set(n, start);
	mpf_init(flr);
	mpf_init(n_flr);
	mpf_init(n_flr_1);
	unsigned int i = 0;

	while (i < count) {
		mpf_floor(flr, n);
		gmp_printf("%.Ff\n", flr);

		mpf_sub(n_flr, n, flr);
		mpf_add_ui(n_flr_1, n_flr, 1);
		mpf_mul(n, flr, n_flr_1);

		i++;
	}
}

int
main(int argc, char *argv[])
{
	unsigned int count = 10;
	unsigned int prec = 256;

	int opt;
	while ((opt = getopt(argc, argv, "n:p:")) != -1) {
		switch (opt)
		{
			case 'n':
				count = atoi(optarg);
				break;
			case 'p':
				prec = atoi(optarg);
				break;
			case '?':
				fprintf(stderr,
						"Usage: %s [-n <count>] [-p <precision>]\n",
						argv[0]);
				exit(1);
			default:
				abort();
		}
	}

	mpf_set_default_prec(prec);
	mpf_t c;
	mpf_init(c);
	mpf_set_str(c, c_str, 10);

	gen_primes(c, count);

	return 0;
}