From 11da511c784eca003deb90c23570f0873954e0de Mon Sep 17 00:00:00 2001 From: Duncan Wilkie Date: Sat, 18 Nov 2023 06:11:09 -0600 Subject: Initial commit. --- ic-reals-6.3/tests/iterate.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ic-reals-6.3/tests/iterate.c (limited to 'ic-reals-6.3/tests/iterate.c') diff --git a/ic-reals-6.3/tests/iterate.c b/ic-reals-6.3/tests/iterate.c new file mode 100644 index 0000000..89c3f07 --- /dev/null +++ b/ic-reals-6.3/tests/iterate.c @@ -0,0 +1,60 @@ +#include +#include "real.h" +#include "real-impl.h" + +main(int argc, char *argv[]) +{ + Real x, y; + double f; + Real makeRealSignCNQInt(Sign, char *, int, int, int); + Real iterate(Real, int); + int niters; + + MyName = argv[0]; + + if (argc != 8) { + fprintf(stderr, "%s \n", + MyName); + exit(1); + } + + initReals(); + + y = makeRealSignCNQInt( + atoi(argv[1]), /* sign */ + argv[2], /* c */ + atoi(argv[3]), /* n */ + atoi(argv[4]), /* a */ + atoi(argv[5])); /* b */ + + niters = atoi(argv[6]); + + print_R_Dec(y, atoi(argv[7])); + printf("\n"); + + x = iterate(y, niters); + + print_R_Dec(x, atoi(argv[7])); + printf("\n"); +} + +/* + * Iterates the function f(x) = 4x(1-x) + */ +Real +iterate(Real x, int n) +{ + Real p, q, r; + + if (n > 0) { + r = iterate(x, n - 1); + p = mul_R_Int(r, 4); + q = sub_Int_R(1, r); + r = mul_R_R(p, q); + if (n > 15) + r = makeStream(r); + return r; + } + else + return x; +} -- cgit v1.2.3