Added sign of a continued fraction.
[frac.git] / cf.h
blob1fd64e374096375eba0a8a7a92253e7fec4539b3
1 // Requires gmp.h
2 //
3 // Opaque interface to continued fractions object.
5 #ifndef __CF_H__
6 #define __CF_H__
8 struct cf_s;
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 int cf_sign(cf_t cf);
18 int cf_flip_sign(cf_t cf);
19 void cf_get(mpz_t z, cf_t cf);
20 void cf_put(cf_t cf, mpz_t z);
21 void cf_put_int(cf_t cf, int n);
23 int cf_wait(cf_t cf);
25 void *cf_data(cf_t cf);
27 // cf_mobius.c:
28 // Compute convergents of a simple continued fraction x.
29 // Outputs p then q on channel, where p/q is the last convergent computed.
30 cf_t cf_new_convergent(cf_t x);
32 // Compute convergents of (a x + b)/(c x + d)
33 // where x is a regular continued fraction.
34 cf_t cf_new_mobius_convergent(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
36 // Compute convergents of (a x + b)/(c x + d)
37 // where x is a nonregular continued fraction.
38 cf_t cf_new_nonregular_mobius_convergent(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
40 cf_t cf_new_nonregular_to_cf(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
42 cf_t cf_new_mobius_to_decimal(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
43 cf_t cf_new_cf_to_decimal(cf_t x);
44 cf_t cf_new_nonregular_mobius_to_decimal(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
46 // Well-known continued fraction expansions.
47 // cf_famous.c:
48 // e:
49 cf_t cf_new_e();
50 cf_t cf_new_pi();
51 cf_t cf_new_tan1();
52 cf_t cf_new_epow(mpz_t pow);
53 cf_t cf_new_tanh(mpz_t z);
55 // This won't work because my code cannot handle negative denominators,
56 // and also assumes the sequence of convergents alternatively overshoot
57 // and undershoots the target. The tan expansion leads to a sequence of
58 // strictly increasing convergents (for positive input).
59 cf_t cf_new_tan(mpz_t z);
61 // Gosper's method for computing bihomographic functions of continued fractions.
62 cf_t cf_new_bihom(cf_t x, cf_t y, mpz_t a[8]);
64 // From taylor.c:
65 cf_t cf_new_sin1();
66 cf_t cf_new_cos1();
68 #endif // __CF_H__