GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pr-flt-fmt.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pr_flt_fmt_h)
24 #define octave_pr_flt_fmt_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iomanip>
29 #include <iosfwd>
30 
31 template <typename T>
33 
34 template <typename T>
36 
37 template <typename T>
39 
40 extern int output_precision (void);
41 
42 extern void set_output_prec (int prec);
43 
44 class
46 {
47 public:
48 
49  float_format (int w = 0, int p = output_precision (), int f = 0)
50  : fw (w), ex (0), prec (p), fmt (f), up (0), sp (0) { }
51 
52  float_format (int w, int e, int p, int f)
53  : fw (w), ex (e), prec (p), fmt (f), up (0), sp (0) { }
54 
55  float_format (const float_format&) = default;
56 
57  float_format& operator = (const float_format&) = default;
58 
59  ~float_format (void) = default;
60 
62  {
63  fmt = std::ios::scientific;
64  return *this;
65  }
66 
68  {
69  fmt = std::ios::fixed;
70  return *this;
71  }
72 
74  {
75  fmt = 0;
76  return *this;
77  }
78 
80  {
81  up = std::ios::uppercase;
82  return *this;
83  }
84 
86  {
87  up = 0;
88  return *this;
89  }
90 
92  {
93  prec = p;
94  return *this;
95  }
96 
98  {
99  fw = w;
100  return *this;
101  }
102 
103  float_format& trailing_zeros (bool tz = true)
104 
105  {
106  sp = (tz ? std::ios::showpoint : 0);
107  return *this;
108  }
109 
110  template <typename T>
111  friend std::ostream&
112  operator << (std::ostream& os, const pr_engineering_float<T>& pef);
113 
114  template <typename T>
115  friend std::ostream&
116  operator << (std::ostream& os, const pr_formatted_float<T>& pff);
117 
118  template <typename T>
119  friend std::ostream&
120  operator << (std::ostream& os, const pr_rational_float<T>& prf);
121 
122  // Field width. Zero means as wide as necessary.
123  int fw;
124 
125  // Exponent Field width. Zero means as wide as necessary.
126  int ex;
127 
128  // Precision.
129  int prec;
130 
131  // Format.
132  int fmt;
133 
134  // E or e.
135  int up;
136 
137  // Show trailing zeros.
138  int sp;
139 };
140 
141 class
143 {
144 public:
145 
146  float_display_format (void) = default;
147 
148  float_display_format (double scale, const float_format& real_fmt,
149  const float_format& imag_fmt = float_format ())
150  : m_scale (scale), m_real_fmt (real_fmt), m_imag_fmt (imag_fmt)
151  { }
152 
153  explicit float_display_format (const float_format& real_fmt,
154  const float_format& imag_fmt = float_format ())
155  : m_scale (1.0), m_real_fmt (real_fmt), m_imag_fmt (imag_fmt)
156  { }
157 
158  float_display_format (const float_display_format&) = default;
159 
160  float_display_format& operator = (const float_display_format&) = default;
161 
162  ~float_display_format (void) = default;
163 
164  double scale_factor (void) const { return m_scale; }
165 
166  float_format real_format (void) const { return m_real_fmt; }
167 
168  float_format imag_format (void) const { return m_imag_fmt; }
169 
170  void set_precision (int prec)
171  {
172  m_real_fmt.prec = prec;
173  m_imag_fmt.prec = prec;
174  }
175 
176 private:
177 
178  double m_scale;
179 
181 
183 };
184 
185 #endif
float_format & fixed(void)
Definition: pr-flt-fmt.h:67
float_format & lowercase(void)
Definition: pr-flt-fmt.h:85
float_format m_real_fmt
Definition: pr-flt-fmt.h:180
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
float_format(int w, int e, int p, int f)
Definition: pr-flt-fmt.h:52
float_format imag_format(void) const
Definition: pr-flt-fmt.h:168
void set_output_prec(int prec)
Definition: pr-flt-fmt.cc:43
float_format m_imag_fmt
Definition: pr-flt-fmt.h:182
i e
Definition: data.cc:2591
float_format real_format(void) const
Definition: pr-flt-fmt.h:166
double scale_factor(void) const
Definition: pr-flt-fmt.h:164
float_format & uppercase(void)
Definition: pr-flt-fmt.h:79
std::complex< double > w(std::complex< double > z, double relerr=0)
float_format & general(void)
Definition: pr-flt-fmt.h:73
float_format(int w=0, int p=output_precision(), int f=0)
Definition: pr-flt-fmt.h:49
int output_precision(void)
Definition: pr-flt-fmt.cc:37
float_display_format(const float_format &real_fmt, const float_format &imag_fmt=float_format())
Definition: pr-flt-fmt.h:153
float_display_format(double scale, const float_format &real_fmt, const float_format &imag_fmt=float_format())
Definition: pr-flt-fmt.h:148
p
Definition: lu.cc:138
float_format & scientific(void)
Definition: pr-flt-fmt.h:61
void scale(Matrix &m, double x, double y, double z)
Definition: graphics.cc:5442
float_format & trailing_zeros(bool tz=true)
Definition: pr-flt-fmt.h:103
float_format & precision(int p)
Definition: pr-flt-fmt.h:91
void set_precision(int prec)
Definition: pr-flt-fmt.h:170
float_format & width(int w)
Definition: pr-flt-fmt.h:97