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
Small cleanup in famous_test.
[frac.git]
/
sqrt2.c
blob
74db94940e3c0df3bf4a98c4419ea396c6aaf060
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
}
12
13
cf_t
cf_new_sqrt2
() {
14
return
cf_new_const
(
sqrt2
);
15
}
16
17
int
main
() {
18
cf_t x
,
conv
;
19
x
=
cf_new_sqrt2
();
20
conv
=
cf_new_convergent
(
x
);
21
22
mpz_t p
,
q
;
23
mpz_init
(
p
);
24
mpz_init
(
q
);
25
for
(
int
i
=
0
;
i
<
10
;
i
++) {
26
cf_get
(
p
,
conv
);
27
cf_get
(
q
,
conv
);
28
gmp_printf
(
"p/q = %Zd/%Zd
\n
"
,
p
,
q
);
29
}
30
cf_free
(
conv
);
31
cf_free
(
x
);
32
mpz_clear
(
p
);
33
mpz_clear
(
q
);
34
return
0
;
35
}