X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=examples%2Fcontfrac.cc;h=8c3b0be075af228b8e2cd3b02cad31e2ea50c908;hb=746549dde985f8e7b05fb88d2842962be421c69d;hp=f93f869e4f8be860efa33dff5837c2508e7c40fb;hpb=dd9e0f894eec7e2a8cf85078330ddc0a6639090b;p=cln.git diff --git a/examples/contfrac.cc b/examples/contfrac.cc index f93f869..8c3b0be 100644 --- a/examples/contfrac.cc +++ b/examples/contfrac.cc @@ -1,45 +1,43 @@ // Print the continued fraction of a real number. // We work with real numbers and integers. -#include -#include +#include +#include // We do I/O. -#include -#include +#include +#include -// Our private error handling: return to the main program. -#include -jmp_buf restartpoint; -void cl_abort (void) { longjmp(restartpoint,1); } +using namespace std; +using namespace cln; int main (int argc, char* argv[]) { for (int i = 1; i < argc; i++) { const char * arg = argv[i]; - if (setjmp(restartpoint)) - continue; - // Convert argument to its internal representation: - cl_R x = arg; - // Check sign. - if (minusp(x)) { - fprint(cl_stdout, "-"); - x = -x; - } - fprint(cl_stdout, "["); - const char* separator = "; "; - for (;;) { - // Split x into integral and fractional part. - cl_R_div_t x_split = floor2(x); - fprint(cl_stdout, x_split.quotient); - x = x_split.remainder; - if (zerop(x)) - break; - fprint(cl_stdout, separator); - separator = ", "; - // Invert x. - x = recip(x); - } - fprint(cl_stdout, "]\n"); + try { + // Convert argument to its internal representation: + cl_R x = arg; + // Check sign. + if (minusp(x)) { + cout << '-'; + x = -x; + } + cout << "["; + const char* separator = "; "; + for (;;) { + // Split x into integral and fractional part. + cl_R_div_t x_split = floor2(x); + cout << x_split.quotient; + x = x_split.remainder; + if (zerop(x)) + break; + cout << separator; + separator = ", "; + // Invert x. + x = recip(x); + } + cout << ']' << endl; + } catch ( const runtime_exception& ) {} } }