repo.or.cz
/
frac.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
New, simpler approach for sin 1 works.
[frac.git]
/
sqrt2.c
blob
6762460f107712a4905b95862c03bb429c7c87ac
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <gmp.h>
4
#include
"cf.h"
5
6
static void
*
sqrt2
(
cf_t cf
) {
7
cf_put_int
(
cf
,
1
);
8
while
(
cf_wait
(
cf
)) {
9
cf_put_int
(
cf
,
2
);
10
}
11
return
NULL
;
12
}
13
14
cf_t
cf_new_sqrt2
() {
15
return
cf_new_const
(
sqrt2
);
16
}
17
18
int
main
() {
19
cf_t x
,
conv
;
20
x
=
cf_new_sqrt2
();
21
conv
=
cf_new_convergent
(
x
);
22
23
mpz_t p
,
q
;
24
mpz_init
(
p
);
25
mpz_init
(
q
);
26
for
(
int
i
=
0
;
i
<
10
;
i
++) {
27
cf_get
(
p
,
conv
);
28
cf_get
(
q
,
conv
);
29
gmp_printf
(
"p/q = %Zd/%Zd
\n
"
,
p
,
q
);
30
}
31
cf_free
(
conv
);
32
cf_free
(
x
);
33
mpz_clear
(
p
);
34
mpz_clear
(
q
);
35
return
0
;
36
}