From: Ben Lynn Date: Wed, 17 Sep 2008 01:33:04 +0000 (-0700) Subject: Newton's method for quadratics involving continued fractions. X-Git-Url: https://repo.or.cz/w/frac.git/commitdiff_plain/b21535311747efaacb99d6b10ef2529ceee9d502 Newton's method for quadratics involving continued fractions. --- diff --git a/Makefile b/Makefile index bc49a6c..c61c560 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: test target clean -CF_OBJS:=cf.o mobius.o famous.o bihom.o taylor.o test.o -TESTS:=bihom_test cf_test famous_test mobius_test +CF_OBJS:=cf.o mobius.o famous.o bihom.o taylor.o test.o newton.o +TESTS:=bihom_test cf_test famous_test mobius_test newton_test BINS:=pi pi2 sqrt2 epow target : $(BINS) diff --git a/cf.h b/cf.h index c607946..f250a9c 100644 --- a/cf.h +++ b/cf.h @@ -72,4 +72,12 @@ cf_t cf_new_bihom(cf_t x, cf_t y, mpz_t a[8]); cf_t cf_new_sin1(); cf_t cf_new_cos1(); +// From newton.c: +// Use Newton's method to find solutions of: +// +// a0 xy + a1 x + a2 y + a3 +// y = ------------------------ +// a4 xy - a0 x + a5 y - a2 +cf_t cf_new_newton(cf_t x, mpz_t a[6]); + #endif // __CF_H__ diff --git a/cf_test.c b/cf_test.c index c417a3e..e44229a 100644 --- a/cf_test.c +++ b/cf_test.c @@ -18,16 +18,31 @@ static void *count_fn(cf_t cf) { return NULL; } +static void *count_int_fn(cf_t cf) { + int n = 0; + while(cf_wait(cf)) { + cf_put_int(cf, n); + n++; + } + return NULL; +} + int main() { - mpz_t z; + mpz_t z, z1; mpz_init(z); - cf_t a; + mpz_init(z1); + cf_t a, b; a = cf_new_const(count_fn); + b = cf_new_const(count_int_fn); for (int i = 0; i < 100; i++) { cf_get(z, a); EXPECT(!mpz_cmp_ui(z, i)); + cf_get(z, b); + EXPECT(!mpz_cmp_ui(z, i)); } cf_free(a); + cf_free(b); mpz_clear(z); + mpz_clear(z1); return 0; } diff --git a/famous_test.c b/famous_test.c index 10db391..7347660 100644 --- a/famous_test.c +++ b/famous_test.c @@ -9,10 +9,10 @@ #include "test.h" int main() { - CF_NEW_EXPECT_DEC(cf_new_e, "2.718281828"); + CF_NEW_EXPECT_DEC(cf_new_sqrt2, "1.41421356237309504880"); + CF_NEW_EXPECT_DEC(cf_new_e, "2.71828182845904523536"); CF_NEW_EXPECT_DEC(cf_new_pi, "3.1415926535897932384"); CF_NEW_EXPECT_DEC(cf_new_tan1, "1.5574077246549022305"); - CF_NEW_EXPECT_DEC(cf_new_sin1, "0.8414709848078965066"); CF_NEW_EXPECT_DEC(cf_new_cos1, "0.5403023058681397174"); return 0;