+ // Print small numbers in compact float format, but larger numbers in
+ // scientific format
+ const int max_cln_int = 536870911; // 2^29-1
+ if (x >= cln::cl_I(-max_cln_int) && x <= cln::cl_I(max_cln_int))
+ c.s << cln::cl_I_to_int(x) << ".0";
+ else
+ c.s << cln::double_approx(x);
+}
+
+/** Helper function to print real number in C++ source format.
+ *
+ * @see numeric::print() */
+static void print_real_csrc(const print_context & c, const cln::cl_R & x)
+{
+ if (cln::instanceof(x, cln::cl_I_ring)) {
+
+ // Integer number
+ print_integer_csrc(c, cln::the<cln::cl_I>(x));
+
+ } else if (cln::instanceof(x, cln::cl_RA_ring)) {
+
+ // Rational number
+ const cln::cl_I numer = cln::numerator(cln::the<cln::cl_RA>(x));
+ const cln::cl_I denom = cln::denominator(cln::the<cln::cl_RA>(x));
+ if (cln::plusp(x) > 0) {
+ c.s << "(";
+ print_integer_csrc(c, numer);
+ } else {
+ c.s << "-(";
+ print_integer_csrc(c, -numer);
+ }
+ c.s << "/";
+ print_integer_csrc(c, denom);
+ c.s << ")";
+
+ } else {
+
+ // Anything else
+ c.s << cln::double_approx(x);
+ }
+}
+
+/** Helper function to print real number in C++ source format using cl_N types.
+ *
+ * @see numeric::print() */
+static void print_real_cl_N(const print_context & c, const cln::cl_R & x)
+{
+ if (cln::instanceof(x, cln::cl_I_ring)) {
+
+ // Integer number
+ c.s << "cln::cl_I(\"";
+ print_real_number(c, x);
+ c.s << "\")";
+
+ } else if (cln::instanceof(x, cln::cl_RA_ring)) {
+
+ // Rational number
+ cln::cl_print_flags ourflags;
+ c.s << "cln::cl_RA(\"";
+ cln::print_rational(c.s, ourflags, cln::the<cln::cl_RA>(x));
+ c.s << "\")";
+
+ } else {
+
+ // Anything else
+ c.s << "cln::cl_F(\"";
+ print_real_number(c, cln::cl_float(1.0, cln::default_float_format) * x);
+ c.s << "_" << Digits << "\")";
+ }
+}
+
+void numeric::print_numeric(const print_context & c, const char *par_open, const char *par_close, const char *imag_sym, const char *mul_sym, unsigned level) const
+{
+ const cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
+ const cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
+