3 // Opaque interface to continued fractions object.
9 typedef struct cf_s
*cf_t
;
11 cf_t
cf_new(void *(*func
)(cf_t
), void *data
);
12 static inline cf_t
cf_new_const(void *(*func
)(cf_t
)) {
13 return cf_new(func
, NULL
);
15 void cf_free(cf_t cf
);
17 void cf_get(mpz_t z
, cf_t cf
);
18 void cf_put(cf_t cf
, mpz_t z
);
19 void cf_put_int(cf_t cf
, int n
);
23 void *cf_data(cf_t cf
);
26 // Compute convergents of a simple continued fraction x.
27 // Outputs p then q on channel, where p/q is the last convergent computed.
28 cf_t
cf_new_convergent(cf_t x
);
30 // Compute convergents of (a x + b)/(c x + d)
31 // where x is a regular continued fraction.
32 cf_t
cf_new_mobius_convergent(cf_t x
, mpz_t a
, mpz_t b
, mpz_t c
, mpz_t d
);
34 // Compute convergents of (a x + b)/(c x + d)
35 // where x is a nonregular continued fraction.
36 cf_t
cf_new_nonregular_mobius_convergent(cf_t x
, mpz_t a
, mpz_t b
, mpz_t c
, mpz_t d
);
38 cf_t
cf_new_nonregular_to_cf(cf_t x
, mpz_t a
, mpz_t b
, mpz_t c
, mpz_t d
);
40 cf_t
cf_new_mobius_to_decimal(cf_t x
, mpz_t a
, mpz_t b
, mpz_t c
, mpz_t d
);
41 cf_t
cf_new_cf_to_decimal(cf_t x
);
42 cf_t
cf_new_nonregular_mobius_to_decimal(cf_t x
, mpz_t a
, mpz_t b
, mpz_t c
, mpz_t d
);
44 // Well-known continued fraction expansions.
50 cf_t
cf_new_epow(mpz_t pow
);
51 cf_t
cf_new_tanh(mpz_t z
);
53 // This won't work because my code cannot handle negative denominators,
54 // and also assumes the sequence of convergents alternatively overshoot
55 // and undershoots the target. The tan expansion leads to a sequence of
56 // strictly increasing convergents (for positive input).
57 cf_t
cf_new_tan(mpz_t z
);
59 // Gosper's method for computing bihomographic functions of continued fractions.
60 cf_t
cf_new_bihom(cf_t x
, cf_t y
, mpz_t a
[8]);