23 #if defined (HAVE_CONFIG_H) 119 return x - 3*
static_cast<int> (
x/3);
137 template <
typename T>
145 T absval = (
x < 0 ? -
x :
x);
146 int logabsval =
static_cast<int> (
std::floor (log10 (absval)));
152 ex = logabsval - 2 + ((-logabsval + 2) % 3);
154 ex = logabsval - (logabsval % 3);
160 template <
typename T>
169 template <
typename T>
176 template <
typename T>
183 template <
typename T>
185 operator << (std::ostream& os, const pr_engineering_float<T>& pef)
191 if (real_fmt.
fw >= 0)
192 os << std::setw (real_fmt.
fw - real_fmt.
ex);
194 if (real_fmt.
prec >= 0)
195 os << std::setprecision (real_fmt.
prec);
197 os.flags (static_cast<std::ios::fmtflags>
198 (real_fmt.
fmt | real_fmt.
up | real_fmt.
sp));
200 os << pef.mantissa ();
202 int ex = pef.exponent ();
205 os << std::setw (0) <<
"e-";
209 os << std::setw (0) <<
"e+";
211 os << std::setw (real_fmt.
ex - 2) << std::setfill (
'0') << ex;
216 template <
typename T>
218 operator << (std::ostream& os, const pr_formatted_float<T>& pff)
224 if (real_fmt.
fw >= 0)
225 os << std::setw (real_fmt.
fw);
227 if (real_fmt.
prec >= 0)
228 os << std::setprecision (real_fmt.
prec);
230 os.flags (static_cast<std::ios::fmtflags>
231 (real_fmt.
fmt | real_fmt.
up | real_fmt.
sp));
238 template <
typename T>
255 std::ostringstream buf;
256 buf.flags (std::ios::fixed);
269 std::ostringstream buf2;
270 buf2.flags (std::ios::fixed);
271 buf2 << std::setprecision (0) << static_cast<int> (n);
290 n = step * n + lastn;
291 d = step *
d + lastd;
295 std::ostringstream buf;
296 buf.flags (std::ios::fixed);
297 buf << std::setprecision (0) << static_cast<int> (n)
298 <<
'/' << static_cast<int> (
d);
304 if (buf.str ().length () >
static_cast<unsigned int> (len + 2))
307 else if (buf.str ().length () >
static_cast<unsigned int> (len))
322 std::ostringstream buf;
323 buf.flags (std::ios::fixed);
324 buf << std::setprecision (0) << static_cast<int> (lastn)
325 <<
'/' << static_cast<int> (lastd);
347 template <
typename T>
349 operator << (std::ostream& os, const pr_rational_float<T>& prf)
359 os << std::setw (fw);
361 os.flags (static_cast<std::ios::fmtflags>
362 (real_fmt.
fmt | real_fmt.
up | real_fmt.
sp));
364 if (fw > 0 &&
s.length () >
static_cast<unsigned int> (fw))
372 template <
typename T>
377 assert (m.
ndims () == 2);
382 T
result = std::numeric_limits<T>::lowest ();
384 bool all_inf_or_nan =
true;
393 all_inf_or_nan =
false;
405 template <
typename T>
414 bool all_inf_or_nan =
true;
423 all_inf_or_nan =
false;
466 template <
typename T>
474 int fw = 0, ld = 0, rd = 0;
483 fw = (digits < 0 ? 5 : digits + 4);
484 if (inf_or_nan && fw < 5)
498 else if (inf_or_nan || int_only)
501 if (inf_or_nan && fw < 4)
515 rd = (prec > digits ? prec - digits : prec);
520 rd = (prec > digits ? prec - digits : prec);
523 fw = 1 + ld + 1 + rd;
524 if (inf_or_nan && fw < 4)
544 if (inf_or_nan && fw < 6)
552 if (inf_or_nan && fw < 4)
554 fmt =
float_format (fw, ex, prec - 1, std::ios::scientific);
561 else if (!
bank_format && (inf_or_nan || int_only))
571 template <
typename T>
584 int digits = (inf_or_nan || val_abs == 0) ? 0 :
num_digits (val_abs);
586 return make_real_format<T> (digits, inf_or_nan, int_only);
603 template <
typename T>
606 int int_or_inf_or_nan)
608 T
scale = ((x_max == 0 || int_or_inf_or_nan)
615 int fw = 0, ld = 0, rd = 0;
624 int digits = (x_max > x_min ? x_max : x_min);
625 fw = (digits <= 0 ? 5 : digits + 4);
626 if (inf_or_nan && fw < 5)
644 if (inf_or_nan && fw < 4)
647 else if (int_or_inf_or_nan)
649 int digits = (x_max > x_min ? x_max : x_min);
650 fw = (digits <= 0 ? 2 : digits + 1);
651 if (inf_or_nan && fw < 4)
661 rd_max = (prec > x_max ? prec - x_max : prec);
667 rd_max = (prec > x_max ? prec - x_max : prec);
675 rd_min = (prec > x_min ? prec - x_min : prec);
681 rd_min = (prec > x_min ? prec - x_min : prec);
685 ld = (ld_max > ld_min ? ld_max : ld_min);
686 rd = (rd_max > rd_min ? rd_max : rd_min);
688 fw = 1 + ld + 1 + rd;
689 if (inf_or_nan && fw < 4)
704 if (x_max > 100 || x_min > 100)
710 if (inf_or_nan && fw < 6)
717 if (inf_or_nan && fw < 4)
719 fmt =
float_format (fw, prec - 1, std::ios::scientific);
734 template <
typename MT>
738 assert (m.ndims () == 2);
743 bool inf_or_nan = m.any_element_is_inf_or_nan ();
745 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan ();
749 typedef typename MT::element_type ELT_T;
754 int x_max = (max_abs == 0 ? 0 :
num_digits (max_abs));
756 int x_min = (min_abs == 0 ? 0 :
num_digits (min_abs));
758 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan,
776 template <
typename T>
779 bool inf_or_nan,
int int_only)
786 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
798 r_fw = (digits <= 0 ? 5 : digits + 4);
799 if (inf_or_nan && r_fw < 5)
805 r_fw = 2 *
sizeof (T);
806 i_fw = 2 *
sizeof (T);
811 r_fw = 8 *
sizeof (T);
812 i_fw = 8 *
sizeof (T);
815 else if (inf_or_nan || int_only)
817 int digits = (x_max > x_min ? x_max : x_min);
818 i_fw = (digits <= 0 ? 1 : digits);
820 if (inf_or_nan && i_fw < 3)
838 rd_max = (prec > x_max ? prec - x_max : prec);
844 rd_max = (prec > x_max ? prec - x_max : prec);
852 rd_min = (prec > x_min ? prec - x_min : prec);
858 rd_min = (prec > x_min ? prec - x_min : prec);
862 ld = (ld_max > ld_min ? ld_max : ld_min);
863 rd = (rd_max > rd_min ? rd_max : rd_min);
867 if (inf_or_nan && i_fw < 3)
888 if (x_max > 100 || x_min > 100)
893 i_fw = 3 + prec + ex;
895 if (inf_or_nan && i_fw < 5)
900 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
901 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
905 i_fw = 1 + prec + ex;
907 if (inf_or_nan && i_fw < 3)
912 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
913 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
923 else if (!
bank_format && (inf_or_nan || int_only))
937 template <
typename T>
952 T r_abs = (rp < 0 ? -rp : rp);
953 T i_abs = (ip < 0 ? -ip : ip);
974 return make_complex_format<T> (x_max, x_min, r_x, inf_or_nan, int_only);
991 template <
typename T>
994 int r_x_min,
bool inf_or_nan,
995 int int_or_inf_or_nan)
997 T
scale = ((x_max == 0 || int_or_inf_or_nan)
1005 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
1015 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min);
1017 r_fw = (digits <= 0 ? 5 : digits + 4);
1018 if (inf_or_nan && r_fw < 5)
1024 r_fw = 2 *
sizeof (T);
1025 i_fw = 2 *
sizeof (T);
1030 r_fw = 8 *
sizeof (T);
1031 i_fw = 8 *
sizeof (T);
1039 if (inf_or_nan && i_fw < 3)
1045 else if (int_or_inf_or_nan)
1047 int digits = (x_max > x_min ? x_max : x_min);
1048 i_fw = (digits <= 0 ? 1 : digits);
1050 if (inf_or_nan && i_fw < 3)
1063 rd_max = (prec > x_max ? prec - x_max : prec);
1069 rd_max = (prec > x_max ? prec - x_max : prec);
1077 rd_min = (prec > x_min ? prec - x_min : prec);
1083 rd_min = (prec > x_min ? prec - x_min : prec);
1087 ld = (ld_max > ld_min ? ld_max : ld_min);
1088 rd = (rd_max > rd_min ? rd_max : rd_min);
1092 if (inf_or_nan && i_fw < 3)
1114 if (x_max > 100 || x_min > 100)
1119 i_fw = 3 + prec + ex;
1121 if (inf_or_nan && i_fw < 5)
1126 r_fmt =
float_format (r_fw, ex, prec - 1, std::ios::fixed);
1127 i_fmt =
float_format (i_fw, ex, prec - 1, std::ios::fixed);
1131 i_fw = 1 + prec + ex;
1133 if (inf_or_nan && i_fw < 3)
1138 r_fmt =
float_format (r_fw, prec - 1, std::ios::scientific);
1139 i_fmt =
float_format (i_fw, prec - 1, std::ios::scientific);
1163 template <
typename CMT>
1170 typedef typename CMT::real_matrix_type RMT;
1171 typedef typename CMT::real_elt_type ELT_T;
1176 bool inf_or_nan = cm.any_element_is_inf_or_nan ();
1178 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan ()
1179 && ip.all_elements_are_int_or_inf_or_nan ());
1181 RMT r_m_abs = rp.abs ();
1185 RMT i_m_abs = ip.abs ();
1189 int r_x_max = (r_max_abs == 0 ? 0 :
num_digits (r_max_abs));
1191 int r_x_min = (r_min_abs == 0 ? 0 :
num_digits (r_min_abs));
1193 int i_x_max = (i_max_abs == 0 ? 0 :
num_digits (i_max_abs));
1195 int i_x_min = (i_min_abs == 0 ? 0 :
num_digits (i_min_abs));
1197 int x_max = (r_x_max > i_x_max ? r_x_max : i_x_max);
1198 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min);
1200 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min,
1201 inf_or_nan, int_or_inf_or_nan);
1225 template <
typename T>
1229 double scale = ((x_max == 0 || all_ints)
1236 int fw = 0, ld = 0, rd = 0;
1245 int digits = (x_max > x_min ? x_max : x_min);
1246 fw = (digits < 0 ? 5 : digits + 4);
1251 fw = 2 *
sizeof (T);
1256 fw = 8 *
sizeof (T);
1261 int digits = (x_max > x_min ? x_max : x_min);
1276 rd_max = (prec > x_max ? prec - x_max : prec);
1282 rd_max = (prec > x_max ? prec - x_max : prec);
1290 rd_min = (prec > x_min ? prec - x_min : prec);
1296 rd_min = (prec > x_min ? prec - x_min : prec);
1300 ld = (ld_max > ld_min ? ld_max : ld_min);
1301 rd = (rd_max > rd_min ? rd_max : rd_min);
1317 if (x_max > 100 || x_min > 100)
1323 fmt =
float_format (fw, ex, prec - 1, std::ios::fixed);
1328 fmt =
float_format (fw, prec - 1, std::ios::scientific);
1350 double r_min = r.
base ();
1351 double r_max = r.
limit ();
1362 double max_abs = (r_max < 0 ? -r_max : r_max);
1363 double min_abs = (r_min < 0 ? -r_min : r_min);
1365 int x_max = (max_abs == 0 ? 0 :
num_digits (max_abs));
1367 int x_min = (min_abs == 0 ? 0 :
num_digits (min_abs));
1369 return make_range_format<double> (x_max, x_min, all_ints);
1372 template <
typename T>
1376 unsigned char i[
sizeof (T)];
1379 #define PRINT_CHAR_BITS(os, c) \ 1382 unsigned char ctmp = c; \ 1384 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ 1385 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ 1386 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ 1387 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ 1388 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ 1389 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ 1390 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ 1391 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ 1397 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ 1400 unsigned char ctmp = c; \ 1402 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ 1403 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ 1404 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ 1405 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ 1406 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ 1407 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ 1408 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ 1409 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ 1415 template <
typename T>
1449 for (
size_t i = 0;
i <
sizeof (T);
i++)
1450 os << std::setw (2) <<
static_cast<int> (
tmp.i[
i]);
1454 for (
int i =
sizeof (T) - 1;
i >= 0;
i--)
1455 os << std::setw (2) <<
static_cast<int> (
tmp.i[
i]);
1468 for (
size_t i = 0;
i <
sizeof (T);
i++)
1475 for (
size_t i = 0;
i <
sizeof (T);
i++)
1480 for (
int i =
sizeof (T) - 1;
i >= 0;
i--)
1490 os << std::setw (fw) <<
"NA";
1495 os << pr_rational_float<T> (fmt,
val);
1507 os << std::setw (fw) <<
s;
1516 os << std::setw (fw) <<
"NaN";
1521 os << pr_engineering_float<T> (fmt,
val);
1523 os << pr_formatted_float<T> (fmt,
val);
1526 template <
typename T>
1538 template <
typename T>
1545 template <
typename T>
1548 const std::complex<T>& cval)
1555 T
scale =
static_cast<T
> (dscale);
1559 ? cval /
scale : cval);
1589 bool pr_as_read_syntax)
1591 assert (nr == 0 || nc == 0);
1593 if (pr_as_read_syntax)
1595 if (nr == 0 && nc == 0)
1598 os <<
"zeros (" << nr <<
", " << nc <<
')';
1605 os <<
'(' << nr <<
'x' << nc <<
')';
1611 bool pr_as_read_syntax)
1613 assert (
dims.any_zero ());
1615 if (pr_as_read_syntax)
1616 os <<
"zeros (" <<
dims.str (
',') <<
')';
1622 os <<
'(' <<
dims.str () <<
')';
1634 << std::setw (8) << std::setprecision (1)
1662 os << std::setw (extra_indent) <<
"";
1665 os <<
" Column " << col + 1 <<
":\n";
1666 else if (num_cols == 2)
1667 os <<
" Columns " << col + 1 <<
" and " << lim <<
":\n";
1669 os <<
" Columns " << col + 1 <<
" through " << lim <<
":\n";
1676 template <
typename T>
1682 else if (
val < T (0))
1694 template <
typename T>
1698 return x < 0 ? -
x :
x;
1701 #define INSTANTIATE_ABS(T) \ 1709 #define SPECIALIZE_UABS(T) \ 1722 #define MAKE_INT_MATRIX_FORMAT(TYPE) \ 1724 float_display_format \ 1725 make_format (const intNDArray<TYPE>& nda) \ 1727 bool isneg = false; \ 1730 for (octave_idx_type i = 0; i < nda.numel (); i++) \ 1733 = static_cast<int> \ 1734 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); \ 1736 if (new_digits > digits) \ 1737 digits = new_digits; \ 1740 isneg = (abs (nda(i).value ()) != nda(i).value ()); \ 1743 return float_display_format (float_format (digits + isneg, 0, 0)); \ 1755 #define MAKE_INT_SCALAR_FORMAT(TYPE) \ 1757 float_display_format \ 1758 make_format (const octave_int<TYPE>& val) \ 1760 bool isneg = false; \ 1762 = static_cast<int> \ 1763 (std::floor (log10 (double (abs (val.value ()))) + 1)); \ 1765 isneg = (abs (val.value ()) != val.value ()); \ 1767 return float_display_format (float_format (digits + isneg, 0, 0)); \ 1781 bool d,
bool pr_as_read_syntax)
1801 double d,
bool pr_as_read_syntax)
1803 if (pr_as_read_syntax)
1818 float d,
bool pr_as_read_syntax)
1820 if (pr_as_read_syntax)
1833 template <
typename MT>
1840 if (pr_as_read_syntax)
1846 os <<
' ' << m.elem(
i,j);
1852 if (pr_as_read_syntax)
1856 template <
typename MT>
1883 int retval = r_fw + i_fw + 2;
1891 template <
typename MT>
1894 bool pr_as_read_syntax,
int extra_indent)
1899 if (nr == 0 || nc == 0)
1910 if (pr_as_read_syntax)
1913 max_width -= extra_indent;
1927 inc = max_width / column_width;
1932 if (pr_as_read_syntax)
1945 if (
i == 0 && j == 0)
1949 if (j > col && j < lim)
1987 os << std::setw (extra_indent) <<
"";
2006 template <
typename DMT>
2009 bool pr_as_read_syntax,
int extra_indent)
2014 if (nr == 0 || nc == 0)
2021 =
make_format (
typename DMT::full_matrix_type (m.diag ()));
2026 if (pr_as_read_syntax)
2029 max_width -= extra_indent;
2043 inc = max_width / column_width;
2048 if (pr_as_read_syntax)
2065 if (j > col && j < lim)
2087 os <<
"Diagonal Matrix\n";
2096 std::ostringstream tmp_oss;
2097 typename DMT::element_type
zero = 0;
2099 zero_fw = tmp_oss.str ().length ();
2111 os << std::setw (extra_indent) <<
"";
2122 os << std::setw (zero_fw) <<
'0';
2133 template <
typename NDA_T,
typename ELT_T,
typename MAT_T>
2135 bool pr_as_read_syntax)
2143 int ndims = nda.ndims ();
2151 for (
int i = 2;
i < ndims;
i++)
2167 std::ostringstream buf;
2169 for (
int k = 2;
k < ndims;
k++)
2187 for (
int k = 2;
k < ndims;
k++)
2211 bool pr_as_read_syntax,
int extra_indent)
2213 switch (nda.
ndims ())
2218 pr_as_read_syntax, extra_indent);
2222 print_nd_array <NDArray, double, Matrix> (
os, nda, pr_as_read_syntax);
2229 bool pr_as_read_syntax,
int extra_indent)
2231 switch (nda.
ndims ())
2236 pr_as_read_syntax, extra_indent);
2240 print_nd_array <FloatNDArray, float, FloatMatrix> (
os, nda, pr_as_read_syntax);
2245 template <
typename T>
2267 const Complex&
c,
bool pr_as_read_syntax)
2269 if (pr_as_read_syntax)
2286 if (pr_as_read_syntax)
2301 bool pr_as_read_syntax,
int extra_indent)
2306 if (nr == 0 || nc == 0)
2313 int column_width = fw + 2;
2317 if (pr_as_read_syntax)
2320 max_width -= extra_indent;
2334 inc = max_width / column_width;
2339 if (pr_as_read_syntax)
2359 if (j > col && j < lim)
2381 os <<
"Permutation Matrix\n";
2394 os << std::setw (extra_indent) <<
"";
2402 os << std::setw (fw) << m(
i,j);
2415 bool pr_as_read_syntax,
int extra_indent)
2417 switch (nda.
ndims ())
2422 pr_as_read_syntax, extra_indent);
2426 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
2427 (
os, nda, pr_as_read_syntax);
2434 bool pr_as_read_syntax,
int extra_indent)
2436 switch (nda.
ndims ())
2441 pr_as_read_syntax, extra_indent);
2445 print_nd_array <FloatComplexNDArray, FloatComplex, FloatComplexMatrix>
2446 (
os, nda, pr_as_read_syntax);
2455 bool pr_as_read_syntax,
int extra_indent)
2462 bool pr_as_read_syntax,
int extra_indent)
2469 bool pr_as_read_syntax,
int extra_indent)
2476 bool pr_as_read_syntax,
int extra_indent)
2483 bool pr_as_read_syntax,
int extra_indent)
2490 bool pr_as_read_syntax,
int extra_indent)
2497 bool pr_as_read_syntax,
int extra_indent)
2504 bool pr_as_read_syntax,
int extra_indent)
2511 bool pr_as_read_syntax,
int extra_indent)
2513 double base = r.
base ();
2514 double increment = r.
inc ();
2515 double limit = r.
limit ();
2524 if (pr_as_read_syntax)
2528 os << base <<
" : ";
2530 os << increment <<
" : ";
2564 inc = max_width / column_width;
2569 max_width -= extra_indent;
2577 while (col < num_elem)
2584 os << std::setw (extra_indent) <<
"";
2594 val = base +
i * increment;
2596 if (
i == num_elem - 1)
2599 if ((increment > 0 &&
val >= limit)
2600 || (increment < 0 &&
val <= limit))
2617 bool pr_as_read_syntax,
2626 bool pr_as_read_syntax,
2629 switch (nda.
ndims ())
2634 pr_as_read_syntax, extra_indent);
2646 bool pr_as_read_syntax,
2654 if (pr_as_read_syntax && nstr > 1)
2665 if (pr_as_read_syntax)
2682 if (pr_as_read_syntax && nstr > 1)
2687 os <<
"sorry, printing char matrices not implemented yet\n";
2693 bool pr_as_read_syntax,
int extra_indent,
2696 switch (nda.
ndims ())
2701 pr_as_read_syntax, extra_indent, pr_as_string);
2705 print_nd_array <charNDArray, char, charMatrix> (
os, nda,
2713 bool pr_as_read_syntax,
int extra_indent)
2722 bool pr_as_read_syntax,
int )
2729 else if (nda.
numel () == 1)
2735 int ndims = nda.
ndims ();
2743 for (
int i = 2;
i < ndims;
i++)
2757 std::ostringstream buf;
2759 for (
int k = 2;
k < ndims;
k++)
2777 for (
int k = 2;
k < ndims;
k++)
2795 os <<
" " <<
page(ii,jj);
2809 template <
typename T>
2817 #define PRINT_CONV(T1, T2) \ 2820 octave_print_conv<T1> \ 2823 typedef T2 print_conv_type; \ 2831 template <
typename T>
2835 size_t sz =
d.byte_size ();
2836 const unsigned char *tmpi =
d.iptr ();
2852 for (
size_t i = 0;
i <
sz;
i++)
2853 os << std::setw (2) <<
static_cast<int> (tmpi[
i]);
2857 for (
int i =
sz - 1;
i >= 0;
i--)
2858 os << std::setw (2) <<
static_cast<int> (tmpi[
i]);
2865 for (
size_t i = 0;
i <
sz;
i++)
2872 for (
size_t i = 0;
i <
sz;
i++)
2877 for (
int i =
sz - 1;
i >= 0;
i--)
2886 os << std::setw (fw)
2918 template <
typename T>
2929 os << typename octave_print_conv<octave_int<T>>::print_conv_type (
val);
2939 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ 2940 OCTINTERP_API void \ 2941 octave_print_internal (std::ostream& os, \ 2942 const float_display_format& fmt, \ 2943 const octave_int<TYPE>& val, bool dummy) \ 2945 octave_print_internal_template (os, fmt, val, dummy); \ 2957 template <typename T>
2960 bool pr_as_read_syntax,
int extra_indent)
2967 else if (nda.numel () == 1)
2972 int ndims = nda.ndims ();
2980 for (
int i = 2;
i < ndims;
i++)
2992 std::ostringstream buf;
2994 for (
int k = 2;
k < ndims;
k++)
3016 for (
int k = 2;
k < ndims;
k++)
3030 if ((ii < nr - 1) || (
i < m -1))
3043 int ndims = nda.ndims ();
3051 for (
int i = 2;
i < ndims;
i++)
3059 fw = 2 * nda(0).byte_size ();
3061 fw = nda(0).nbits ();
3073 if (new_digits > digits)
3074 digits = new_digits;
3077 isneg = (
abs (nda(
i).
value ()) != nda(
i).value ());
3080 fw = digits + isneg;
3089 inc = max_width / column_width;
3100 std::ostringstream buf;
3102 for (
int k = 2;
k < ndims;
k++)
3124 for (
int k = 2;
k < ndims;
k++)
3131 if (pr_as_read_syntax)
3140 os << typename octave_print_conv<T>::print_conv_type (
page(ii,jj));
3145 if (pr_as_read_syntax)
3165 os << std::setw (extra_indent) <<
"";
3173 if ((ii < n_rows - 1) || (
i < m -1))
3188 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ 3189 OCTINTERP_API void \ 3190 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ 3191 bool pr_as_read_syntax, int extra_indent) \ 3193 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ 3217 DEFUN (rats, args, ,
3239 int nargin = args.length ();
3247 error (
"rats: X must be numeric");
3261 std::ostringstream buf;
3265 std::list<std::string> lst;
3268 size_t s_len =
s.length ();
3272 size_t m =
s.find (
'\n', n);
3274 if (m == std::string::npos)
3276 lst.push_back (
s.substr (n));
3281 lst.push_back (
s.substr (n, m - n));
3290 classes: cell
char double function_handle int8 int16 int32 int64 logical single
struct uint8 uint16 uint32 uint64
3315 if (args.length () != 1)
3326 std::ostringstream buf;
3335 classes: cell
char double function_handle int8 int16 int32 int64 logical single
struct uint8 uint16 uint32 uint64
3356 if (args.length () != 2)
3372 error (
"fdisp: stream FID not open for writing");
3417 DEFUN (display, args, ,
3418 classes: cell
char double function_handle int8 int16 int32 int64 logical single
struct uint8 uint16 uint32 uint64
3456 int nargin = args.length ();
3469 name = args(1).xstring_value (
"NAME must be a string");
3484 bool print_newlines =
false;
3513 init_format_state (
void)
3549 init_format_state ();
3552 else if (
arg ==
"E")
3554 init_format_state ();
3558 else if (
arg ==
"g")
3560 init_format_state ();
3563 else if (
arg ==
"G")
3565 init_format_state ();
3569 else if (
arg ==
"eng")
3571 init_format_state ();
3575 error (
"format: unrecognized option 'short %s'",
arg.c_str ());
3578 init_format_state ();
3582 else if (
arg ==
"shorte")
3584 init_format_state ();
3588 else if (
arg ==
"shortE")
3590 init_format_state ();
3595 else if (
arg ==
"shortg")
3597 init_format_state ();
3601 else if (
arg ==
"shortG")
3603 init_format_state ();
3608 else if (
arg ==
"shortEng")
3610 init_format_state ();
3614 else if (
arg ==
"long")
3623 init_format_state ();
3626 else if (
arg ==
"E")
3628 init_format_state ();
3632 else if (
arg ==
"g")
3634 init_format_state ();
3637 else if (
arg ==
"G")
3639 init_format_state ();
3643 else if (
arg ==
"eng")
3645 init_format_state ();
3649 error (
"format: unrecognized option 'long %s'",
arg.c_str ());
3652 init_format_state ();
3656 else if (
arg ==
"longe")
3658 init_format_state ();
3662 else if (
arg ==
"longE")
3664 init_format_state ();
3669 else if (
arg ==
"longg")
3671 init_format_state ();
3675 else if (
arg ==
"longG")
3677 init_format_state ();
3682 else if (
arg ==
"longEng")
3684 init_format_state ();
3688 else if (
arg ==
"hex")
3690 init_format_state ();
3693 else if (
arg ==
"native-hex")
3695 init_format_state ();
3698 else if (
arg ==
"bit")
3700 init_format_state ();
3703 else if (
arg ==
"native-bit")
3705 init_format_state ();
3708 else if (
arg ==
"+" ||
arg ==
"plus")
3718 error (
"format: invalid option for plus format");
3723 init_format_state ();
3726 else if (
arg ==
"rat")
3728 init_format_state ();
3731 else if (
arg ==
"bank")
3733 init_format_state ();
3736 else if (
arg ==
"free")
3738 init_format_state ();
3741 else if (
arg ==
"none")
3743 init_format_state ();
3746 else if (
arg ==
"compact")
3751 else if (
arg ==
"loose")
3757 error (
"format: unrecognized format state '%s'",
arg.c_str ());
3761 init_format_state ();
3944 int argc = args.length () + 1;
3952 if (args.length () > 0)
3953 warning (
"format: cannot query and set format at the same time, ignoring set operation");
3958 retval(0) = format_string;
OCTINTERP_API octave_value_list feval(const std::string &name, const octave_value_list &args=octave_value_list(), int nargout=0)
static int rat_string_len
static void pr_plus_format(std::ostream &os, const T &val)
octave_idx_type rows(void) const
static const int max_field_width
Template for N-dimensional array classes with like-type math operators.
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define PRINT_INT_SCALAR_INTERNAL(TYPE)
#define PRINT_CHAR_BITS_SWAPPED(os, c)
const octave_base_value const Array< octave_idx_type > & ra_idx
static int num_digits(T x)
octave_idx_type rows(void) const
#define SPECIALIZE_UABS(T)
static T pr_max_internal(const MArray< T > &m)
int output_precision(void)
float_display_format make_complex_scalar_format(const std::complex< T > &c)
static float_display_format make_matrix_format(const MT &m)
OCTINTERP_API void print_usage(void)
static int calc_scale_exp(const int &x)
identity matrix If supplied two scalar respectively For allows like xample val
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
bool all_elements_are_ints(void) const
OCTINTERP_API std::string undo_string_escapes(const std::string &s)
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by zero($0/0$)
OCTAVE_EXPORT octave_value_list page
octave::stream_list & streams
static void print_empty_matrix(std::ostream &os, octave_idx_type nr, octave_idx_type nc, bool pr_as_read_syntax)
static void octave_print_diag_matrix_internal(std::ostream &os, const DMT &m, bool pr_as_read_syntax, int extra_indent)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
static bool Vfixed_point_format
void error(const char *fmt,...)
std::complex< T > floor(const std::complex< T > &x)
#define SET_INTERNAL_VARIABLE(NM)
#define MAKE_INT_SCALAR_FORMAT(TYPE)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
#define lo_ieee_signbit(x)
octave::mach_info::float_format flt_fmt
octave_idx_type columns(void) const
static std::string rational_approx(T val, int len)
void print_nd_array(std::ostream &os, const NDA_T &nda, bool pr_as_read_syntax)
static void pr_any_float(std::ostream &os, const float_format &fmt, T val)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
static float_display_format make_real_format(int digits, bool inf_or_nan, bool int_only)
in this the arguments are accumulated from left to right
void octave_print_internal_template(std::ostream &os, const float_display_format &fmt, const octave_int< T > &val, bool)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
static void pr_float(std::ostream &os, const float_display_format &fmt, T val)
bool is_dq_string(void) const
static float_display_format make_range_format(int x_max, int x_min, int all_ints)
stream lookup(int fid, const std::string &who="") const
std::ostream * output_stream(void)
static const int digits10
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
nd deftypefn *std::string name
Array< T > index(const idx_vector &i) const
Indexing without resizing.
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
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 float_display_format make_real_matrix_format(int x_max, int x_min, bool inf_or_nan, int int_or_inf_or_nan)
static const int digits10
bool valid_identifier(const char *s)
#define MAKE_INT_MATRIX_FORMAT(TYPE)
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
void print(std::ostream &os, bool pr_as_read_syntax=false)
static void octave_print_matrix_internal(std::ostream &os, const MT &m, bool pr_as_read_syntax, int extra_indent)
#define PRINT_CONV(T1, T2)
static void set_format_style(int argc, const string_vector &argv)
float_format native_float_format(void)
static float_display_format make_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)
string_vector & append(const std::string &s)
octave_idx_type numel(void) 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 T pr_min_internal(const MArray< T > &m)
double elem(octave_idx_type i) const
static std::string plus_format_chars
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
bool words_big_endian(void)
With real return the complex result
const Array< octave_idx_type > & col_perm_vec(void) const
static void pr_plus_format_matrix(std::ostream &os, const MT &m)
#define PRINT_CHAR_BITS(os, c)
static const int digits10
static bool Vsplit_long_rows
static const int max_field_width
octave_idx_type columns(void) const
void warning(const char *fmt,...)
octave::unwind_protect frame
static float_display_format make_complex_format(int x_max, int x_min, int r_x, bool inf_or_nan, int int_only)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
charNDArray max(char d, const charNDArray &m)
static int get_column_width(const float_display_format &fmt)
static void pr_imag_float(std::ostream &os, const float_display_format &fmt, T val)
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)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
float_display_format make_format(const double &d)
static const int max_field_width
std::string row_as_string(octave_idx_type, bool strip_ws=false) 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 pr_int(std::ostream &os, const T &d, int fw=0)
static int engineering_exponent(T x)
void set_output_prec(int prec)
void scale(Matrix &m, double x, double y, double z)
ColumnVector imag(const ComplexColumnVector &a)
if(! arg.isnumeric()) error("rats return retval
std::complex< float > FloatComplex
static int terminal_cols(void)
static void octave_print_free(std::ostream &os, const MT &m, bool pr_as_read_syntax)
int get_file_number(const octave_value &fid) const
std::complex< double > Complex
unsigned char i[sizeof(T)]
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
ColumnVector real(const ComplexColumnVector &a)
Vector representing the dimensions (size) of an Array.
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
nd group nd example For each display the value
bool isnumeric(void) const
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
float_display_format make_scalar_format(const T &val)
charNDArray min(char d, const charNDArray &m)