23 #if defined (HAVE_CONFIG_H)
144 : fw (
w), ex (0), prec (
p), fmt (
f), up (0), sp (0) { }
147 : fw (w), ex (e), prec (p), fmt (f), up (0), sp (0) { }
150 : fw (ff.fw), ex (ff.ex), prec (ff.prec), fmt (ff.fmt), up (ff.up),
182 { sp = tz ? std::ios::showpoint : 0;
return *
this; }
184 friend std::ostream&
operator << (std::ostream& os,
187 friend std::ostream&
operator << (std::ostream& os,
190 friend std::ostream&
operator << (std::ostream& os,
220 return x - 3*
static_cast<int> (x/3);
244 double absval = (x < 0.0 ? -x :
x);
245 int logabsval =
static_cast<int> (
std::floor (log10 (absval)));
249 ex = logabsval - 2 + ((-logabsval + 2) % 3);
251 ex = logabsval - (logabsval % 3);
259 return 1 + (print_eng
280 return val /
std::pow (10.0, exponent ());
284 : f (f_arg), val (val_arg) { }
293 os << std::setw (pef.
f.
fw - pef.
f.
ex);
296 os << std::setprecision (pef.
f.
prec);
298 os.flags (static_cast<std::ios::fmtflags>
306 os << std::setw (0) <<
"e-";
310 os << std::setw (0) <<
"e+";
312 os << std::setw (pef.
f.
ex - 2) << std::setfill (
'0') << ex;
327 : f (f_arg), val (val_arg) { }
336 os << std::setw (pff.
f.
fw);
339 os << std::setprecision (pff.
f.
prec);
341 os.flags (static_cast<std::ios::fmtflags>
365 std::ostringstream buf;
366 buf.flags (std::ios::fixed);
376 double frac = val - n;
379 std::ostringstream buf2;
380 buf2.flags (std::ios::fixed);
381 buf2 << std::setprecision (0) << static_cast<int>(n);
386 double flip = 1. / frac;
400 n = step * n + lastn;
401 d = step * d + lastd;
405 std::ostringstream buf;
406 buf.flags (std::ios::fixed);
407 buf << std::setprecision (0) << static_cast<int>(n)
408 <<
"/" << static_cast<int>(d);
414 if (buf.str ().length () >
static_cast<unsigned int>(len + 2))
417 else if (buf.str ().length () >
static_cast<unsigned int>(len))
432 std::ostringstream buf;
433 buf.flags (std::ios::fixed);
434 buf << std::setprecision (0) << static_cast<int>(lastn)
435 <<
"/" << static_cast<int>(lastd);
467 : f (f_arg), val (val_arg) { }
475 int fw = (rat_string_len > 0 ? rat_string_len : prf.
f.
fw);
479 os << std::setw (fw);
481 os.flags (static_cast<std::ios::fmtflags>
484 if (fw > 0 && s.length () >
static_cast<unsigned int>(fw))
507 bool all_inf_or_nan =
true;
516 all_inf_or_nan =
false;
536 bool all_inf_or_nan =
true;
545 all_inf_or_nan =
false;
573 else if (bank_format)
575 fw = digits < 0 ? 5 : digits + 4;
576 if (inf_or_nan && fw < 5)
590 else if (inf_or_nan || int_only)
593 if (inf_or_nan && fw < 4)
602 rd = prec > digits ? prec - digits : prec;
607 rd = prec > digits ? prec - digits : prec;
610 fw = 1 + ld + 1 + rd;
611 if (inf_or_nan && fw < 4)
615 if (! (rat_format || bank_format || hex_format || bit_format)
616 && (fw > Voutput_max_field_width || print_e || print_g ||
print_eng))
629 if (inf_or_nan && fw < 6)
637 if (inf_or_nan && fw < 4)
639 fmt =
float_format (fw, ex, prec - 1, std::ios::scientific);
646 else if (! bank_format && (inf_or_nan || int_only))
651 curr_real_fmt = &fmt;
667 double d_abs = d < 0.0 ? -d :
d;
669 int digits = (inf_or_nan || d_abs == 0.0) ? 0 :
num_digits (d_abs);
683 int int_or_inf_or_nan,
int& fw)
696 else if (bank_format)
698 int digits = x_max > x_min ? x_max : x_min;
699 fw = digits <= 0 ? 5 : digits + 4;
700 if (inf_or_nan && fw < 5)
714 else if (Vfixed_point_format && ! print_g)
718 if (inf_or_nan && fw < 4)
721 else if (int_or_inf_or_nan)
723 int digits = x_max > x_min ? x_max : x_min;
724 fw = digits <= 0 ? 2 : digits + 1;
725 if (inf_or_nan && fw < 4)
735 rd_max = prec > x_max ? prec - x_max : prec;
741 rd_max = prec > x_max ? prec - x_max : prec;
749 rd_min = prec > x_min ? prec - x_min : prec;
755 rd_min = prec > x_min ? prec - x_min : prec;
759 ld = ld_max > ld_min ? ld_max : ld_min;
760 rd = rd_max > rd_min ? rd_max : rd_min;
762 fw = 1 + ld + 1 + rd;
763 if (inf_or_nan && fw < 4)
767 if (! (rat_format || bank_format || hex_format || bit_format)
769 || print_eng || print_g
777 if (x_max > 100 || x_min > 100)
783 if (inf_or_nan && fw < 6)
790 if (inf_or_nan && fw < 4)
792 fmt =
float_format (fw, prec - 1, std::ios::scientific);
799 else if (! bank_format && int_or_inf_or_nan)
804 curr_real_fmt = &fmt;
824 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
826 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
828 scale = (x_max == 0 || int_or_inf_or_nan)
844 int int_only,
int& r_fw,
int& i_fw)
859 else if (bank_format)
863 r_fw = digits <= 0 ? 5 : digits + 4;
864 if (inf_or_nan && r_fw < 5)
870 r_fw = 2 *
sizeof (
double);
871 i_fw = 2 *
sizeof (
double);
876 r_fw = 8 *
sizeof (
double);
877 i_fw = 8 *
sizeof (
double);
880 else if (inf_or_nan || int_only)
882 int digits = x_max > x_min ? x_max : x_min;
883 i_fw = digits <= 0 ? 1 : digits;
885 if (inf_or_nan && i_fw < 3)
898 rd_max = prec > x_max ? prec - x_max : prec;
904 rd_max = prec > x_max ? prec - x_max : prec;
912 rd_min = prec > x_min ? prec - x_min : prec;
918 rd_min = prec > x_min ? prec - x_min : prec;
922 ld = ld_max > ld_min ? ld_max : ld_min;
923 rd = rd_max > rd_min ? rd_max : rd_min;
927 if (inf_or_nan && i_fw < 3)
934 if (! (rat_format || bank_format || hex_format || bit_format)
935 && (r_fw > Voutput_max_field_width || print_e || print_eng ||
print_g))
945 if (x_max > 100 || x_min > 100)
950 i_fw = 3 + prec + ex;
952 if (inf_or_nan && i_fw < 5)
957 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
958 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
962 i_fw = 1 + prec + ex;
964 if (inf_or_nan && i_fw < 3)
969 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
970 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
980 else if (! bank_format && (inf_or_nan || int_only))
991 curr_real_fmt = &r_fmt;
992 curr_imag_fmt = &i_fmt;
1004 double rp = c.real ();
1005 double ip = c.imag ();
1012 double r_abs = rp < 0.0 ? -rp : rp;
1013 double i_abs = ip < 0.0 ? -ip : ip;
1046 int r_x_min,
bool inf_or_nan,
1047 int int_or_inf_or_nan,
int& r_fw,
int& i_fw)
1062 else if (bank_format)
1064 int digits = r_x_max > r_x_min ? r_x_max : r_x_min;
1066 r_fw = digits <= 0 ? 5 : digits + 4;
1067 if (inf_or_nan && r_fw < 5)
1071 else if (hex_format)
1073 r_fw = 2 *
sizeof (
double);
1074 i_fw = 2 *
sizeof (
double);
1077 else if (bit_format)
1079 r_fw = 8 *
sizeof (
double);
1080 i_fw = 8 *
sizeof (
double);
1083 else if (Vfixed_point_format && ! print_g)
1088 if (inf_or_nan && i_fw < 3)
1094 else if (int_or_inf_or_nan)
1096 int digits = x_max > x_min ? x_max : x_min;
1097 i_fw = digits <= 0 ? 1 : digits;
1099 if (inf_or_nan && i_fw < 3)
1112 rd_max = prec > x_max ? prec - x_max : prec;
1118 rd_max = prec > x_max ? prec - x_max : prec;
1126 rd_min = prec > x_min ? prec - x_min : prec;
1132 rd_min = prec > x_min ? prec - x_min : prec;
1136 ld = ld_max > ld_min ? ld_max : ld_min;
1137 rd = rd_max > rd_min ? rd_max : rd_min;
1141 if (inf_or_nan && i_fw < 3)
1148 if (! (rat_format || bank_format || hex_format || bit_format)
1150 || print_eng || print_g
1161 if (x_max > 100 || x_min > 100)
1166 i_fw = 3 + prec + ex;
1168 if (inf_or_nan && i_fw < 5)
1173 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
1174 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
1178 i_fw = 1 + prec + ex;
1180 if (inf_or_nan && i_fw < 3)
1185 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
1186 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
1196 else if (! bank_format && int_or_inf_or_nan)
1207 curr_real_fmt = &r_fmt;
1208 curr_imag_fmt = &i_fmt;
1236 int r_x_max = r_max_abs == 0.0 ? 0 :
num_digits (r_max_abs);
1238 int r_x_min = r_min_abs == 0.0 ? 0 :
num_digits (r_min_abs);
1240 int i_x_max = i_max_abs == 0.0 ? 0 :
num_digits (i_max_abs);
1242 int i_x_min = i_min_abs == 0.0 ? 0 :
num_digits (i_min_abs);
1244 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
1245 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
1247 scale = (x_max == 0 || int_or_inf_or_nan)
1251 int_or_inf_or_nan, r_fw, i_fw);
1276 else if (bank_format)
1278 int digits = x_max > x_min ? x_max : x_min;
1279 fw = digits < 0 ? 5 : digits + 4;
1282 else if (hex_format)
1284 fw = 2 *
sizeof (
double);
1287 else if (bit_format)
1289 fw = 8 *
sizeof (
double);
1294 int digits = x_max > x_min ? x_max : x_min;
1298 else if (Vfixed_point_format && ! print_g)
1309 rd_max = prec > x_max ? prec - x_max : prec;
1315 rd_max = prec > x_max ? prec - x_max : prec;
1323 rd_min = prec > x_min ? prec - x_min : prec;
1329 rd_min = prec > x_min ? prec - x_min : prec;
1333 ld = ld_max > ld_min ? ld_max : ld_min;
1334 rd = rd_max > rd_min ? rd_max : rd_min;
1339 if (! (rat_format || bank_format || hex_format || bit_format)
1341 || print_eng || print_g
1349 if (x_max > 100 || x_min > 100)
1355 fmt =
float_format (fw, ex, prec - 1, std::ios::fixed);
1360 fmt =
float_format (fw, prec - 1, std::ios::scientific);
1367 else if (! bank_format && all_ints)
1372 curr_real_fmt = &fmt;
1384 double r_min = r.
base ();
1385 double r_max = r.
limit ();
1396 double max_abs = r_max < 0.0 ? -r_max : r_max;
1397 double min_abs = r_min < 0.0 ? -r_min : r_min;
1399 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
1401 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
1403 scale = (x_max == 0 || all_ints)
1423 #define PRINT_CHAR_BITS(os, c) \
1426 unsigned char ctmp = c; \
1428 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
1429 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
1430 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
1431 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
1432 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
1433 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
1434 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
1435 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
1441 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
1444 unsigned char ctmp = c; \
1446 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
1447 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
1448 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
1449 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
1450 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
1451 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
1452 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
1453 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
1492 for (
size_t i = 0;
i <
sizeof (
double);
i++)
1493 os << std::setw (2) <<
static_cast<int> (tmp.
i[
i]);
1497 for (
int i =
sizeof (
double) - 1;
i >= 0;
i--)
1498 os << std::setw (2) <<
static_cast<int> (tmp.
i[
i]);
1501 else if (bit_format)
1511 for (
size_t i = 0;
i <
sizeof (
double);
i++)
1518 for (
size_t i = 0;
i <
sizeof (
double);
i++)
1523 for (
int i =
sizeof (
double) - 1;
i >= 0;
i--)
1533 os << std::setw (fw) <<
"NA";
1537 else if (rat_format)
1550 os << std::setw (fw) <<
s;
1559 os << std::setw (fw) <<
"NaN";
1575 if (Vfixed_point_format && ! print_g &&
scale != 1.0)
1589 int i_fw = 0,
double scale = 1.0)
1592 = (Vfixed_point_format && ! print_g &&
scale != 1.0) ? c /
scale :
c;
1594 double r = tmp.real ();
1600 double i = tmp.imag ();
1609 if (hex_format || bit_format)
1622 bool pr_as_read_syntax)
1624 assert (nr == 0 || nc == 0);
1626 if (pr_as_read_syntax)
1628 if (nr == 0 && nc == 0)
1631 os <<
"zeros (" << nr <<
", " << nc <<
")";
1637 if (Vprint_empty_dimensions)
1638 os <<
"(" << nr <<
"x" << nc <<
")";
1644 bool pr_as_read_syntax)
1648 if (pr_as_read_syntax)
1649 os <<
"zeros (" << dims.
str (
',') <<
")";
1654 if (Vprint_empty_dimensions)
1655 os <<
"(" << dims.
str () <<
")";
1662 if (Vfixed_point_format && ! print_g && scale != 1.0)
1667 << std::setw (8) << std::setprecision (1)
1672 if (! Vcompact_format)
1681 if (total_width > max_width && Vsplit_long_rows)
1687 if (Vcompact_format)
1695 os << std::setw (extra_indent) <<
"";
1698 os <<
" Column " << col + 1 <<
":\n";
1699 else if (num_cols == 2)
1700 os <<
" Columns " << col + 1 <<
" and " << lim <<
":\n";
1702 os <<
" Columns " << col + 1 <<
" through " << lim <<
":\n";
1704 if (! Vcompact_format)
1709 template <
typename T>
1715 else if (val < T (0))
1716 os << plus_format_chars[1];
1718 os << plus_format_chars[2];
1729 bool pr_as_read_syntax)
1731 if (pr_as_read_syntax)
1733 else if (plus_format)
1747 bool pr_as_read_syntax,
int extra_indent)
1752 if (nr == 0 || nc == 0)
1754 else if (plus_format && ! pr_as_read_syntax)
1774 int column_width = fw + 2;
1778 if (pr_as_read_syntax)
1781 max_width -= extra_indent;
1788 if (pr_as_read_syntax)
1793 if (pr_as_read_syntax)
1800 if (total_width > max_width && Vsplit_long_rows)
1802 inc = max_width / column_width;
1807 if (pr_as_read_syntax)
1820 if (
i == 0 && j == 0)
1824 if (j > col && j < lim)
1862 os << std::setw (extra_indent) <<
"";
1883 bool pr_as_read_syntax,
int extra_indent)
1888 if (nr == 0 || nc == 0)
1890 else if (plus_format && ! pr_as_read_syntax)
1910 int column_width = fw + 2;
1914 if (pr_as_read_syntax)
1917 max_width -= extra_indent;
1924 if (pr_as_read_syntax)
1929 if (pr_as_read_syntax)
1936 if (total_width > max_width && Vsplit_long_rows)
1938 inc = max_width / column_width;
1943 if (pr_as_read_syntax)
1960 if (j > col && j < lim)
1982 os <<
"Diagonal Matrix\n";
1983 if (! Vcompact_format)
1992 std::ostringstream tmp_oss;
1993 pr_float (tmp_oss, 0.0, fw, scale);
1994 zero_fw = tmp_oss.str ().length ();
2006 os << std::setw (extra_indent) <<
"";
2017 os << std::setw (zero_fw) <<
'0';
2029 template <
typename NDA_T,
typename ELT_T,
typename MAT_T>
2031 bool pr_as_read_syntax)
2034 if (nda.is_empty ())
2039 int ndims = nda.ndims ();
2047 for (
int i = 2;
i < ndims;
i++)
2063 std::ostringstream buf;
2065 for (
int k = 2;
k < ndims;
k++)
2083 for (
int k = 2;
k < ndims;
k++)
2107 bool pr_as_read_syntax,
int extra_indent)
2109 switch (nda.
ndims ())
2114 pr_as_read_syntax, extra_indent);
2118 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax);
2127 double rp =
c.real ();
2128 double ip =
c.imag ();
2145 bool pr_as_read_syntax)
2147 if (pr_as_read_syntax)
2149 else if (plus_format)
2163 bool pr_as_read_syntax,
int extra_indent)
2168 if (nr == 0 || nc == 0)
2170 else if (plus_format && ! pr_as_read_syntax)
2190 int column_width = i_fw + r_fw;
2191 column_width += (rat_format || bank_format || hex_format
2196 if (pr_as_read_syntax)
2199 max_width -= extra_indent;
2206 if (pr_as_read_syntax)
2211 if (pr_as_read_syntax)
2218 if (total_width > max_width && Vsplit_long_rows)
2220 inc = max_width / column_width;
2225 if (pr_as_read_syntax)
2238 if (
i == 0 && j == 0)
2242 if (j > col && j < lim)
2280 os << std::setw (extra_indent) <<
"";
2301 bool pr_as_read_syntax,
int extra_indent)
2306 if (nr == 0 || nc == 0)
2308 else if (plus_format && ! pr_as_read_syntax)
2328 int column_width = i_fw + r_fw;
2329 column_width += (rat_format || bank_format || hex_format
2334 if (pr_as_read_syntax)
2337 max_width -= extra_indent;
2344 if (pr_as_read_syntax)
2349 if (pr_as_read_syntax)
2356 if (total_width > max_width && Vsplit_long_rows)
2358 inc = max_width / column_width;
2363 if (pr_as_read_syntax)
2380 if (j > col && j < lim)
2402 os <<
"Diagonal Matrix\n";
2403 if (! Vcompact_format)
2412 std::ostringstream tmp_oss;
2414 zero_fw = tmp_oss.str ().length ();
2426 os << std::setw (extra_indent) <<
"";
2437 os << std::setw (zero_fw) <<
'0';
2450 bool pr_as_read_syntax,
int extra_indent)
2455 if (nr == 0 || nc == 0)
2457 else if (plus_format && ! pr_as_read_syntax)
2475 int column_width = fw + 2;
2479 if (pr_as_read_syntax)
2482 max_width -= extra_indent;
2489 if (pr_as_read_syntax)
2494 if (pr_as_read_syntax)
2501 if (total_width > max_width && Vsplit_long_rows)
2503 inc = max_width / column_width;
2508 if (pr_as_read_syntax)
2528 if (j > col && j < lim)
2550 os <<
"Permutation Matrix\n";
2551 if (! Vcompact_format)
2563 os << std::setw (extra_indent) <<
"";
2571 os << std::setw (fw) <<
m(
i,j);
2584 bool pr_as_read_syntax,
int extra_indent)
2586 switch (nda.
ndims ())
2591 pr_as_read_syntax, extra_indent);
2595 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
2596 (os, nda, pr_as_read_syntax);
2617 bool pr_as_read_syntax,
int extra_indent)
2624 bool pr_as_read_syntax,
int extra_indent)
2631 bool pr_as_read_syntax,
int extra_indent)
2638 bool pr_as_read_syntax)
2645 bool pr_as_read_syntax,
int extra_indent)
2653 bool pr_as_read_syntax,
int extra_indent)
2661 bool pr_as_read_syntax,
int extra_indent)
2669 bool pr_as_read_syntax,
int extra_indent)
2671 double base = r.
base ();
2672 double increment = r.
inc ();
2673 double limit = r.
limit ();
2676 if (plus_format && ! pr_as_read_syntax)
2682 double val = base +
i * increment;
2693 if (pr_as_read_syntax)
2697 os << base <<
" : ";
2698 if (increment != 1.0)
2699 os << increment <<
" : ";
2706 if (increment != 1.0)
2718 int column_width = fw + 2;
2729 if (total_width > max_width && Vsplit_long_rows)
2731 inc = max_width / column_width;
2736 max_width -= extra_indent;
2744 while (col < num_elem)
2751 os << std::setw (extra_indent) <<
"";
2761 val = base +
i * increment;
2763 if (
i == num_elem - 1)
2766 if ((increment > 0 && val >= limit)
2767 || (increment < 0 && val <= limit))
2784 bool pr_as_read_syntax,
2793 bool pr_as_read_syntax,
2796 switch (nda.
ndims ())
2801 pr_as_read_syntax, extra_indent);
2813 bool pr_as_read_syntax,
2821 if (pr_as_read_syntax && nstr > 1)
2832 if (pr_as_read_syntax)
2849 if (pr_as_read_syntax && nstr > 1)
2854 os <<
"sorry, printing char matrices not implemented yet\n";
2860 bool pr_as_read_syntax,
int extra_indent,
2863 switch (nda.
ndims ())
2868 pr_as_read_syntax, extra_indent, pr_as_string);
2872 print_nd_array <charNDArray, char, charMatrix> (os, nda,
2880 bool pr_as_read_syntax,
int extra_indent)
2889 bool pr_as_read_syntax,
int )
2896 else if (nda.
numel () == 1)
2902 int ndims = nda.
ndims ();
2910 for (
int i = 2;
i < ndims;
i++)
2924 std::ostringstream buf;
2926 for (
int k = 2;
k < ndims;
k++)
2944 for (
int k = 2;
k < ndims;
k++)
2956 if (! Vcompact_format)
2962 os <<
" " <<
page(ii,jj);
2976 template <
typename T>
2984 #define PRINT_CONV(T1, T2) \
2987 octave_print_conv<T1> \
2990 typedef T2 print_conv_type; \
2998 template <
typename T>
3002 size_t sz = d.byte_size ();
3003 const unsigned char * tmpi = d.iptr ();
3019 for (
size_t i = 0;
i <
sz;
i++)
3020 os << std::setw (2) <<
static_cast<int> (tmpi[
i]);
3024 for (
int i = sz - 1;
i >= 0;
i--)
3025 os << std::setw (2) <<
static_cast<int> (tmpi[
i]);
3028 else if (bit_format)
3032 for (
size_t i = 0;
i <
sz;
i++)
3039 for (
size_t i = 0;
i <
sz;
i++)
3044 for (
int i = sz - 1;
i >= 0;
i--)
3053 os << std::setw (fw)
3067 template <
typename T>
3071 return x < 0 ? -x :
x;
3074 #define INSTANTIATE_ABS(T) \
3083 #define SPECIALIZE_UABS(T) \
3086 abs (unsigned T x) \
3121 template <typename T>
3133 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val);
3139 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
3140 OCTINTERP_API void \
3141 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \
3143 octave_print_internal_template (os, val, dummy); \
3155 template <typename T>
3158 bool pr_as_read_syntax,
int extra_indent)
3163 if (nda.is_empty ())
3165 else if (nda.numel () == 1)
3167 else if (plus_format && ! pr_as_read_syntax)
3169 int ndims = nda.ndims ();
3177 for (
int i = 2;
i < ndims;
i++)
3189 std::ostringstream buf;
3191 for (
int k = 2;
k < ndims;
k++)
3204 if (! Vcompact_format)
3213 for (
int k = 2;
k < ndims;
k++)
3227 if ((ii < nr - 1) || (
i < m -1))
3240 int ndims = nda.ndims ();
3248 for (
int i = 2;
i < ndims;
i++)
3256 fw = 2 * nda(0).byte_size ();
3257 else if (bit_format)
3258 fw = nda(0).nbits ();
3270 if (new_digits > digits)
3271 digits = new_digits;
3274 isneg = (
abs (nda(
i).
value ()) != nda(
i).value ());
3277 fw = digits + isneg;
3280 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2));
3284 if (total_width > max_width && Vsplit_long_rows)
3286 inc = max_width / column_width;
3297 std::ostringstream buf;
3299 for (
int k = 2;
k < ndims;
k++)
3312 if (! Vcompact_format)
3321 for (
int k = 2;
k < ndims;
k++)
3328 if (pr_as_read_syntax)
3337 os << typename octave_print_conv<T>::print_conv_type (
page(ii,jj));
3342 if (pr_as_read_syntax)
3361 os << std::setw (extra_indent) <<
"";
3369 if ((ii < n_rows - 1) || (
i < m -1))
3384 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
3385 OCTINTERP_API void \
3386 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \
3387 bool pr_as_read_syntax, int extra_indent) \
3389 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
3437 if (nargin < 1 || nargin > 2)
3443 error (
"rats: X must be numeric");
3451 rat_string_len =
args(1).nint_value ();
3457 std::ostringstream buf;
3461 std::list<std::string> lst;
3464 size_t s_len = s.length ();
3468 size_t m = s.find (
'\n', n);
3470 if (m == std::string::npos)
3472 lst.push_back (s.substr (n));
3477 lst.push_back (s.substr (n, m - n));
3509 if (
args.length () != 1)
3520 std::ostringstream buf;
3549 if (
args.length () != 2)
3563 error (
"fdisp: stream FID not open for writing");
3596 init_format_state (
void)
3598 free_format =
false;
3599 plus_format =
false;
3601 bank_format =
false;
3604 Vcompact_format =
false;
3606 print_big_e =
false;
3612 set_output_prec_and_fw (
int prec,
int fw)
3614 Voutput_precision = prec;
3615 Voutput_max_field_width = fw;
3640 init_format_state ();
3643 else if (arg ==
"E")
3645 init_format_state ();
3649 else if (arg ==
"g")
3651 init_format_state ();
3654 else if (arg ==
"G")
3656 init_format_state ();
3660 else if (arg ==
"eng")
3662 init_format_state ();
3666 error (
"format: unrecognized option 'short %s'", arg.c_str ());
3669 init_format_state ();
3671 set_output_prec_and_fw (5, 10);
3673 else if (arg ==
"shorte")
3675 init_format_state ();
3677 set_output_prec_and_fw (5, 10);
3679 else if (arg ==
"shortE")
3681 init_format_state ();
3684 set_output_prec_and_fw (5, 10);
3686 else if (arg ==
"shortg")
3688 init_format_state ();
3690 set_output_prec_and_fw (5, 10);
3692 else if (arg ==
"shortG")
3694 init_format_state ();
3697 set_output_prec_and_fw (5, 10);
3699 else if (arg ==
"shortEng")
3701 init_format_state ();
3703 set_output_prec_and_fw (5, 10);
3705 else if (arg ==
"long")
3714 init_format_state ();
3717 else if (arg ==
"E")
3719 init_format_state ();
3723 else if (arg ==
"g")
3725 init_format_state ();
3728 else if (arg ==
"G")
3730 init_format_state ();
3734 else if (arg ==
"eng")
3736 init_format_state ();
3740 error (
"format: unrecognized option 'long %s'", arg.c_str ());
3743 init_format_state ();
3745 set_output_prec_and_fw (15, 20);
3747 else if (arg ==
"longe")
3749 init_format_state ();
3751 set_output_prec_and_fw (15, 20);
3753 else if (arg ==
"longE")
3755 init_format_state ();
3758 set_output_prec_and_fw (15, 20);
3760 else if (arg ==
"longg")
3762 init_format_state ();
3764 set_output_prec_and_fw (15, 20);
3766 else if (arg ==
"longG")
3768 init_format_state ();
3771 set_output_prec_and_fw (15, 20);
3773 else if (arg ==
"longEng")
3775 init_format_state ();
3777 set_output_prec_and_fw (15, 20);
3779 else if (arg ==
"hex")
3781 init_format_state ();
3784 else if (arg ==
"native-hex")
3786 init_format_state ();
3789 else if (arg ==
"bit")
3791 init_format_state ();
3794 else if (arg ==
"native-bit")
3796 init_format_state ();
3799 else if (arg ==
"+" || arg ==
"plus")
3806 if (arg.length () == 3)
3809 error (
"format: invalid option for plus format");
3814 init_format_state ();
3817 else if (arg ==
"rat")
3819 init_format_state ();
3822 else if (arg ==
"bank")
3824 init_format_state ();
3827 else if (arg ==
"free")
3829 init_format_state ();
3832 else if (arg ==
"none")
3834 init_format_state ();
3837 else if (arg ==
"compact")
3839 Vcompact_format =
true;
3842 else if (arg ==
"loose")
3844 Vcompact_format =
false;
3848 error (
"format: unrecognized format state '%s'", arg.c_str ());
3852 init_format_state ();
3853 set_output_prec_and_fw (5, 10);
4052 DEFUN (__formatstring__, , ,
4058 return ovl (format_string);
static int rat_string_len
static int Voutput_max_field_width
std::ostream & operator<<(std::ostream &os, const pr_engineering_float &pef)
#define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL)
bool is_empty(void) const
unsigned char i[sizeof(double)]
std::string str(char sep= 'x') const
double mantissa(void) const
#define PRINT_INT_SCALAR_INTERNAL(TYPE)
bool print_name_tag(std::ostream &os, const std::string &name) const
#define PRINT_CHAR_BITS_SWAPPED(os, c)
const octave_base_value const Array< octave_idx_type > & ra_idx
#define SPECIALIZE_UABS(T)
octave_idx_type rows(void) const
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
static int calc_scale_exp(const int &x)
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
OCTINTERP_API std::string undo_string_escapes(const std::string &s)
static float_format * curr_imag_fmt
pr_engineering_float(const float_format &f_arg, double val_arg)
if(!arg.is_numeric_type()) error("rats return retval
bool is_numeric_type(void) const
static void pr_any_float(const float_format *fmt, std::ostream &os, double d, int fw=0)
OCTAVE_EXPORT octave_value_list page
static void pr_imag_float(std::ostream &os, double d, int fw=0)
static void print_empty_matrix(std::ostream &os, octave_idx_type nr, octave_idx_type nc, bool pr_as_read_syntax)
#define DEFUN(name, args_name, nargout_name, doc)
static bool Vfixed_point_format
void error(const char *fmt,...)
octave_idx_type rows(void) const
#define SET_INTERNAL_VARIABLE(NM)
#define lo_ieee_signbit(x)
octave::mach_info::float_format flt_fmt
static void pr_complex(std::ostream &os, const Complex &c, int r_fw=0, int i_fw=0, double scale=1.0)
void print_nd_array(std::ostream &os, const NDA_T &nda, bool pr_as_read_syntax)
octave_idx_type columns(void) const
in this the arguments are accumulated from left to right
static int num_digits(const double &x)
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
octave_idx_type rows(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
static double pr_max_internal(const Matrix &m)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
static int Voutput_precision
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
static float_format * curr_real_fmt
void octave_print_internal_template(std::ostream &os, const octave_int< T > &val, bool)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
static int current_output_precision(void)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
static bool words_big_endian(void)
void pr_int(std::ostream &os, const T &d, int fw=0)
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
static void set_real_matrix_format(int x_max, int x_min, bool inf_or_nan, int int_or_inf_or_nan, int &fw)
void print(std::ostream &os, bool pr_as_read_syntax=false)
const Array< octave_idx_type > & col_perm_vec(void) const
nd deftypefn *octave_map m
static int current_output_max_field_width(void)
static void set_real_format(int digits, bool inf_or_nan, bool int_only, int &fw)
#define PRINT_CONV(T1, T2)
std::complex< double > w(std::complex< double > z, double relerr=0)
static void set_format_style(int argc, const string_vector &argv)
static double pr_min_internal(const Matrix &m)
octave_idx_type numel(void) const
string_vector & append(const std::string &s)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
#define panic_impossible()
static void pr_scale_header(std::ostream &os, double scale)
#define PRINT_INT_ARRAY_INTERNAL(TYPE)
static octave_stream lookup(int fid, const std::string &who="")
std::ostream * output_stream(void)
static std::string plus_format_chars
bool any_element_is_inf_or_nan(void) const
bool any_zero(void) const
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
static void set_complex_matrix_format(int x_max, int x_min, int r_x_max, int r_x_min, bool inf_or_nan, int int_or_inf_or_nan, int &r_fw, int &i_fw)
MArray< T > diag(octave_idx_type k=0) const
With real return the complex result
void pr_plus_format(std::ostream &os, const T &val)
#define PRINT_CHAR_BITS(os, c)
static bool Vsplit_long_rows
static float_format native_float_format(void)
bool all_elements_are_int_or_inf_or_nan(void) const
octave::unwind_protect frame
static void set_complex_format(int x_max, int x_min, int r_x, bool inf_or_nan, int int_only, int &r_fw, int &i_fw)
charNDArray max(char d, const charNDArray &m)
bool Vprint_empty_dimensions
#define INSTANTIATE_ABS(T)
static void print_empty_nd_array(std::ostream &os, const dim_vector &dims, bool pr_as_read_syntax)
bool is_dq_string(void) const
=val(i)}if ode{val(i)}occurs in table i
static void pr_col_num_header(std::ostream &os, octave_idx_type total_width, int max_width, octave_idx_type lim, octave_idx_type col, int extra_indent)
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
static void set_range_format(int x_max, int x_min, int all_ints, int &fw)
static int engineering_exponent(const double &x)
void octave_print_internal(std::ostream &, char, bool)
octave_idx_type columns(void) const
issues an error eealso double
bool all_elements_are_ints(void) const
void print_with_name(std::ostream &os, const std::string &name) const
void scale(Matrix &m, double x, double y, double z)
bool any_element_is_inf_or_nan(void) const
static std::string rational_approx(double val, int len)
ColumnVector imag(const ComplexColumnVector &a)
std::complex< float > FloatComplex
static int terminal_cols(void)
std::complex< double > Complex
ColumnVector real(const ComplexColumnVector &a)
Vector representing the dimensions (size) of an Array.
static int get_file_number(const octave_value &fid)
static void pr_float(std::ostream &os, double d, int fw=0, double scale=1.0)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
octave_idx_type columns(void) const
static void set_format(double d, int &fw)
pr_rational_float(const float_format &f_arg, double val_arg)
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
Array< T > index(const idx_vector &i) const
Indexing without resizing.
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
charNDArray min(char d, const charNDArray &m)