Mercurial > octave
comparison libinterp/corefcn/pr-output.cc @ 27183:2d9decd77e58
revamp float_format object
* pr-flt-fmt.h: Use m_ prefix for data members. Make data members
privatae and provide accessor functions. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Jun 2019 17:40:36 -0500 |
parents | d0c32d60ed35 |
children | db687716fed6 |
comparison
equal
deleted
inserted
replaced
27182:0beeb6817376 | 27183:2d9decd77e58 |
---|---|
186 { | 186 { |
187 octave::preserve_stream_state stream_state (os); | 187 octave::preserve_stream_state stream_state (os); |
188 | 188 |
189 float_format real_fmt = pef.m_ff; | 189 float_format real_fmt = pef.m_ff; |
190 | 190 |
191 if (real_fmt.fw >= 0) | 191 if (real_fmt.width () >= 0) |
192 os << std::setw (real_fmt.fw - real_fmt.ex); | 192 os << std::setw (real_fmt.width () - real_fmt.exponent_width ()); |
193 | 193 |
194 if (real_fmt.prec >= 0) | 194 if (real_fmt.precision () >= 0) |
195 os << std::setprecision (real_fmt.prec); | 195 os << std::setprecision (real_fmt.precision ()); |
196 | 196 |
197 os.flags (static_cast<std::ios::fmtflags> | 197 os.flags (real_fmt.format_flags ()); |
198 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); | |
199 | 198 |
200 os << pef.mantissa (); | 199 os << pef.mantissa (); |
201 | 200 |
202 int ex = pef.exponent (); | 201 int ex = pef.exponent (); |
203 if (ex < 0) | 202 if (ex < 0) |
206 ex = -ex; | 205 ex = -ex; |
207 } | 206 } |
208 else | 207 else |
209 os << std::setw (0) << "e+"; | 208 os << std::setw (0) << "e+"; |
210 | 209 |
211 os << std::setw (real_fmt.ex - 2) << std::setfill ('0') << ex; | 210 os << std::setw (real_fmt.exponent_width () - 2) |
211 << std::setfill ('0') << ex; | |
212 | 212 |
213 return os; | 213 return os; |
214 } | 214 } |
215 | 215 |
216 template <typename T> | 216 template <typename T> |
219 { | 219 { |
220 octave::preserve_stream_state stream_state (os); | 220 octave::preserve_stream_state stream_state (os); |
221 | 221 |
222 float_format real_fmt = pff.m_ff; | 222 float_format real_fmt = pff.m_ff; |
223 | 223 |
224 if (real_fmt.fw >= 0) | 224 if (real_fmt.width () >= 0) |
225 os << std::setw (real_fmt.fw); | 225 os << std::setw (real_fmt.width ()); |
226 | 226 |
227 if (real_fmt.prec >= 0) | 227 if (real_fmt.precision () >= 0) |
228 os << std::setprecision (real_fmt.prec); | 228 os << std::setprecision (real_fmt.precision ()); |
229 | 229 |
230 os.flags (static_cast<std::ios::fmtflags> | 230 os.flags (real_fmt.format_flags ()); |
231 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); | |
232 | 231 |
233 os << pff.m_val; | 232 os << pff.m_val; |
234 | 233 |
235 return os; | 234 return os; |
236 } | 235 } |
241 { | 240 { |
242 octave::preserve_stream_state stream_state (os); | 241 octave::preserve_stream_state stream_state (os); |
243 | 242 |
244 float_format real_fmt = prf.m_ff; | 243 float_format real_fmt = prf.m_ff; |
245 | 244 |
246 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.fw); | 245 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.width ()); |
247 std::string s = rational_approx (prf.m_val, fw); | 246 std::string s = rational_approx (prf.m_val, fw); |
248 | 247 |
249 if (fw >= 0) | 248 if (fw >= 0) |
250 os << std::setw (fw); | 249 os << std::setw (fw); |
251 | 250 |
252 os.flags (static_cast<std::ios::fmtflags> | 251 os.flags (real_fmt.format_flags ()); |
253 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); | |
254 | 252 |
255 if (fw > 0 && s.length () > static_cast<unsigned int> (fw)) | 253 if (fw > 0 && s.length () > static_cast<unsigned int> (fw)) |
256 os << '*'; | 254 os << '*'; |
257 else | 255 else |
258 os << s; | 256 os << s; |
1298 // for hex and bit formats. | 1296 // for hex and bit formats. |
1299 // | 1297 // |
1300 // {bit,hex}_format == 1: print big-endian | 1298 // {bit,hex}_format == 1: print big-endian |
1301 // {bit,hex}_format == 2: print native | 1299 // {bit,hex}_format == 2: print native |
1302 | 1300 |
1303 int fw = fmt.fw; | 1301 int fw = fmt.width (); |
1304 | 1302 |
1305 if (hex_format) | 1303 if (hex_format) |
1306 { | 1304 { |
1307 octave::preserve_stream_state stream_state (os); | 1305 octave::preserve_stream_state stream_state (os); |
1308 | 1306 |
1753 } | 1751 } |
1754 | 1752 |
1755 static inline int | 1753 static inline int |
1756 get_column_width (const float_display_format& fmt) | 1754 get_column_width (const float_display_format& fmt) |
1757 { | 1755 { |
1758 int r_fw = fmt.real_format().fw; | 1756 int r_fw = fmt.real_format().width (); |
1759 int i_fw = fmt.imag_format().fw; | 1757 int i_fw = fmt.imag_format().width (); |
1760 | 1758 |
1761 int retval = r_fw + i_fw + 2; | 1759 int retval = r_fw + i_fw + 2; |
1762 | 1760 |
1763 if (i_fw && ! (rat_format || bank_format || hex_format || bit_format)) | 1761 if (i_fw && ! (rat_format || bank_format || hex_format || bit_format)) |
1764 retval += 5; | 1762 retval += 5; |
2805 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); | 2803 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); |
2806 else | 2804 else |
2807 { | 2805 { |
2808 float_format r_fmt = fmt.real_format (); | 2806 float_format r_fmt = fmt.real_format (); |
2809 | 2807 |
2810 pr_int (os, val, r_fmt.fw); | 2808 pr_int (os, val, r_fmt.width ()); |
2811 } | 2809 } |
2812 } | 2810 } |
2813 } | 2811 } |
2814 | 2812 |
2815 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ | 2813 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ |