1 // Print the continued fraction of a real number.
3 // We work with real numbers and integers.
5 #include <cl_integer.h>
9 #include <cl_integer_io.h>
11 // Our private error handling: return to the main program.
14 void cl_abort (void) { longjmp(restartpoint,1); }
16 int main (int argc, char* argv[])
18 for (int i = 1; i < argc; i++) {
19 const char * arg = argv[i];
20 if (setjmp(restartpoint))
22 // Convert argument to its internal representation:
26 fprint(cl_stdout, "-");
29 fprint(cl_stdout, "[");
30 const char* separator = "; ";
32 // Split x into integral and fractional part.
33 cl_R_div_t x_split = floor2(x);
34 fprint(cl_stdout, x_split.quotient);
35 x = x_split.remainder;
38 fprint(cl_stdout, separator);
43 fprint(cl_stdout, "]\n");