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);
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);
396 n = n * step + lastn;
397 d = d * step + lastd;
401 std::ostringstream buf;
402 buf.flags (std::ios::fixed);
403 buf << std::setprecision (0) << static_cast<int>(n)
404 <<
"/" << static_cast<int>(d);
410 if (buf.str ().length () >
static_cast<unsigned int>(len + 2))
413 else if (buf.str ().length () >
static_cast<unsigned int>(len))
428 std::ostringstream buf;
429 buf.flags (std::ios::fixed);
430 buf << std::setprecision (0) << static_cast<int>(lastn)
431 <<
"/" << static_cast<int>(lastd);
463 : f (f_arg), val (val_arg) { }
471 int fw = (rat_string_len > 0 ? rat_string_len : prf.
f.
fw);
475 os << std::setw (fw);
477 os.flags (static_cast<std::ios::fmtflags>
480 if (fw > 0 && s.length () >
static_cast<unsigned int>(fw))
503 bool all_inf_or_nan =
true;
512 all_inf_or_nan =
false;
532 bool all_inf_or_nan =
true;
541 all_inf_or_nan =
false;
571 fw = digits < 0 ? 5 : digits + 4;
572 if (inf_or_nan && fw < 5)
586 else if (inf_or_nan || int_only)
589 if (inf_or_nan && fw < 4)
598 rd = prec > digits ? prec - digits : prec;
603 rd = prec > digits ? prec - digits : prec;
606 fw = 1 + ld + 1 + rd;
607 if (inf_or_nan && fw < 4)
625 if (inf_or_nan && fw < 6)
633 if (inf_or_nan && fw < 4)
635 fmt =
float_format (fw, ex, prec - 1, std::ios::scientific);
642 else if (!
bank_format && (inf_or_nan || int_only))
647 curr_real_fmt = &fmt;
661 bool int_only = (! inf_or_nan &&
D_NINT (d) ==
d);
663 double d_abs = d < 0.0 ? -d :
d;
665 int digits = (inf_or_nan || d_abs == 0.0) ? 0 :
num_digits (d_abs);
679 int int_or_inf_or_nan,
int& fw)
694 int digits = x_max > x_min ? x_max : x_min;
695 fw = digits <= 0 ? 5 : digits + 4;
696 if (inf_or_nan && fw < 5)
714 if (inf_or_nan && fw < 4)
717 else if (int_or_inf_or_nan)
719 int digits = x_max > x_min ? x_max : x_min;
720 fw = digits <= 0 ? 2 : digits + 1;
721 if (inf_or_nan && fw < 4)
731 rd_max = prec > x_max ? prec - x_max : prec;
737 rd_max = prec > x_max ? prec - x_max : prec;
745 rd_min = prec > x_min ? prec - x_min : prec;
751 rd_min = prec > x_min ? prec - x_min : prec;
755 ld = ld_max > ld_min ? ld_max : ld_min;
756 rd = rd_max > rd_min ? rd_max : rd_min;
758 fw = 1 + ld + 1 + rd;
759 if (inf_or_nan && fw < 4)
773 if (x_max > 100 || x_min > 100)
779 if (inf_or_nan && fw < 6)
786 if (inf_or_nan && fw < 4)
788 fmt =
float_format (fw, prec - 1, std::ios::scientific);
800 curr_real_fmt = &fmt;
820 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
822 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
824 scale = (x_max == 0 || int_or_inf_or_nan)
840 int int_only,
int& r_fw,
int& i_fw)
859 r_fw = digits <= 0 ? 5 : digits + 4;
860 if (inf_or_nan && r_fw < 5)
866 r_fw = 2 *
sizeof (
double);
867 i_fw = 2 *
sizeof (
double);
872 r_fw = 8 *
sizeof (
double);
873 i_fw = 8 *
sizeof (
double);
876 else if (inf_or_nan || int_only)
878 int digits = x_max > x_min ? x_max : x_min;
879 i_fw = digits <= 0 ? 1 : digits;
881 if (inf_or_nan && i_fw < 3)
894 rd_max = prec > x_max ? prec - x_max : prec;
900 rd_max = prec > x_max ? prec - x_max : prec;
908 rd_min = prec > x_min ? prec - x_min : prec;
914 rd_min = prec > x_min ? prec - x_min : prec;
918 ld = ld_max > ld_min ? ld_max : ld_min;
919 rd = rd_max > rd_min ? rd_max : rd_min;
923 if (inf_or_nan && i_fw < 3)
941 if (x_max > 100 || x_min > 100)
946 i_fw = 3 + prec + ex;
948 if (inf_or_nan && i_fw < 5)
953 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
954 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
958 i_fw = 1 + prec + ex;
960 if (inf_or_nan && i_fw < 3)
965 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
966 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
976 else if (!
bank_format && (inf_or_nan || int_only))
987 curr_real_fmt = &r_fmt;
988 curr_imag_fmt = &i_fmt;
1000 double rp = c.real ();
1001 double ip = c.imag ();
1005 bool int_only = (
D_NINT (rp) == rp &&
D_NINT (ip) == ip);
1007 double r_abs = rp < 0.0 ? -rp : rp;
1008 double i_abs = ip < 0.0 ? -ip : ip;
1039 int r_x_min,
bool inf_or_nan,
1040 int int_or_inf_or_nan,
int& r_fw,
int& i_fw)
1057 int digits = r_x_max > r_x_min ? r_x_max : r_x_min;
1059 r_fw = digits <= 0 ? 5 : digits + 4;
1060 if (inf_or_nan && r_fw < 5)
1064 else if (hex_format)
1066 r_fw = 2 *
sizeof (
double);
1067 i_fw = 2 *
sizeof (
double);
1070 else if (bit_format)
1072 r_fw = 8 *
sizeof (
double);
1073 i_fw = 8 *
sizeof (
double);
1081 if (inf_or_nan && i_fw < 3)
1087 else if (int_or_inf_or_nan)
1089 int digits = x_max > x_min ? x_max : x_min;
1090 i_fw = digits <= 0 ? 1 : digits;
1092 if (inf_or_nan && i_fw < 3)
1105 rd_max = prec > x_max ? prec - x_max : prec;
1111 rd_max = prec > x_max ? prec - x_max : prec;
1119 rd_min = prec > x_min ? prec - x_min : prec;
1125 rd_min = prec > x_min ? prec - x_min : prec;
1129 ld = ld_max > ld_min ? ld_max : ld_min;
1130 rd = rd_max > rd_min ? rd_max : rd_min;
1134 if (inf_or_nan && i_fw < 3)
1154 if (x_max > 100 || x_min > 100)
1159 i_fw = 3 + prec + ex;
1161 if (inf_or_nan && i_fw < 5)
1166 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
1167 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
1171 i_fw = 1 + prec + ex;
1173 if (inf_or_nan && i_fw < 3)
1178 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
1179 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
1200 curr_real_fmt = &r_fmt;
1201 curr_imag_fmt = &i_fmt;
1229 int r_x_max = r_max_abs == 0.0 ? 0 :
num_digits (r_max_abs);
1231 int r_x_min = r_min_abs == 0.0 ? 0 :
num_digits (r_min_abs);
1233 int i_x_max = i_max_abs == 0.0 ? 0 :
num_digits (i_max_abs);
1235 int i_x_min = i_min_abs == 0.0 ? 0 :
num_digits (i_min_abs);
1237 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
1238 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
1240 scale = (x_max == 0 || int_or_inf_or_nan)
1244 int_or_inf_or_nan, r_fw, i_fw);
1271 int digits = x_max > x_min ? x_max : x_min;
1272 fw = digits < 0 ? 5 : digits + 4;
1275 else if (hex_format)
1277 fw = 2 *
sizeof (
double);
1280 else if (bit_format)
1282 fw = 8 *
sizeof (
double);
1287 int digits = x_max > x_min ? x_max : x_min;
1302 rd_max = prec > x_max ? prec - x_max : prec;
1308 rd_max = prec > x_max ? prec - x_max : prec;
1316 rd_min = prec > x_min ? prec - x_min : prec;
1322 rd_min = prec > x_min ? prec - x_min : prec;
1326 ld = ld_max > ld_min ? ld_max : ld_min;
1327 rd = rd_max > rd_min ? rd_max : rd_min;
1342 if (x_max > 100 || x_min > 100)
1348 fmt =
float_format (fw, ex, prec - 1, std::ios::fixed);
1353 fmt =
float_format (fw, prec - 1, std::ios::scientific);
1365 curr_real_fmt = &fmt;
1377 double r_min = r.
base ();
1378 double r_max = r.
limit ();
1389 double max_abs = r_max < 0.0 ? -r_max : r_max;
1390 double min_abs = r_min < 0.0 ? -r_min : r_min;
1392 int x_max = max_abs == 0.0 ? 0 :
num_digits (max_abs);
1394 int x_min = min_abs == 0.0 ? 0 :
num_digits (min_abs);
1396 scale = (x_max == 0 || all_ints)
1416 #define PRINT_CHAR_BITS(os, c) \
1419 unsigned char ctmp = c; \
1421 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
1422 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
1423 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
1424 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
1425 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
1426 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
1427 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
1428 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
1434 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
1437 unsigned char ctmp = c; \
1439 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
1440 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
1441 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
1442 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
1443 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
1444 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
1445 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
1446 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
1480 os.flags (std::ios::right | std::ios::hex);
1485 for (
size_t i = 0; i <
sizeof (
double); i++)
1486 os << std::setw (2) <<
static_cast<int> (tmp.
i[i]);
1490 for (
int i =
sizeof (
double) - 1; i >= 0; i--)
1491 os << std::setw (2) <<
static_cast<int> (tmp.
i[i]);
1494 else if (bit_format)
1504 for (
size_t i = 0; i <
sizeof (
double); i++)
1511 for (
size_t i = 0; i <
sizeof (
double); i++)
1516 for (
int i =
sizeof (
double) - 1; i >= 0; i--)
1526 os << std::setw (fw) <<
"NA";
1543 os << std::setw (fw) << s;
1552 os << std::setw (fw) <<
"NaN";
1582 int i_fw = 0,
double scale = 1.0)
1587 double r = tmp.real ();
1593 double i = tmp.imag ();
1602 if (hex_format || bit_format)
1615 bool pr_as_read_syntax)
1617 assert (nr == 0 || nc == 0);
1619 if (pr_as_read_syntax)
1621 if (nr == 0 && nc == 0)
1624 os <<
"zeros (" << nr <<
", " << nc <<
")";
1631 os <<
"(" << nr <<
"x" << nc <<
")";
1637 bool pr_as_read_syntax)
1641 if (pr_as_read_syntax)
1642 os <<
"zeros (" << dims.
str (
',') <<
")";
1648 os <<
"(" << dims.
str () <<
")";
1660 << std::setw (8) << std::setprecision (1)
1688 os << std::setw (extra_indent) <<
"";
1691 os <<
" Column " << col + 1 <<
":\n";
1692 else if (num_cols == 2)
1693 os <<
" Columns " << col + 1 <<
" and " << lim <<
":\n";
1695 os <<
" Columns " << col + 1 <<
" through " << lim <<
":\n";
1708 else if (val < T (0))
1709 os << plus_format_chars[1];
1711 os << plus_format_chars[2];
1722 bool pr_as_read_syntax)
1724 if (pr_as_read_syntax)
1740 bool pr_as_read_syntax,
int extra_indent)
1745 if (nr == 0 || nc == 0)
1767 int column_width = fw + 2;
1771 if (pr_as_read_syntax)
1774 max_width -= extra_indent;
1781 if (pr_as_read_syntax)
1786 if (pr_as_read_syntax)
1795 inc = max_width / column_width;
1800 if (pr_as_read_syntax)
1813 if (i == 0 && j == 0)
1817 if (j > col && j < lim)
1855 os << std::setw (extra_indent) <<
"";
1876 bool pr_as_read_syntax,
int extra_indent)
1881 if (nr == 0 || nc == 0)
1903 int column_width = fw + 2;
1907 if (pr_as_read_syntax)
1910 max_width -= extra_indent;
1917 if (pr_as_read_syntax)
1922 if (pr_as_read_syntax)
1931 inc = max_width / column_width;
1936 if (pr_as_read_syntax)
1953 if (j > col && j < lim)
1975 os <<
"Diagonal Matrix\n";
1985 std::ostringstream tmp_oss;
1986 pr_float (tmp_oss, 0.0, fw, scale);
1987 zero_fw = tmp_oss.str ().length ();
1999 os << std::setw (extra_indent) <<
"";
2010 os << std::setw (zero_fw) <<
'0';
2022 template <
typename NDA_T,
typename ELT_T,
typename MAT_T>
2024 bool pr_as_read_syntax)
2027 if (nda.is_empty ())
2032 int ndims = nda.ndims ();
2040 for (
int i = 2; i < ndims; i++)
2050 std::string nm =
"ans";
2056 std::ostringstream buf;
2058 for (
int k = 2; k < ndims; k++)
2076 for (
int k = 2; k < ndims; k++)
2100 bool pr_as_read_syntax,
int extra_indent)
2102 switch (nda.
ndims ())
2107 pr_as_read_syntax, extra_indent);
2111 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax);
2118 pr_plus_format<> (std::ostream& os,
const Complex& c)
2120 double rp = c.real ();
2121 double ip = c.imag ();
2138 bool pr_as_read_syntax)
2140 if (pr_as_read_syntax)
2156 bool pr_as_read_syntax,
int extra_indent)
2161 if (nr == 0 || nc == 0)
2183 int column_width = i_fw + r_fw;
2189 if (pr_as_read_syntax)
2192 max_width -= extra_indent;
2199 if (pr_as_read_syntax)
2204 if (pr_as_read_syntax)
2213 inc = max_width / column_width;
2218 if (pr_as_read_syntax)
2231 if (i == 0 && j == 0)
2235 if (j > col && j < lim)
2273 os << std::setw (extra_indent) <<
"";
2294 bool pr_as_read_syntax,
int extra_indent)
2299 if (nr == 0 || nc == 0)
2321 int column_width = i_fw + r_fw;
2327 if (pr_as_read_syntax)
2330 max_width -= extra_indent;
2337 if (pr_as_read_syntax)
2342 if (pr_as_read_syntax)
2351 inc = max_width / column_width;
2356 if (pr_as_read_syntax)
2373 if (j > col && j < lim)
2395 os <<
"Diagonal Matrix\n";
2405 std::ostringstream tmp_oss;
2407 zero_fw = tmp_oss.str ().length ();
2419 os << std::setw (extra_indent) <<
"";
2430 os << std::setw (zero_fw) <<
'0';
2443 bool pr_as_read_syntax,
int extra_indent)
2448 if (nr == 0 || nc == 0)
2468 int column_width = fw + 2;
2472 if (pr_as_read_syntax)
2475 max_width -= extra_indent;
2482 if (pr_as_read_syntax)
2487 if (pr_as_read_syntax)
2496 inc = max_width / column_width;
2501 if (pr_as_read_syntax)
2521 if (j > col && j < lim)
2543 os <<
"Permutation Matrix\n";
2556 os << std::setw (extra_indent) <<
"";
2564 os << std::setw (fw) << m(i,j);
2577 bool pr_as_read_syntax,
int extra_indent)
2579 switch (nda.
ndims ())
2584 pr_as_read_syntax, extra_indent);
2588 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
2589 (os, nda, pr_as_read_syntax);
2610 bool pr_as_read_syntax,
int extra_indent)
2617 bool pr_as_read_syntax,
int extra_indent)
2624 bool pr_as_read_syntax,
int extra_indent)
2631 bool pr_as_read_syntax)
2638 bool pr_as_read_syntax,
int extra_indent)
2646 bool pr_as_read_syntax,
int extra_indent)
2654 bool pr_as_read_syntax,
int extra_indent)
2662 bool pr_as_read_syntax,
int extra_indent)
2664 double base = r.
base ();
2665 double increment = r.
inc ();
2666 double limit = r.
limit ();
2675 double val = base + i * increment;
2686 if (pr_as_read_syntax)
2690 os << base <<
" : ";
2691 if (increment != 1.0)
2692 os << increment <<
" : ";
2699 if (increment != 1.0)
2711 int column_width = fw + 2;
2724 inc = max_width / column_width;
2729 max_width -= extra_indent;
2737 while (col < num_elem)
2744 os << std::setw (extra_indent) <<
"";
2754 val = base + i * increment;
2756 if (i == num_elem - 1)
2759 if ((increment > 0 && val >= limit)
2760 || (increment < 0 && val <= limit))
2777 bool pr_as_read_syntax,
2786 bool pr_as_read_syntax,
2789 switch (nda.
ndims ())
2794 pr_as_read_syntax, extra_indent);
2806 bool pr_as_read_syntax,
2814 if (pr_as_read_syntax && nstr > 1)
2825 if (pr_as_read_syntax)
2842 if (pr_as_read_syntax && nstr > 1)
2847 os <<
"sorry, printing char matrices not implemented yet\n";
2853 bool pr_as_read_syntax,
int extra_indent,
2856 switch (nda.
ndims ())
2861 pr_as_read_syntax, extra_indent, pr_as_string);
2865 print_nd_array <charNDArray, char, charMatrix> (os, nda,
2873 bool pr_as_read_syntax,
int extra_indent)
2882 bool pr_as_read_syntax,
int )
2889 else if (nda.
length () == 1)
2895 int ndims = nda.
ndims ();
2903 for (
int i = 2; i < ndims; i++)
2911 std::string nm =
"ans";
2917 std::ostringstream buf;
2919 for (
int k = 2; k < ndims; k++)
2937 for (
int k = 2; k < ndims; k++)
2955 os <<
" " << page(ii,jj);
2977 #define PRINT_CONV(T1, T2) \
2980 octave_print_conv<T1> \
2983 typedef T2 print_conv_type; \
2995 size_t sz = d.byte_size ();
2996 const unsigned char * tmpi = d.iptr ();
3008 os.flags (std::ios::right | std::ios::hex);
3012 for (
size_t i = 0; i < sz; i++)
3013 os << std::setw (2) <<
static_cast<int> (tmpi[i]);
3017 for (
int i = sz - 1; i >= 0; i--)
3018 os << std::setw (2) <<
static_cast<int> (tmpi[i]);
3021 else if (bit_format)
3025 for (
size_t i = 0; i < sz; i++)
3032 for (
size_t i = 0; i < sz; i++)
3037 for (
int i = sz - 1; i >= 0; i--)
3046 os << std::setw (fw)
3064 return x < 0 ? -x :
x;
3067 #define INSTANTIATE_ABS(T) \
3076 #define SPECIALIZE_UABS(T) \
3079 abs (unsigned T x) \
3126 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val);
3132 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
3133 OCTINTERP_API void \
3134 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \
3136 octave_print_internal_template (os, val, dummy); \
3151 bool pr_as_read_syntax,
int extra_indent)
3156 if (nda.is_empty ())
3158 else if (nda.length () == 1)
3162 int ndims = nda.ndims ();
3170 for (
int i = 2; i < ndims; i++)
3180 std::string nm =
"ans(:,:,";
3182 std::ostringstream buf;
3184 for (
int k = 2; k < ndims; k++)
3206 for (
int k = 2; k < ndims; k++)
3220 if ((ii < nr - 1) || (i < m -1))
3233 int ndims = nda.ndims ();
3241 for (
int i = 2; i < ndims; i++)
3249 fw = 2 * nda(0).byte_size ();
3250 else if (bit_format)
3251 fw = nda(0).nbits ();
3263 if (new_digits > digits)
3264 digits = new_digits;
3267 isneg = (
abs (nda(i).value ()) != nda(i).value ());
3270 fw = digits + isneg;
3279 inc = max_width / column_width;
3288 std::string nm =
"ans(:,:,";
3290 std::ostringstream buf;
3292 for (
int k = 2; k < ndims; k++)
3314 for (
int k = 2; k < ndims; k++)
3321 if (pr_as_read_syntax)
3330 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj));
3335 if (pr_as_read_syntax)
3354 os << std::setw (extra_indent) <<
"";
3360 pr_int (os, page(ii,jj), fw);
3362 if ((ii < n_rows - 1) || (i < m -1))
3377 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
3378 OCTINTERP_API void \
3379 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \
3380 bool pr_as_read_syntax, int extra_indent) \
3382 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
3406 DEFUN (rats, args, nargout,
3408 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\
3409 Convert @var{x} into a rational approximation represented as a string.\n\
3411 The string can be converted back into a matrix as follows:\n\
3415 r = rats (hilb (4));\n\
3420 The optional second argument defines the maximum length of the string\n\
3421 representing the elements of @var{x}. By default @var{len} is 9.\n\
3423 If the length of the smallest possible rational approximation exceeds\n\
3424 @var{len}, an asterisk (*) padded with spaces will be returned instead.\n\
3425 @seealso{format, rat}\n\
3430 int nargin = args.
length ();
3432 if (nargin < 1 || nargin > 2 || nargout > 1)
3443 rat_string_len = args(1).nint_value ();
3455 std::ostringstream buf;
3457 std::string s = buf.str ();
3459 std::list<std::string> lst;
3462 size_t s_len = s.length ();
3466 size_t m = s.find (
'\n', n);
3468 if (m == std::string::npos)
3470 lst.push_back (s.substr (n));
3475 lst.push_back (s.substr (n, m - n));
3483 error (
"rats: X must be numeric");
3490 DEFUN (disp, args, nargout,
3492 @deftypefn {Built-in Function} {} disp (@var{x})\n\
3493 Display the value of @var{x}.\n\
3499 disp (\"The value of pi is:\"), disp (pi)\n\
3501 @print{} the value of pi is:\n\
3507 Note that the output from @code{disp} always ends with a newline.\n\
3509 If an output value is requested, @code{disp} prints nothing and returns the\n\
3510 formatted output in a string.\n\
3516 int nargin = args.
length ();
3518 if (nargin == 1 && nargout < 2)
3526 std::ostringstream buf;
3537 DEFUN (fdisp, args, ,
3539 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\
3540 Display the value of @var{x} on the stream @var{fid}.\n\
3546 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\
3548 @print{} the value of pi is:\n\
3554 Note that the output from @code{fdisp} always ends with a newline.\n\
3560 int nargin = args.
length ();
3577 error (
"fdisp: stream FID not open for writing");
3632 Voutput_precision = prec;
3633 Voutput_max_field_width = fw;
3646 std::string
arg = argv[idx++];
3661 else if (arg ==
"E")
3667 else if (arg ==
"g")
3672 else if (arg ==
"G")
3678 else if (arg ==
"eng")
3685 error (
"format: unrecognized option 'short %s'",
3695 else if (arg ==
"shorte")
3701 else if (arg ==
"shortE")
3708 else if (arg ==
"shortg")
3714 else if (arg ==
"shortG")
3721 else if (arg ==
"shortEng")
3727 else if (arg ==
"long")
3739 else if (arg ==
"E")
3745 else if (arg ==
"g")
3750 else if (arg ==
"G")
3756 else if (arg ==
"eng")
3763 error (
"format: unrecognized option 'long %s'",
3773 else if (arg ==
"longe")
3779 else if (arg ==
"longE")
3786 else if (arg ==
"longg")
3792 else if (arg ==
"longG")
3799 else if (arg ==
"longEng")
3805 else if (arg ==
"hex")
3810 else if (arg ==
"native-hex")
3815 else if (arg ==
"bit")
3820 else if (arg ==
"native-bit")
3825 else if (arg ==
"+" || arg ==
"plus")
3832 if (arg.length () == 3)
3836 error (
"format: invalid option for plus format");
3846 else if (arg ==
"rat")
3851 else if (arg ==
"bank")
3856 else if (arg ==
"free")
3861 else if (arg ==
"none")
3866 else if (arg ==
"compact")
3871 else if (arg ==
"loose")
3878 error (
"format: unrecognized format state '%s'", arg.c_str ());
3886 format = std::string (
"short");
3893 DEFUN (format, args, ,
3895 @deftypefn {Command} {} format\n\
3896 @deftypefnx {Command} {} format options\n\
3897 Reset or specify the format of the output produced by @code{disp} and\n\
3898 Octave's normal echoing mechanism.\n\
3900 This command only affects the display of numbers but not how they are stored\n\
3901 or computed. To change the internal representation from the default double\n\
3902 use one of the conversion functions such as @code{single}, @code{uint8},\n\
3903 @code{int64}, etc.\n\
3905 By default, Octave displays 5 significant digits in a human readable form\n\
3906 (option @samp{short} paired with @samp{loose} format for matrices).\n\
3907 If @code{format} is invoked without any options, this default format\n\
3910 Valid formats for floating point numbers are listed in the following\n\
3915 Fixed point format with 5 significant figures in a field that is a maximum\n\
3916 of 10 characters wide. (default).\n\
3918 If Octave is unable to format a matrix so that columns line up on the\n\
3919 decimal point and all numbers fit within the maximum field width then\n\
3920 it switches to an exponential @samp{e} format.\n\
3923 Fixed point format with 15 significant figures in a field that is a maximum\n\
3924 of 20 characters wide.\n\
3926 As with the @samp{short} format, Octave will switch to an exponential\n\
3927 @samp{e} format if it is unable to format a matrix properly using the\n\
3932 Exponential format. The number to be represented is split between a mantissa\n\
3933 and an exponent (power of 10). The mantissa has 5 significant digits in the\n\
3934 short format and 15 digits in the long format.\n\
3935 For example, with the @samp{short e} format, @code{pi} is displayed as\n\
3936 @code{3.1416e+00}.\n\
3940 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\
3941 @samp{E} to indicate the exponent.\n\
3942 For example, with the @samp{long E} format, @code{pi} is displayed as\n\
3943 @code{3.14159265358979E+00}.\n\
3947 Optimally choose between fixed point and exponential format based on\n\
3948 the magnitude of the number.\n\
3949 For example, with the @samp{short g} format,\n\
3950 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\
3966 Identical to @samp{short e} or @samp{long e} but displays the value\n\
3967 using an engineering format, where the exponent is divisible by 3. For\n\
3968 example, with the @samp{short eng} format, @code{10 * pi} is displayed as\n\
3969 @code{31.4159e+00}.\n\
3973 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\
3974 @samp{E} to indicate the exponent.\n\
3978 Print output in free format, without trying to line up columns of\n\
3979 matrices on the decimal point. This also causes complex numbers to be\n\
3980 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\
3981 of like this @samp{0.60419 + 0.60709i}.\n\
3984 The following formats affect all numeric output (floating point and\n\
3989 @itemx \"+\" @var{chars}\n\
3991 @itemx plus @var{chars}\n\
3992 Print a @samp{+} symbol for matrix elements greater than zero, a\n\
3993 @samp{-} symbol for elements less than zero and a space for zero matrix\n\
3994 elements. This format can be very useful for examining the structure\n\
3995 of a large sparse matrix.\n\
3997 The optional argument @var{chars} specifies a list of 3 characters to use\n\
3998 for printing values greater than zero, less than zero and equal to zero.\n\
3999 For example, with the @samp{\"+\" \"+-.\"} format,\n\
4000 @code{[1, 0, -1; -1, 0, 1]} is displayed as\n\
4012 Print in a fixed format with two digits to the right of the decimal\n\
4016 Print the hexadecimal representation of numbers as they are stored in\n\
4017 memory. For example, on a workstation which stores 8 byte real values\n\
4018 in IEEE format with the least significant byte first, the value of\n\
4019 @code{pi} when printed in @code{native-hex} format is\n\
4020 @code{400921fb54442d18}.\n\
4023 The same as @code{native-hex}, but always print the most significant\n\
4027 Print the bit representation of numbers as stored in memory.\n\
4028 For example, the value of @code{pi} is\n\
4032 01000000000010010010000111111011\n\
4033 01010100010001000010110100011000\n\
4037 (shown here in two 32 bit sections for typesetting purposes) when\n\
4038 printed in native-bit format on a workstation which stores 8 byte real values\n\
4039 in IEEE format with the least significant byte first.\n\
4042 The same as @code{native-bit}, but always print the most significant\n\
4046 Print a rational approximation, i.e., values are approximated\n\
4047 as the ratio of small integers.\n\
4048 For example, with the @samp{rat} format,\n\
4049 @code{pi} is displayed as @code{355/113}.\n\
4052 The following two options affect the display of all matrices.\n\
4056 Remove blank lines around column number labels and between\n\
4057 matrices producing more compact output with more data per page.\n\
4060 Insert blank lines above and below column number labels and between matrices\n\
4061 to produce a more readable output with less data per page. (default).\n\
4063 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, print_empty_dimensions, rats}\n\
4068 int argc = args.
length () + 1;
4080 DEFUN (__compactformat__, args, nargout,
4082 @deftypefn {Built-in Function} {@var{val} =} __compactformat__ ()\n\
4083 @deftypefnx {Built-in Function} {} __compactformat__ (@var{TRUE|FALSE})\n\
4084 Undocumented internal function\n\
4090 DEFUN (__formatstring__, , ,
4092 @deftypefn {Built-in Function} {@var{val} =} __formatstring__ ()\n\
4093 Undocumented internal function\n\
4099 DEFUN (fixed_point_format, args, nargout,
4101 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\
4102 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\
4103 @deftypefnx {Built-in Function} {} fixed_point_format (@var{new_val}, \"local\")\n\
4104 Query or set the internal variable that controls whether Octave will\n\
4105 use a scaled format to print matrix values.\n\
4107 The scaled format prints a scaling factor on the first line of output chosen\n\
4108 such that the largest matrix element can be written with a single leading\n\
4109 digit. For example:\n\
4113 logspace (1, 7, 5)'\n\
4127 Notice that the first value appears to be 0 when it is actually 1. Because\n\
4128 of the possibility for confusion you should be careful about enabling\n\
4129 @code{fixed_point_format}.\n\
4131 When called from inside a function with the @qcode{\"local\"} option, the\n\
4132 variable is changed locally for the function and any subroutines it calls.\n\
4133 The original variable value is restored when exiting the function.\n\
4134 @seealso{format, output_max_field_width, output_precision}\n\
4140 DEFUN (print_empty_dimensions, args, nargout,
4142 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\
4143 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\
4144 @deftypefnx {Built-in Function} {} print_empty_dimensions (@var{new_val}, \"local\")\n\
4145 Query or set the internal variable that controls whether the dimensions of\n\
4146 empty matrices are printed along with the empty matrix symbol, @samp{[]}.\n\
4148 For example, the expression\n\
4161 When called from inside a function with the @qcode{\"local\"} option, the\n\
4162 variable is changed locally for the function and any subroutines it calls.\n\
4163 The original variable value is restored when exiting the function.\n\
4170 DEFUN (split_long_rows, args, nargout,
4172 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\
4173 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\
4174 @deftypefnx {Built-in Function} {} split_long_rows (@var{new_val}, \"local\")\n\
4175 Query or set the internal variable that controls whether rows of a matrix\n\
4176 may be split when displayed to a terminal window.\n\
4178 If the rows are split, Octave will display the matrix in a series of smaller\n\
4179 pieces, each of which can fit within the limits of your terminal width and\n\
4180 each set of rows is labeled so that you can easily see which columns are\n\
4181 currently being displayed. For example:\n\
4185 octave:13> rand (2,10)\n\
4188 Columns 1 through 6:\n\
4190 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\
4191 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\
4193 Columns 7 through 10:\n\
4195 0.90174 0.11854 0.72313 0.73326\n\
4196 0.44672 0.94303 0.56564 0.82150\n\
4200 When called from inside a function with the @qcode{\"local\"} option, the\n\
4201 variable is changed locally for the function and any subroutines it calls.\n\
4202 The original variable value is restored when exiting the function.\n\
4209 DEFUN (output_max_field_width, args, nargout,
4211 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\
4212 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\
4213 @deftypefnx {Built-in Function} {} output_max_field_width (@var{new_val}, \"local\")\n\
4214 Query or set the internal variable that specifies the maximum width\n\
4215 of a numeric output field.\n\
4217 When called from inside a function with the @qcode{\"local\"} option, the\n\
4218 variable is changed locally for the function and any subroutines it calls.\n\
4219 The original variable value is restored when exiting the function.\n\
4220 @seealso{format, fixed_point_format, output_precision}\n\
4227 DEFUN (output_precision, args, nargout,
4229 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\
4230 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\
4231 @deftypefnx {Built-in Function} {} output_precision (@var{new_val}, \"local\")\n\
4232 Query or set the internal variable that specifies the minimum number of\n\
4233 significant figures to display for numeric output.\n\
4235 When called from inside a function with the @qcode{\"local\"} option, the\n\
4236 variable is changed locally for the function and any subroutines it calls.\n\
4237 The original variable value is restored when exiting the function.\n\
4238 @seealso{format, fixed_point_format, output_max_field_width}\n\
static int rat_string_len
static void set_output_prec_and_fw(int prec, int fw)
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)
static octave_stream lookup(int fid, const std::string &who=std::string())
bool is_empty(void) const
static int terminal_cols(void)
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
OCTINTERP_API void print_usage(void)
static int calc_scale_exp(const int &x)
octave_idx_type length(void) const
octave_idx_type nelem(void) const
static float_format * curr_imag_fmt
pr_engineering_float(const float_format &f_arg, double val_arg)
bool is_numeric_type(void) const
static void pr_any_float(const float_format *fmt, std::ostream &os, double d, int fw=0)
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)
static void init_format_state(void)
static std::string format_string("short")
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
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.
F77_RET_T const double const double double * d
static double pr_max_internal(const Matrix &m)
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)
static int current_output_precision(void)
F77_RET_T const double const double * f
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
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)
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)
std::ostream * output_stream(void)
static bool words_big_endian(void)
octave_idx_type length(void) const
static std::string plus_format_chars
bool any_element_is_inf_or_nan(void) const
OCTAVE_API double D_NINT(double x)
bool any_zero(void) const
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
void pr_plus_format(std::ostream &os, const T &val)
#define PRINT_CHAR_BITS(os, c)
static bool Vsplit_long_rows
bool all_elements_are_int_or_inf_or_nan(void) const
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)
octave_idx_type length(void) const
Number of elements in the array.
bool Vprint_empty_dimensions
#define INSTANTIATE_ABS(T)
std::string undo_string_escapes(const std::string &s)
octave_value_list ovl(const octave_value &a0)
static void print_empty_nd_array(std::ostream &os, const dim_vector &dims, bool pr_as_read_syntax)
static float_format native_float_format(void)
bool is_dq_string(void) const
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)
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
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
std::complex< T > floor(const std::complex< T > &x)
std::complex< double > Complex
ColumnVector real(const ComplexColumnVector &a)
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)
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)
Array< T > index(const idx_vector &i) const
Indexing without resizing.
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
F77_RET_T const double * x
charNDArray min(char d, const charNDArray &m)
bool octave_is_NA(double x)