GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pr-output.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pr_output_h)
27 #define octave_pr_output_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 
33 #include "Array-fwd.h"
34 #include "intNDArray-fwd.h"
35 #include "oct-cmplx.h"
36 #include "oct-inttypes-fwd.h"
37 #include "range-fwd.h"
38 
39 #include "pr-flt-fmt.h"
40 
41 class ComplexMatrix;
42 class FloatComplexMatrix;
43 class ComplexDiagMatrix;
45 class ComplexNDArray;
47 class Matrix;
48 class FloatMatrix;
49 class DiagMatrix;
50 class FloatDiagMatrix;
51 class NDArray;
52 class FloatNDArray;
53 class boolMatrix;
54 class boolNDArray;
55 class charMatrix;
56 class charNDArray;
57 class PermMatrix;
58 class Cell;
59 class octave_value;
60 
61 template <typename T>
63 make_format (const std::complex<T>&)
64 {
65  return float_display_format ();
66 }
67 
68 template <>
70 make_format (const std::complex<double>& c);
71 
72 template <>
74 make_format (const std::complex<float>& fc);
75 
76 template <typename T>
78 make_format (const T&)
79 {
80  return float_display_format ();
81 }
82 
83 template <>
85 make_format (const double& d);
86 
87 template <>
89 make_format (const float& f);
90 
91 template <>
93 make_format (const octave::range<double>& r);
94 
95 template <>
97 make_format (const Matrix& m);
98 
99 template <>
101 make_format (const FloatMatrix& m);
102 
103 template <>
105 make_format (const ComplexMatrix& m);
106 
107 template <>
110 
111 template <>
113 make_format (const boolNDArray& nda);
114 
115 template <>
118 
119 template <>
122 
123 template <>
126 
127 template <>
130 
131 template <>
134 
135 template <>
138 
139 template <>
142 
143 template <>
146 
147 template <>
149 make_format (const octave_int8& nda);
150 
151 template <>
153 make_format (const octave_int16& nda);
154 
155 template <>
157 make_format (const octave_int32& nda);
158 
159 template <>
161 make_format (const octave_int64& nda);
162 
163 template <>
165 make_format (const octave_uint8& nda);
166 
167 template <>
169 make_format (const octave_uint16& nda);
170 
171 template <>
173 make_format (const octave_uint32& nda);
174 
175 template <>
177 make_format (const octave_uint64& nda);
178 
179 // FIXME: templates plus specializations might help here.
180 
181 extern OCTINTERP_API void
182 octave_print_internal (std::ostream& os, const float_display_format& fmt,
183  bool d, bool pr_as_read_syntax = false);
184 
185 extern OCTINTERP_API void
186 octave_print_internal (std::ostream& os, bool d,
187  bool pr_as_read_syntax = false);
188 
189 extern OCTINTERP_API void
190 octave_print_internal (std::ostream& os, const float_display_format& fmt,
191  char c, bool pr_as_read_syntax = false);
192 
193 inline void
194 octave_print_internal (std::ostream& os, char c,
195  bool pr_as_read_syntax = false)
196 {
197  float_display_format fmt (float_format (0, 0));
198  octave_print_internal (os, fmt, c, pr_as_read_syntax);
199 }
200 
201 extern OCTINTERP_API void
202 octave_print_internal (std::ostream& os, const float_display_format& fmt,
203  double d, bool pr_as_read_syntax = false);
204 
205 inline void
206 octave_print_internal (std::ostream& os, double d,
207  bool pr_as_read_syntax = false)
208 {
209  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
210 }
211 
212 extern OCTINTERP_API void
213 octave_print_internal (std::ostream& os, const float_display_format& fmt,
214  float d, bool pr_as_read_syntax = false);
215 
216 inline void
217 octave_print_internal (std::ostream& os, float d,
218  bool pr_as_read_syntax = false)
219 {
220  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
221 }
222 
223 extern OCTINTERP_API void
224 octave_print_internal (std::ostream& os, const Matrix& m,
225  bool pr_as_read_syntax = false,
226  int extra_indent = 0);
227 
228 extern OCTINTERP_API void
229 octave_print_internal (std::ostream& os, const FloatMatrix& m,
230  bool pr_as_read_syntax = false,
231  int extra_indent = 0);
232 
233 extern OCTINTERP_API void
234 octave_print_internal (std::ostream& os, const DiagMatrix& m,
235  bool pr_as_read_syntax = false,
236  int extra_indent = 0);
237 
238 extern OCTINTERP_API void
239 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
240  bool pr_as_read_syntax = false,
241  int extra_indent = 0);
242 
243 extern OCTINTERP_API void
244 octave_print_internal (std::ostream& os, const NDArray& nda,
245  bool pr_as_read_syntax = false,
246  int extra_indent = 0);
247 
248 extern OCTINTERP_API void
249 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
250  bool pr_as_read_syntax = false,
251  int extra_indent = 0);
252 
253 extern OCTINTERP_API void
254 octave_print_internal (std::ostream& os, const float_display_format& fmt,
255  const Complex& c, bool pr_as_read_syntax = false);
256 
257 inline void
258 octave_print_internal (std::ostream& os, const Complex& c,
259  bool pr_as_read_syntax = false)
260 {
261  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
262 }
263 
264 extern OCTINTERP_API void
265 octave_print_internal (std::ostream& os, const float_display_format& fmt,
266  const FloatComplex& c, bool pr_as_read_syntax = false);
267 
268 inline void
269 octave_print_internal (std::ostream& os, const FloatComplex& c,
270  bool pr_as_read_syntax = false)
271 {
272  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
273 }
274 
275 extern OCTINTERP_API void
276 octave_print_internal (std::ostream& os, const ComplexMatrix& cm,
277  bool pr_as_read_syntax = false,
278  int extra_indent = 0);
279 
280 extern OCTINTERP_API void
281 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
282  bool pr_as_read_syntax = false,
283  int extra_indent = 0);
284 
285 extern OCTINTERP_API void
286 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
287  bool pr_as_read_syntax = false,
288  int extra_indent = 0);
289 
290 extern OCTINTERP_API void
291 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm,
292  bool pr_as_read_syntax = false,
293  int extra_indent = 0);
294 
295 extern OCTINTERP_API void
296 octave_print_internal (std::ostream& os, const ComplexNDArray& nda,
297  bool pr_as_read_syntax = false,
298  int extra_indent = 0);
299 
300 extern OCTINTERP_API void
301 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
302  bool pr_as_read_syntax = false,
303  int extra_indent = 0);
304 
305 extern OCTINTERP_API void
306 octave_print_internal (std::ostream& os, const PermMatrix& m,
307  bool pr_as_read_syntax = false,
308  int extra_indent = 0);
309 
310 extern OCTINTERP_API void
311 octave_print_internal (std::ostream& os, const octave::range<double>& r,
312  bool pr_as_read_syntax = false,
313  int extra_indent = 0);
314 
315 extern OCTINTERP_API void
316 octave_print_internal (std::ostream& os, const boolMatrix& m,
317  bool pr_as_read_syntax = false,
318  int extra_indent = 0);
319 
320 extern OCTINTERP_API void
321 octave_print_internal (std::ostream& os, const boolNDArray& m,
322  bool pr_as_read_syntax = false,
323  int extra_indent = 0);
324 
325 extern OCTINTERP_API void
326 octave_print_internal (std::ostream& os, const charMatrix& chm,
327  bool pr_as_read_syntax = false,
328  int extra_indent = 0,
329  bool pr_as_string = false);
330 
331 extern OCTINTERP_API void
332 octave_print_internal (std::ostream& os, const charNDArray& nda,
333  bool pr_as_read_syntax = false,
334  int extra_indent = 0,
335  bool pr_as_string = false);
336 
337 extern OCTINTERP_API void
338 octave_print_internal (std::ostream& os, const std::string& s,
339  bool pr_as_read_syntax = false,
340  int extra_indent = 0);
341 
342 extern OCTINTERP_API void
343 octave_print_internal (std::ostream& os, const Array<std::string>& sa,
344  bool pr_as_read_syntax = false,
345  int extra_indent = 0);
346 
347 extern OCTINTERP_API void
348 octave_print_internal (std::ostream& os, const intNDArray<octave_int8>& sa,
349  bool pr_as_read_syntax = false,
350  int extra_indent = 0);
351 
352 extern OCTINTERP_API void
353 octave_print_internal (std::ostream& os, const intNDArray<octave_uint8>& sa,
354  bool pr_as_read_syntax = false,
355  int extra_indent = 0);
356 
357 extern OCTINTERP_API void
358 octave_print_internal (std::ostream& os, const intNDArray<octave_int16>& sa,
359  bool pr_as_read_syntax = false,
360  int extra_indent = 0);
361 
362 extern OCTINTERP_API void
363 octave_print_internal (std::ostream& os, const intNDArray<octave_uint16>& sa,
364  bool pr_as_read_syntax = false,
365  int extra_indent = 0);
366 
367 extern OCTINTERP_API void
368 octave_print_internal (std::ostream& os, const intNDArray<octave_int32>& sa,
369  bool pr_as_read_syntax = false,
370  int extra_indent = 0);
371 
372 extern OCTINTERP_API void
373 octave_print_internal (std::ostream& os, const intNDArray<octave_uint32>& sa,
374  bool pr_as_read_syntax = false,
375  int extra_indent = 0);
376 
377 extern OCTINTERP_API void
378 octave_print_internal (std::ostream& os, const intNDArray<octave_int64>& sa,
379  bool pr_as_read_syntax = false,
380  int extra_indent = 0);
381 
382 extern OCTINTERP_API void
383 octave_print_internal (std::ostream& os, const intNDArray<octave_uint64>& sa,
384  bool pr_as_read_syntax = false,
385  int extra_indent = 0);
386 
387 extern OCTINTERP_API void
388 octave_print_internal (std::ostream& os, const float_display_format&,
389  const octave_int<int8_t>& sa,
390  bool pr_as_read_syntax = false);
391 
392 inline void
393 octave_print_internal (std::ostream& os, const octave_int<int8_t>& sa,
394  bool pr_as_read_syntax = false)
395 {
396  float_display_format fmt (float_format (0, 0));
397  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
398 }
399 
400 extern OCTINTERP_API void
401 octave_print_internal (std::ostream& os, const float_display_format&,
402  const octave_int<uint8_t>& sa,
403  bool pr_as_read_syntax = false);
404 
405 inline void
406 octave_print_internal (std::ostream& os, const octave_int<uint8_t>& sa,
407  bool pr_as_read_syntax = false)
408 {
409  float_display_format fmt (float_format (0, 0));
410  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
411 }
412 
413 extern OCTINTERP_API void
414 octave_print_internal (std::ostream& os, const float_display_format&,
415  const octave_int<int16_t>& sa,
416  bool pr_as_read_syntax = false);
417 
418 inline void
419 octave_print_internal (std::ostream& os, const octave_int<int16_t>& sa,
420  bool pr_as_read_syntax = false)
421 {
422  float_display_format fmt (float_format (0, 0));
423  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
424 }
425 
426 extern OCTINTERP_API void
427 octave_print_internal (std::ostream& os, const float_display_format&,
428  const octave_int<uint16_t>& sa,
429  bool pr_as_read_syntax = false);
430 
431 inline void
432 octave_print_internal (std::ostream& os, const octave_int<uint16_t>& sa,
433  bool pr_as_read_syntax = false)
434 {
435  float_display_format fmt (float_format (0, 0));
436  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
437 }
438 
439 extern OCTINTERP_API void
440 octave_print_internal (std::ostream& os, const float_display_format&,
441  const octave_int<int32_t>& sa,
442  bool pr_as_read_syntax = false);
443 
444 inline void
445 octave_print_internal (std::ostream& os, const octave_int<int32_t>& sa,
446  bool pr_as_read_syntax = false)
447 {
448  float_display_format fmt (float_format (0, 0));
449  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
450 }
451 
452 extern OCTINTERP_API void
453 octave_print_internal (std::ostream& os, const float_display_format&,
454  const octave_int<uint32_t>& sa,
455  bool pr_as_read_syntax = false);
456 
457 inline void
458 octave_print_internal (std::ostream& os, const octave_int<uint32_t>& sa,
459  bool pr_as_read_syntax = false)
460 {
461  float_display_format fmt (float_format (0, 0));
462  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
463 }
464 
465 extern OCTINTERP_API void
466 octave_print_internal (std::ostream& os, const float_display_format&,
467  const octave_int<int64_t>& sa,
468  bool pr_as_read_syntax = false);
469 
470 inline void
471 octave_print_internal (std::ostream& os, const octave_int<int64_t>& sa,
472  bool pr_as_read_syntax = false)
473 {
474  float_display_format fmt (float_format (0, 0));
475  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
476 }
477 
478 extern OCTINTERP_API void
479 octave_print_internal (std::ostream& os, const float_display_format&,
480  const octave_int<uint64_t>& sa,
481  bool pr_as_read_syntax = false);
482 
483 inline void
484 octave_print_internal (std::ostream& os, const octave_int<uint64_t>& sa,
485  bool pr_as_read_syntax = false)
486 {
487  float_display_format fmt (float_format (0, 0));
488  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
489 }
490 
491 extern OCTINTERP_API void
492 octave_print_internal (std::ostream& os, const Cell& cell,
493  bool pr_as_read_syntax = false,
494  int extra_indent = 0,
495  bool pr_as_string = false);
496 
497 inline void
498 octave_print_internal (std::ostream& os, const float_display_format&,
499  const Cell& cell, bool pr_as_read_syntax = false,
500  int extra_indent = 0, bool pr_as_string = false)
501 {
502  octave_print_internal (os, cell, pr_as_read_syntax, extra_indent,
503  pr_as_string);
504 }
505 
506 extern OCTINTERP_API void
507 octave_print_internal (std::ostream& os, const octave_value& ov,
508  bool pr_as_read_syntax = false);
509 
510 template <typename T>
511 class
513 {
514 public:
515 
517 
518  T m_val;
519 
520  int exponent () const;
521 
522  T mantissa () const;
523 
525  : m_ff (ff), m_val (val) { }
526 
528  : m_ff (fdf.real_format ()), m_val (val) { }
529 };
530 
531 template <typename T>
532 class
534 {
535 public:
536 
538 
539  T m_val;
540 
541  pr_formatted_float (const float_format& ff, T val)
542  : m_ff (ff), m_val (val) { }
543 
545  : m_ff (fdf.real_format ()), m_val (val) { }
546 };
547 
548 template <typename T>
549 class
551 {
552 public:
553 
555 
556  T m_val;
557 
558  pr_rational_float (const float_format& ff, T val)
559  : m_ff (ff), m_val (val) { }
560 
562  : m_ff (fdf.real_format ()), m_val (val) { }
563 };
564 
565 template <typename T>
566 extern std::ostream&
567 operator << (std::ostream& os, const pr_engineering_float<T>& pef);
568 
569 template <typename T>
570 extern std::ostream&
571 operator << (std::ostream& os, const pr_formatted_float<T>& pff);
572 
573 template <typename T>
574 extern std::ostream&
575 operator << (std::ostream& os, const pr_rational_float<T>& prf);
576 
577 // TRUE means that the dimensions of empty objects should be printed
578 // like this: x = [](2x0).
579 extern bool Vprint_empty_dimensions;
580 
581 // TRUE means don't put empty lines in output
582 extern bool Vcompact_format;
583 
584 #endif
Definition: Cell.h:43
Definition: dMatrix.h:42
pr_engineering_float(const float_format &ff, T val)
Definition: pr-output.h:524
pr_engineering_float(const float_display_format &fdf, T val)
Definition: pr-output.h:527
const float_format m_ff
Definition: pr-output.h:516
pr_formatted_float(const float_display_format &fdf, T val)
Definition: pr-output.h:544
pr_formatted_float(const float_format &ff, T val)
Definition: pr-output.h:541
const float_format m_ff
Definition: pr-output.h:537
const float_format m_ff
Definition: pr-output.h:554
pr_rational_float(const float_format &ff, T val)
Definition: pr-output.h:558
pr_rational_float(const float_display_format &fdf, T val)
Definition: pr-output.h:561
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE const F77_DBLE * f
T octave_idx_type m
Definition: mx-inlines.cc:781
T * r
Definition: mx-inlines.cc:781
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
float_display_format make_format(const std::complex< T > &)
Definition: pr-output.h:63
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax=false)
Definition: pr-output.cc:1761
bool Vprint_empty_dimensions
Definition: pr-output.cc:71
std::ostream & operator<<(std::ostream &os, const pr_engineering_float< T > &pef)
Definition: pr-output.cc:187
bool Vcompact_format
Definition: pr-output.cc:102