143 : fw (
w), ex (0), prec (p), fmt (
f), up (0), sp (0) { }
146 : fw (w), ex (e), prec (p), fmt (f), up (0), sp (0) { }
149 : fw (ff.fw), ex (ff.ex), prec (ff.prec), fmt (ff.fmt), up (ff.up),
181 { sp = tz ? std::ios::showpoint : 0;
return *
this; }
183 friend std::ostream&
operator << (std::ostream& os,
186 friend std::ostream&
operator << (std::ostream& os,
189 friend std::ostream&
operator << (std::ostream& os,
219 return x - 3*
static_cast<int> (x/3);
240 double absval = (x < 0.0 ? -x :
x);
241 int logabsval =
static_cast<int> (
gnulib::floor (log10 (absval)));
245 ex = logabsval - 2 + ((-logabsval + 2) % 3);
247 ex = logabsval - (logabsval % 3);
269 int exponent (
void)
const
274 double mantissa (
void)
const
276 return val /
std::pow (10.0, exponent ());
280 : f (f_arg), val (val_arg) { }
289 os << std::setw (pef.
f.
fw - pef.
f.
ex);
292 os << std::setprecision (pef.
f.
prec);
294 os.flags (static_cast<std::ios::fmtflags>
302 os << std::setw (0) <<
"e-";
306 os << std::setw (0) <<
"e+";
308 os << std::setw (pef.
f.
ex - 2) << std::setfill (
'0') << ex;
323 : f (f_arg), val (val_arg) { }
332 os << std::setw (pff.
f.
fw);
335 os << std::setprecision (pff.
f.
prec);
337 os.flags (static_cast<std::ios::fmtflags>
345 static inline std::string
361 std::ostringstream buf;
362 buf.flags (std::ios::fixed);
363 buf << std::setprecision (0) <<
xround (val);
372 double frac = val - n;
375 std::ostringstream buf2;
376 buf2.flags (std::ios::fixed);
377 buf2 << std::setprecision (0) << static_cast<int>(n);
382 double flip = 1. / frac;
383 double step =
xround (flip);
397 n = n * step + lastn;
398 d = d * step + lastd;
402 std::ostringstream buf;
403 buf.flags (std::ios::fixed);
404 buf << std::setprecision (0) << static_cast<int>(n)
405 <<
"/" << static_cast<int>(d);
411 if (buf.str ().length () >
static_cast<unsigned int>(len + 2) &&
415 else if (buf.str ().length () >
static_cast<unsigned int>(len) &&
427 std::ostringstream buf;
428 buf.flags (std::ios::fixed);
429 buf << std::setprecision (0) << static_cast<int>(lastn)
430 <<
"/" << static_cast<int>(lastd);
448 : f (f_arg), val (val_arg) { }
456 int fw = (rat_string_len > 0 ? rat_string_len : prf.
f.
fw);
460 os << std::setw (fw);
462 os.flags (static_cast<std::ios::fmtflags>
465 if (fw > 0 && s.length () >
static_cast<unsigned int>(fw))
488 bool all_inf_or_nan =
true;
497 all_inf_or_nan =
false;
517 bool all_inf_or_nan =
true;
526 all_inf_or_nan =
false;
556 fw = digits < 0 ? 5 : digits + 4;
557 if (inf_or_nan && fw < 5)
571 else if (inf_or_nan || int_only)
574 if (inf_or_nan && fw < 4)
583 rd = prec > digits ? prec - digits : prec;
589 rd = prec > digits ? prec - digits : prec;
590 digits = -digits + 1;
593 fw = 1 + ld + 1 + rd;
594 if (inf_or_nan && fw < 4)
612 if (inf_or_nan && fw < 6)
620 if (inf_or_nan && fw < 4)
622 fmt =
float_format (fw, ex, prec - 1, std::ios::scientific);
629 else if (!
bank_format && (inf_or_nan || int_only))
634 curr_real_fmt = &fmt;
648 bool int_only = (! inf_or_nan &&
D_NINT (d) ==
d);
650 double d_abs = d < 0.0 ? -d :
d;
652 int digits = (inf_or_nan || d_abs == 0.0) ? 0 :
num_digits (d_abs);
666 int int_or_inf_or_nan,
int& fw)
681 int digits = x_max > x_min ? x_max : x_min;
682 fw = digits <= 0 ? 5 : digits + 4;
683 if (inf_or_nan && fw < 5)
701 if (inf_or_nan && fw < 4)
704 else if (int_or_inf_or_nan)
706 int digits = x_max > x_min ? x_max : x_min;
707 fw = digits <= 0 ? 2 : digits + 1;
708 if (inf_or_nan && fw < 4)
718 rd_max = prec > x_max ? prec - x_max : prec;
724 rd_max = prec > x_max ? prec - x_max : prec;
732 rd_min = prec > x_min ? prec - x_min : prec;
738 rd_min = prec > x_min ? prec - x_min : prec;
742 ld = ld_max > ld_min ? ld_max : ld_min;
743 rd = rd_max > rd_min ? rd_max : rd_min;
745 fw = 1 + ld + 1 + rd;
746 if (inf_or_nan && fw < 4)
760 if (x_max > 100 || x_min > 100)
766 if (inf_or_nan && fw < 6)
773 if (inf_or_nan && fw < 4)
775 fmt =
float_format (fw, prec - 1, std::ios::scientific);
787 curr_real_fmt = &fmt;
807 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
809 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
811 scale = (x_max == 0 || int_or_inf_or_nan)
827 int int_only,
int& r_fw,
int& i_fw)
846 r_fw = digits <= 0 ? 5 : digits + 4;
847 if (inf_or_nan && r_fw < 5)
853 r_fw = 2 *
sizeof (
double);
854 i_fw = 2 *
sizeof (
double);
859 r_fw = 8 *
sizeof (
double);
860 i_fw = 8 *
sizeof (
double);
863 else if (inf_or_nan || int_only)
865 int digits = x_max > x_min ? x_max : x_min;
866 i_fw = digits <= 0 ? 1 : digits;
868 if (inf_or_nan && i_fw < 3)
881 rd_max = prec > x_max ? prec - x_max : prec;
887 rd_max = prec > x_max ? prec - x_max : prec;
895 rd_min = prec > x_min ? prec - x_min : prec;
901 rd_min = prec > x_min ? prec - x_min : prec;
905 ld = ld_max > ld_min ? ld_max : ld_min;
906 rd = rd_max > rd_min ? rd_max : rd_min;
910 if (inf_or_nan && i_fw < 3)
928 if (x_max > 100 || x_min > 100)
933 i_fw = 3 + prec + ex;
935 if (inf_or_nan && i_fw < 5)
940 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
941 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
945 i_fw = 1 + prec + ex;
947 if (inf_or_nan && i_fw < 3)
952 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
953 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
963 else if (!
bank_format && (inf_or_nan || int_only))
974 curr_real_fmt = &r_fmt;
975 curr_imag_fmt = &i_fmt;
987 double rp = c.real ();
988 double ip = c.imag ();
992 bool int_only = (
D_NINT (rp) == rp &&
D_NINT (ip) == ip);
994 double r_abs = rp < 0.0 ? -rp : rp;
995 double i_abs = ip < 0.0 ? -ip : ip;
1026 int r_x_min,
bool inf_or_nan,
1027 int int_or_inf_or_nan,
int& r_fw,
int& i_fw)
1044 int digits = r_x_max > r_x_min ? r_x_max : r_x_min;
1046 r_fw = digits <= 0 ? 5 : digits + 4;
1047 if (inf_or_nan && r_fw < 5)
1051 else if (hex_format)
1053 r_fw = 2 *
sizeof (
double);
1054 i_fw = 2 *
sizeof (
double);
1057 else if (bit_format)
1059 r_fw = 8 *
sizeof (
double);
1060 i_fw = 8 *
sizeof (
double);
1068 if (inf_or_nan && i_fw < 3)
1074 else if (int_or_inf_or_nan)
1076 int digits = x_max > x_min ? x_max : x_min;
1077 i_fw = digits <= 0 ? 1 : digits;
1079 if (inf_or_nan && i_fw < 3)
1092 rd_max = prec > x_max ? prec - x_max : prec;
1098 rd_max = prec > x_max ? prec - x_max : prec;
1106 rd_min = prec > x_min ? prec - x_min : prec;
1112 rd_min = prec > x_min ? prec - x_min : prec;
1116 ld = ld_max > ld_min ? ld_max : ld_min;
1117 rd = rd_max > rd_min ? rd_max : rd_min;
1121 if (inf_or_nan && i_fw < 3)
1141 if (x_max > 100 || x_min > 100)
1146 i_fw = 3 + prec + ex;
1148 if (inf_or_nan && i_fw < 5)
1153 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
1154 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
1158 i_fw = 1 + prec + ex;
1160 if (inf_or_nan && i_fw < 3)
1165 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
1166 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
1187 curr_real_fmt = &r_fmt;
1188 curr_imag_fmt = &i_fmt;
1216 int r_x_max = r_max_abs == 0.0 ? 0 :
num_digits (r_max_abs);
1218 int r_x_min = r_min_abs == 0.0 ? 0 :
num_digits (r_min_abs);
1220 int i_x_max = i_max_abs == 0.0 ? 0 :
num_digits (i_max_abs);
1222 int i_x_min = i_min_abs == 0.0 ? 0 :
num_digits (i_min_abs);
1224 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
1225 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
1227 scale = (x_max == 0 || int_or_inf_or_nan)
1231 int_or_inf_or_nan, r_fw, i_fw);
1258 int digits = x_max > x_min ? x_max : x_min;
1259 fw = digits < 0 ? 5 : digits + 4;
1262 else if (hex_format)
1264 fw = 2 *
sizeof (
double);
1267 else if (bit_format)
1269 fw = 8 *
sizeof (
double);
1274 int digits = x_max > x_min ? x_max : x_min;
1289 rd_max = prec > x_max ? prec - x_max : prec;
1295 rd_max = prec > x_max ? prec - x_max : prec;
1303 rd_min = prec > x_min ? prec - x_min : prec;
1309 rd_min = prec > x_min ? prec - x_min : prec;
1313 ld = ld_max > ld_min ? ld_max : ld_min;
1314 rd = rd_max > rd_min ? rd_max : rd_min;
1329 if (x_max > 100 || x_min > 100)
1335 fmt =
float_format (fw, ex, prec - 1, std::ios::fixed);
1340 fmt =
float_format (fw, prec - 1, std::ios::scientific);
1352 curr_real_fmt = &fmt;
1364 double r_min = r.
base ();
1365 double r_max = r.
limit ();
1376 double max_abs = r_max < 0.0 ? -r_max : r_max;
1377 double min_abs = r_min < 0.0 ? -r_min : r_min;
1379 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
1381 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
1383 scale = (x_max == 0 || all_ints)
1403 #define PRINT_CHAR_BITS(os, c) \
1406 unsigned char ctmp = c; \
1408 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
1409 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
1410 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
1411 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
1412 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
1413 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
1414 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
1415 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
1421 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
1424 unsigned char ctmp = c; \
1426 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
1427 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
1428 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
1429 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
1430 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
1431 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
1432 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
1433 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
1467 os.flags (std::ios::right | std::ios::hex);
1472 for (
size_t i = 0; i <
sizeof (
double); i++)
1473 os << std::setw (2) <<
static_cast<int> (tmp.
i[i]);
1477 for (
int i =
sizeof (
double) - 1; i >= 0; i--)
1478 os << std::setw (2) <<
static_cast<int> (tmp.
i[i]);
1481 else if (bit_format)
1491 for (
size_t i = 0; i <
sizeof (
double); i++)
1498 for (
size_t i = 0; i <
sizeof (
double); i++)
1503 for (
int i =
sizeof (
double) - 1; i >= 0; i--)
1513 os << std::setw (fw) <<
"NA";
1530 os << std::setw (fw) << s;
1539 os << std::setw (fw) <<
"NaN";
1569 int i_fw = 0,
double scale = 1.0)
1574 double r = tmp.real ();
1580 double i = tmp.imag ();
1589 if (hex_format || bit_format)
1602 bool pr_as_read_syntax)
1604 assert (nr == 0 || nc == 0);
1606 if (pr_as_read_syntax)
1608 if (nr == 0 && nc == 0)
1611 os <<
"zeros (" << nr <<
", " << nc <<
")";
1618 os <<
"(" << nr <<
"x" << nc <<
")";
1624 bool pr_as_read_syntax)
1628 if (pr_as_read_syntax)
1629 os <<
"zeros (" << dims.
str (
',') <<
")";
1635 os <<
"(" << dims.
str () <<
")";
1647 << std::setw (8) << std::setprecision (1)
1675 os << std::setw (extra_indent) <<
"";
1678 os <<
" Column " << col + 1 <<
":\n";
1679 else if (num_cols == 2)
1680 os <<
" Columns " << col + 1 <<
" and " << lim <<
":\n";
1682 os <<
" Columns " << col + 1 <<
" through " << lim <<
":\n";
1695 else if (val < T (0))
1696 os << plus_format_chars[1];
1698 os << plus_format_chars[2];
1709 bool pr_as_read_syntax)
1711 if (pr_as_read_syntax)
1727 bool pr_as_read_syntax,
int extra_indent)
1732 if (nr == 0 || nc == 0)
1754 int column_width = fw + 2;
1758 if (pr_as_read_syntax)
1761 max_width -= extra_indent;
1768 if (pr_as_read_syntax)
1773 if (pr_as_read_syntax)
1782 inc = max_width / column_width;
1787 if (pr_as_read_syntax)
1800 if (i == 0 && j == 0)
1804 if (j > col && j < lim)
1842 os << std::setw (extra_indent) <<
"";
1863 bool pr_as_read_syntax,
int extra_indent)
1868 if (nr == 0 || nc == 0)
1890 int column_width = fw + 2;
1894 if (pr_as_read_syntax)
1897 max_width -= extra_indent;
1904 if (pr_as_read_syntax)
1909 if (pr_as_read_syntax)
1918 inc = max_width / column_width;
1923 if (pr_as_read_syntax)
1940 if (j > col && j < lim)
1962 os <<
"Diagonal Matrix\n";
1972 std::ostringstream tmp_oss;
1973 pr_float (tmp_oss, 0.0, fw, scale);
1974 zero_fw = tmp_oss.str ().length ();
1986 os << std::setw (extra_indent) <<
"";
1997 os << std::setw (zero_fw) <<
'0';
2009 template <
typename NDA_T,
typename ELT_T,
typename MAT_T>
2011 bool pr_as_read_syntax)
2014 if (nda.is_empty ())
2019 int ndims = nda.ndims ();
2027 for (
int i = 2; i < ndims; i++)
2037 std::string nm =
"ans";
2043 std::ostringstream buf;
2045 for (
int k = 2; k < ndims; k++)
2047 buf << ra_idx(k) + 1;
2063 for (
int k = 2; k < ndims; k++)
2087 bool pr_as_read_syntax,
int extra_indent)
2089 switch (nda.
ndims ())
2094 pr_as_read_syntax, extra_indent);
2098 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax);
2105 pr_plus_format<> (std::ostream& os,
const Complex& c)
2107 double rp = c.real ();
2108 double ip = c.imag ();
2125 bool pr_as_read_syntax)
2127 if (pr_as_read_syntax)
2143 bool pr_as_read_syntax,
int extra_indent)
2148 if (nr == 0 || nc == 0)
2170 int column_width = i_fw + r_fw;
2176 if (pr_as_read_syntax)
2179 max_width -= extra_indent;
2186 if (pr_as_read_syntax)
2191 if (pr_as_read_syntax)
2200 inc = max_width / column_width;
2205 if (pr_as_read_syntax)
2218 if (i == 0 && j == 0)
2222 if (j > col && j < lim)
2260 os << std::setw (extra_indent) <<
"";
2281 bool pr_as_read_syntax,
int extra_indent)
2286 if (nr == 0 || nc == 0)
2308 int column_width = i_fw + r_fw;
2314 if (pr_as_read_syntax)
2317 max_width -= extra_indent;
2324 if (pr_as_read_syntax)
2329 if (pr_as_read_syntax)
2338 inc = max_width / column_width;
2343 if (pr_as_read_syntax)
2360 if (j > col && j < lim)
2382 os <<
"Diagonal Matrix\n";
2392 std::ostringstream tmp_oss;
2394 zero_fw = tmp_oss.str ().length ();
2406 os << std::setw (extra_indent) <<
"";
2417 os << std::setw (zero_fw) <<
'0';
2430 bool pr_as_read_syntax,
int extra_indent)
2435 if (nr == 0 || nc == 0)
2455 int column_width = fw + 2;
2459 if (pr_as_read_syntax)
2462 max_width -= extra_indent;
2469 if (pr_as_read_syntax)
2474 if (pr_as_read_syntax)
2483 inc = max_width / column_width;
2488 if (pr_as_read_syntax)
2494 if (colp) os <<
":, ";
2509 if (j > col && j < lim)
2525 if (! colp) os <<
", :";
2532 os <<
"Permutation Matrix\n";
2545 os << std::setw (extra_indent) <<
"";
2553 os << std::setw (fw) << m(i,j);
2566 bool pr_as_read_syntax,
int extra_indent)
2568 switch (nda.
ndims ())
2573 pr_as_read_syntax, extra_indent);
2577 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
2578 (os, nda, pr_as_read_syntax);
2599 bool pr_as_read_syntax,
int extra_indent)
2606 bool pr_as_read_syntax,
int extra_indent)
2613 bool pr_as_read_syntax,
int extra_indent)
2620 bool pr_as_read_syntax)
2627 bool pr_as_read_syntax,
int extra_indent)
2635 bool pr_as_read_syntax,
int extra_indent)
2643 bool pr_as_read_syntax,
int extra_indent)
2651 bool pr_as_read_syntax,
int extra_indent)
2653 double base = r.
base ();
2654 double increment = r.
inc ();
2655 double limit = r.
limit ();
2664 double val = base + i * increment;
2675 if (pr_as_read_syntax)
2679 os << base <<
" : ";
2680 if (increment != 1.0)
2681 os << increment <<
" : ";
2688 if (increment != 1.0)
2700 int column_width = fw + 2;
2713 inc = max_width / column_width;
2718 max_width -= extra_indent;
2726 while (col < num_elem)
2733 os << std::setw (extra_indent) <<
"";
2743 val = base + i * increment;
2745 if (i == num_elem - 1)
2748 if ((increment > 0 && val >= limit)
2749 || (increment < 0 && val <= limit))
2766 bool pr_as_read_syntax,
2775 bool pr_as_read_syntax,
2778 switch (nda.
ndims ())
2783 pr_as_read_syntax, extra_indent);
2795 bool pr_as_read_syntax,
2803 if (pr_as_read_syntax && nstr > 1)
2814 if (pr_as_read_syntax)
2831 if (pr_as_read_syntax && nstr > 1)
2836 os <<
"sorry, printing char matrices not implemented yet\n";
2842 bool pr_as_read_syntax,
int extra_indent,
2845 switch (nda.
ndims ())
2850 pr_as_read_syntax, extra_indent, pr_as_string);
2854 print_nd_array <charNDArray, char, charMatrix> (os, nda,
2862 bool pr_as_read_syntax,
int extra_indent)
2871 bool pr_as_read_syntax,
int )
2878 else if (nda.
length () == 1)
2884 int ndims = nda.
ndims ();
2892 for (
int i = 2; i < ndims; i++)
2900 std::string nm =
"ans";
2906 std::ostringstream buf;
2908 for (
int k = 2; k < ndims; k++)
2910 buf << ra_idx(k) + 1;
2926 for (
int k = 2; k < ndims; k++)
2944 os <<
" " << page(ii,jj);
2966 #define PRINT_CONV(T1, T2) \
2969 octave_print_conv<T1> \
2972 typedef T2 print_conv_type; \
2984 size_t sz = d.byte_size ();
2985 const unsigned char * tmpi = d.iptr ();
2997 os.flags (std::ios::right | std::ios::hex);
3001 for (
size_t i = 0; i < sz; i++)
3002 os << std::setw (2) <<
static_cast<int> (tmpi[i]);
3006 for (
int i = sz - 1; i >= 0; i--)
3007 os << std::setw (2) <<
static_cast<int> (tmpi[i]);
3010 else if (bit_format)
3014 for (
size_t i = 0; i < sz; i++)
3021 for (
size_t i = 0; i < sz; i++)
3026 for (
int i = sz - 1; i >= 0; i--)
3035 os << std::setw (fw)
3053 return x < 0 ? -x :
x;
3056 #define INSTANTIATE_ABS(T) \
3065 #define SPECIALIZE_UABS(T) \
3068 abs (unsigned T x) \
3115 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val);
3121 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
3122 OCTINTERP_API void \
3123 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \
3125 octave_print_internal_template (os, val, dummy); \
3140 bool pr_as_read_syntax,
int extra_indent)
3145 if (nda.is_empty ())
3147 else if (nda.length () == 1)
3151 int ndims = nda.ndims ();
3159 for (
int i = 2; i < ndims; i++)
3169 std::string nm =
"ans(:,:,";
3171 std::ostringstream buf;
3173 for (
int k = 2; k < ndims; k++)
3175 buf << ra_idx(k) + 1;
3195 for (
int k = 2; k < ndims; k++)
3209 if ((ii < nr - 1) || (i < m -1))
3222 int ndims = nda.ndims ();
3230 for (
int i = 2; i < ndims; i++)
3238 fw = 2 * nda(0).byte_size ();
3239 else if (bit_format)
3240 fw = nda(0).nbits ();
3252 if (new_digits > digits)
3253 digits = new_digits;
3256 isneg = (
abs (nda(i).value ()) != nda(i).value ());
3259 fw = digits + isneg;
3268 inc = max_width / column_width;
3277 std::string nm =
"ans(:,:,";
3279 std::ostringstream buf;
3281 for (
int k = 2; k < ndims; k++)
3283 buf << ra_idx(k) + 1;
3303 for (
int k = 2; k < ndims; k++)
3310 if (pr_as_read_syntax)
3319 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj));
3324 if (pr_as_read_syntax)
3343 os << std::setw (extra_indent) <<
"";
3349 pr_int (os, page(ii,jj), fw);
3351 if ((ii < n_rows - 1) || (i < m -1))
3366 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
3367 OCTINTERP_API void \
3368 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \
3369 bool pr_as_read_syntax, int extra_indent) \
3371 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
3391 bool pr_as_read_syntax)
3396 DEFUN (rats, args, nargout,
3398 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\
3399 Convert @var{x} into a rational approximation represented as a string.\n\
3400 You can convert the string back into a matrix as follows:\n\
3404 r = rats (hilb (4));\n\
3409 The optional second argument defines the maximum length of the string\n\
3410 representing the elements of @var{x}. By default @var{len} is 9.\n\
3411 @seealso{format, rat}\n\
3416 int nargin = args.
length ();
3418 if (nargin < 1 || nargin > 2 || nargout > 1)
3429 rat_string_len = args(1).nint_value ();
3441 std::ostringstream buf;
3442 args(0).print (buf);
3443 std::string s = buf.str ();
3445 std::list<std::string> lst;
3448 size_t s_len = s.length ();
3452 size_t m = s.find (
'\n', n);
3454 if (m == std::string::npos)
3456 lst.push_back (s.substr (n));
3461 lst.push_back (s.substr (n, m - n));
3469 error (
"rats: X must be numeric");
3476 DEFUN (disp, args, nargout,
3478 @deftypefn {Built-in Function} {} disp (@var{x})\n\
3479 Display the value of @var{x}. For example:\n\
3483 disp (\"The value of pi is:\"), disp (pi)\n\
3485 @print{} the value of pi is:\n\
3491 Note that the output from @code{disp} always ends with a newline.\n\
3493 If an output value is requested, @code{disp} prints nothing and\n\
3494 returns the formatted output in a string.\n\
3500 int nargin = args.
length ();
3502 if (nargin == 1 && nargout < 2)
3509 std::ostringstream buf;
3520 DEFUN (fdisp, args, ,
3522 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\
3523 Display the value of @var{x} on the stream @var{fid}. For example:\n\
3527 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\
3529 @print{} the value of pi is:\n\
3535 Note that the output from @code{fdisp} always ends with a newline.\n\
3541 int nargin = args.
length ();
3554 args(1).print (*osp);
3556 error (
"fdisp: stream FID not open for writing");
3611 Voutput_precision = prec;
3612 Voutput_max_field_width = fw;
3622 std::string
arg = argv[idx++];
3635 else if (arg ==
"E")
3641 else if (arg ==
"g")
3646 else if (arg ==
"G")
3652 else if (arg ==
"eng")
3659 error (
"format: unrecognized option 'short %s'",
3669 else if (arg ==
"long")
3680 else if (arg ==
"E")
3686 else if (arg ==
"g")
3691 else if (arg ==
"G")
3697 else if (arg ==
"eng")
3704 error (
"format: unrecognized option 'long %s'",
3714 else if (arg ==
"hex")
3719 else if (arg ==
"native-hex")
3724 else if (arg ==
"bit")
3729 else if (arg ==
"native-bit")
3734 else if (arg ==
"+" || arg ==
"plus")
3740 if (arg.length () == 3)
3744 error (
"format: invalid option for plus format");
3754 else if (arg ==
"rat")
3759 else if (arg ==
"bank")
3764 else if (arg ==
"free")
3769 else if (arg ==
"none")
3774 else if (arg ==
"compact")
3778 else if (arg ==
"loose")
3783 error (
"format: unrecognized format state '%s'", arg.c_str ());
3792 DEFUN (format, args, ,
3794 @deftypefn {Command} {} format\n\
3795 @deftypefnx {Command} {} format options\n\
3796 Reset or specify the format of the output produced by @code{disp} and\n\
3797 Octave's normal echoing mechanism. This command only affects the display\n\
3798 of numbers but not how they are stored or computed. To change the internal\n\
3799 representation from the default double use one of the conversion functions\n\
3800 such as @code{single}, @code{uint8}, @code{int64}, etc.\n\
3802 By default, Octave displays 5 significant digits in a human readable form\n\
3803 (option @samp{short} paired with @samp{loose} format for matrices).\n\
3804 If @code{format} is invoked without any options, this default format\n\
3807 Valid formats for floating point numbers are listed in the following\n\
3812 Fixed point format with 5 significant figures in a field that is a maximum\n\
3813 of 10 characters wide. (default).\n\
3815 If Octave is unable to format a matrix so that columns line up on the\n\
3816 decimal point and all numbers fit within the maximum field width then\n\
3817 it switches to an exponential @samp{e} format.\n\
3820 Fixed point format with 15 significant figures in a field that is a maximum\n\
3821 of 20 characters wide.\n\
3823 As with the @samp{short} format, Octave will switch to an exponential\n\
3824 @samp{e} format if it is unable to format a matrix properly using the\n\
3829 Exponential format. The number to be represented is split between a mantissa\n\
3830 and an exponent (power of 10). The mantissa has 5 significant digits in the\n\
3831 short format and 15 digits in the long format.\n\
3832 For example, with the @samp{short e} format, @code{pi} is displayed as\n\
3833 @code{3.1416e+00}.\n\
3837 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\
3838 @samp{E} to indicate the exponent.\n\
3839 For example, with the @samp{long E} format, @code{pi} is displayed as\n\
3840 @code{3.14159265358979E+00}.\n\
3844 Optimally choose between fixed point and exponential format based on\n\
3845 the magnitude of the number.\n\
3846 For example, with the @samp{short g} format,\n\
3847 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\
3863 Identical to @samp{short e} or @samp{long e} but displays the value\n\
3864 using an engineering format, where the exponent is divisible by 3. For\n\
3865 example, with the @samp{short eng} format, @code{10 * pi} is displayed as\n\
3866 @code{31.4159e+00}.\n\
3870 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\
3871 @samp{E} to indicate the exponent.\n\
3875 Print output in free format, without trying to line up columns of\n\
3876 matrices on the decimal point. This also causes complex numbers to be\n\
3877 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\
3878 of like this @samp{0.60419 + 0.60709i}.\n\
3881 The following formats affect all numeric output (floating point and\n\
3886 @itemx + @var{chars}\n\
3888 @itemx plus @var{chars}\n\
3889 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\
3890 matrix elements. This format can be very useful for examining the\n\
3891 structure of a large sparse matrix.\n\
3893 The optional argument @var{chars} specifies a list of 3 characters to use\n\
3894 for printing values greater than zero, less than zero and equal to zero.\n\
3895 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\
3908 Print in a fixed format with two digits to the right of the decimal\n\
3912 Print the hexadecimal representation of numbers as they are stored in\n\
3913 memory. For example, on a workstation which stores 8 byte real values\n\
3914 in IEEE format with the least significant byte first, the value of\n\
3915 @code{pi} when printed in @code{native-hex} format is\n\
3916 @code{400921fb54442d18}.\n\
3919 The same as @code{native-hex}, but always print the most significant\n\
3923 Print the bit representation of numbers as stored in memory.\n\
3924 For example, the value of @code{pi} is\n\
3928 01000000000010010010000111111011\n\
3929 01010100010001000010110100011000\n\
3933 (shown here in two 32 bit sections for typesetting purposes) when\n\
3934 printed in native-bit format on a workstation which stores 8 byte real values\n\
3935 in IEEE format with the least significant byte first.\n\
3938 The same as @code{native-bit}, but always print the most significant\n\
3942 Print a rational approximation, i.e., values are approximated\n\
3943 as the ratio of small integers.\n\
3944 For example, with the @samp{rat} format,\n\
3945 @code{pi} is displayed as @code{355/113}.\n\
3948 The following two options affect the display of all matrices.\n\
3952 Remove blank lines around column number labels and between\n\
3953 matrices producing more compact output with more data per page.\n\
3956 Insert blank lines above and below column number labels and between matrices\n\
3957 to produce a more readable output with less data per page. (default).\n\
3959 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, rats}\n\
3964 int argc = args.
length () + 1;
3976 DEFUN (fixed_point_format, args, nargout,
3978 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\
3979 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\
3980 @deftypefnx {Built-in Function} {} fixed_point_format (@var{new_val}, \"local\")\n\
3981 Query or set the internal variable that controls whether Octave will\n\
3982 use a scaled format to print matrix values such that the largest\n\
3983 element may be written with a single leading digit with the scaling\n\
3984 factor is printed on the first line of output. For example:\n\
3988 octave:1> logspace (1, 7, 5)'\n\
4002 Notice that first value appears to be zero when it is actually 1. For\n\
4003 this reason, you should be careful when setting\n\
4004 @code{fixed_point_format} to a nonzero value.\n\
4006 When called from inside a function with the @qcode{\"local\"} option, the\n\
4007 variable is changed locally for the function and any subroutines it calls. \n\
4008 The original variable value is restored when exiting the function.\n\
4009 @seealso{format, output_max_field_width, output_precision}\n\
4015 DEFUN (print_empty_dimensions, args, nargout,
4017 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\
4018 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\
4019 @deftypefnx {Built-in Function} {} print_empty_dimensions (@var{new_val}, \"local\")\n\
4020 Query or set the internal variable that controls whether the\n\
4021 dimensions of empty matrices are printed along with the empty matrix\n\
4022 symbol, @samp{[]}. For example, the expression\n\
4035 When called from inside a function with the @qcode{\"local\"} option, the\n\
4036 variable is changed locally for the function and any subroutines it calls. \n\
4037 The original variable value is restored when exiting the function.\n\
4044 DEFUN (split_long_rows, args, nargout,
4046 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\
4047 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\
4048 @deftypefnx {Built-in Function} {} split_long_rows (@var{new_val}, \"local\")\n\
4049 Query or set the internal variable that controls whether rows of a matrix\n\
4050 may be split when displayed to a terminal window. If the rows are split,\n\
4051 Octave will display the matrix in a series of smaller pieces, each of\n\
4052 which can fit within the limits of your terminal width and each set of\n\
4053 rows is labeled so that you can easily see which columns are currently\n\
4054 being displayed. For example:\n\
4058 octave:13> rand (2,10)\n\
4061 Columns 1 through 6:\n\
4063 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\
4064 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\
4066 Columns 7 through 10:\n\
4068 0.90174 0.11854 0.72313 0.73326\n\
4069 0.44672 0.94303 0.56564 0.82150\n\
4073 When called from inside a function with the @qcode{\"local\"} option, the\n\
4074 variable is changed locally for the function and any subroutines it calls. \n\
4075 The original variable value is restored when exiting the function.\n\
4082 DEFUN (output_max_field_width, args, nargout,
4084 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\
4085 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\
4086 @deftypefnx {Built-in Function} {} output_max_field_width (@var{new_val}, \"local\")\n\
4087 Query or set the internal variable that specifies the maximum width\n\
4088 of a numeric output field.\n\
4090 When called from inside a function with the @qcode{\"local\"} option, the\n\
4091 variable is changed locally for the function and any subroutines it calls. \n\
4092 The original variable value is restored when exiting the function.\n\
4093 @seealso{format, fixed_point_format, output_precision}\n\
4100 DEFUN (output_precision, args, nargout,
4102 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\
4103 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\
4104 @deftypefnx {Built-in Function} {} output_precision (@var{new_val}, \"local\")\n\
4105 Query or set the internal variable that specifies the minimum number of\n\
4106 significant figures to display for numeric output.\n\
4108 When called from inside a function with the @qcode{\"local\"} option, the\n\
4109 variable is changed locally for the function and any subroutines it calls. \n\
4110 The original variable value is restored when exiting the function.\n\
4111 @seealso{format, fixed_point_format, output_max_field_width}\n\