comparison src/pr-output.cc @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents 7d6d8c1e471f
children c2a9fd508db4
comparison
equal deleted inserted replaced
11585:1473d0cf86d2 11586:12df7854fa7c
223 * portability issues, we re-implement the modulo function to the desired 223 * portability issues, we re-implement the modulo function to the desired
224 * behavior (truncation). There may be a gnulib replacement. 224 * behavior (truncation). There may be a gnulib replacement.
225 * 225 *
226 * ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, IEC. 2003 . 226 * ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, IEC. 2003 .
227 * "the binary % operator yields the remainder from the division of the first 227 * "the binary % operator yields the remainder from the division of the first
228 * expression by the second. .... If both operands are nonnegative then the 228 * expression by the second. .... If both operands are nonnegative then the
229 * remainder is nonnegative; if not, the sign of the remainder is 229 * remainder is nonnegative; if not, the sign of the remainder is
230 * implementation-defined". */ 230 * implementation-defined". */
231 } 231 }
232 232
233 static int 233 static int
234 engineering_exponent (const double& x) 234 engineering_exponent (const double& x)
239 double absval = (x < 0.0 ? -x : x); 239 double absval = (x < 0.0 ? -x : x);
240 int logabsval = static_cast<int> (gnulib::floor (log10 (absval))); 240 int logabsval = static_cast<int> (gnulib::floor (log10 (absval)));
241 /* Avoid using modulo function with negative arguments for portability. 241 /* Avoid using modulo function with negative arguments for portability.
242 * See extended comment at calc_scale_exp */ 242 * See extended comment at calc_scale_exp */
243 if (logabsval < 0.0) 243 if (logabsval < 0.0)
244 ex = logabsval - 2 + ((-logabsval + 2) % 3); 244 ex = logabsval - 2 + ((-logabsval + 2) % 3);
245 else 245 else
246 ex = logabsval - (logabsval % 3); 246 ex = logabsval - (logabsval % 3);
247 } 247 }
248 return ex; 248 return ex;
249 } 249 }
267 267
268 int exponent (void) const 268 int exponent (void) const
269 { 269 {
270 return engineering_exponent (val); 270 return engineering_exponent (val);
271 } 271 }
272 272
273 double mantissa (void) const 273 double mantissa (void) const
274 { 274 {
275 return val / std::pow (10.0, exponent ()); 275 return val / std::pow (10.0, exponent ());
276 } 276 }
277 277
286 os << std::setw (pef.f.fw - pef.f.ex); 286 os << std::setw (pef.f.fw - pef.f.ex);
287 287
288 if (pef.f.prec >= 0) 288 if (pef.f.prec >= 0)
289 os << std::setprecision (pef.f.prec); 289 os << std::setprecision (pef.f.prec);
290 290
291 std::ios::fmtflags oflags = 291 std::ios::fmtflags oflags =
292 os.flags (static_cast<std::ios::fmtflags> 292 os.flags (static_cast<std::ios::fmtflags>
293 (pef.f.fmt | pef.f.up | pef.f.sp)); 293 (pef.f.fmt | pef.f.up | pef.f.sp));
294 294
295 os << pef.mantissa (); 295 os << pef.mantissa ();
296 296
297 int ex = pef.exponent (); 297 int ex = pef.exponent ();
301 ex = -ex; 301 ex = -ex;
302 } 302 }
303 else 303 else
304 os << std::setw (0) << "e+"; 304 os << std::setw (0) << "e+";
305 305
306 os << std::setw (pef.f.ex - 2) << std::setfill('0') << ex 306 os << std::setw (pef.f.ex - 2) << std::setfill('0') << ex
307 << std::setfill(' '); 307 << std::setfill(' ');
308 308
309 os.flags (oflags); 309 os.flags (oflags);
310 310
311 return os; 311 return os;
331 os << std::setw (pff.f.fw); 331 os << std::setw (pff.f.fw);
332 332
333 if (pff.f.prec >= 0) 333 if (pff.f.prec >= 0)
334 os << std::setprecision (pff.f.prec); 334 os << std::setprecision (pff.f.prec);
335 335
336 std::ios::fmtflags oflags = 336 std::ios::fmtflags oflags =
337 os.flags (static_cast<std::ios::fmtflags> 337 os.flags (static_cast<std::ios::fmtflags>
338 (pff.f.fmt | pff.f.up | pff.f.sp)); 338 (pff.f.fmt | pff.f.up | pff.f.sp));
339 339
340 os << pff.val; 340 os << pff.val;
341 341
342 os.flags (oflags); 342 os.flags (oflags);
372 double frac = val - n; 372 double frac = val - n;
373 int m = 0; 373 int m = 0;
374 374
375 std::ostringstream buf2; 375 std::ostringstream buf2;
376 buf2.flags (std::ios::fixed); 376 buf2.flags (std::ios::fixed);
377 buf2 << std::setprecision (0) << static_cast<int>(n); 377 buf2 << std::setprecision (0) << static_cast<int>(n);
378 s = buf2.str(); 378 s = buf2.str();
379 379
380 while (1) 380 while (1)
381 { 381 {
382 double flip = 1. / frac; 382 double flip = 1. / frac;
398 lastn = nextn; 398 lastn = nextn;
399 lastd = nextd; 399 lastd = nextd;
400 400
401 std::ostringstream buf; 401 std::ostringstream buf;
402 buf.flags (std::ios::fixed); 402 buf.flags (std::ios::fixed);
403 buf << std::setprecision (0) << static_cast<int>(n) 403 buf << std::setprecision (0) << static_cast<int>(n)
404 << "/" << static_cast<int>(d); 404 << "/" << static_cast<int>(d);
405 m++; 405 m++;
406 406
407 if (n < 0 && d < 0) 407 if (n < 0 && d < 0)
408 { 408 {
409 // Double negative, string can be two characters longer.. 409 // Double negative, string can be two characters longer..
410 if (buf.str().length() > static_cast<unsigned int>(len + 2) && 410 if (buf.str().length() > static_cast<unsigned int>(len + 2) &&
411 m > 1) 411 m > 1)
412 break; 412 break;
413 } 413 }
414 else if (buf.str().length() > static_cast<unsigned int>(len) && 414 else if (buf.str().length() > static_cast<unsigned int>(len) &&
415 m > 1) 415 m > 1)
416 break; 416 break;
417 417
418 s = buf.str(); 418 s = buf.str();
419 } 419 }
420 420
423 // Move sign to the top 423 // Move sign to the top
424 lastd = - lastd; 424 lastd = - lastd;
425 lastn = - lastn; 425 lastn = - lastn;
426 std::ostringstream buf; 426 std::ostringstream buf;
427 buf.flags (std::ios::fixed); 427 buf.flags (std::ios::fixed);
428 buf << std::setprecision (0) << static_cast<int>(lastn) 428 buf << std::setprecision (0) << static_cast<int>(lastn)
429 << "/" << static_cast<int>(lastd); 429 << "/" << static_cast<int>(lastd);
430 s = buf.str(); 430 s = buf.str();
431 } 431 }
432 } 432 }
433 433
454 std::string s = rational_approx (prf.val, fw); 454 std::string s = rational_approx (prf.val, fw);
455 455
456 if (fw >= 0) 456 if (fw >= 0)
457 os << std::setw (fw); 457 os << std::setw (fw);
458 458
459 std::ios::fmtflags oflags = 459 std::ios::fmtflags oflags =
460 os.flags (static_cast<std::ios::fmtflags> 460 os.flags (static_cast<std::ios::fmtflags>
461 (prf.f.fmt | prf.f.up | prf.f.sp)); 461 (prf.f.fmt | prf.f.up | prf.f.sp));
462 462
463 if (fw > 0 && s.length() > static_cast<unsigned int>(fw)) 463 if (fw > 0 && s.length() > static_cast<unsigned int>(fw))
464 os << "*"; 464 os << "*";
465 else 465 else
807 807
808 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs); 808 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs);
809 809
810 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs); 810 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs);
811 811
812 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 812 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0
813 : std::pow (10.0, calc_scale_exp (x_max - 1)); 813 : std::pow (10.0, calc_scale_exp (x_max - 1));
814 814
815 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw); 815 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw);
816 } 816 }
817 817
1225 int i_x_min = i_min_abs == 0.0 ? 0 : num_digits (i_min_abs); 1225 int i_x_min = i_min_abs == 0.0 ? 0 : num_digits (i_min_abs);
1226 1226
1227 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; 1227 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
1228 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; 1228 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
1229 1229
1230 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 1230 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0
1231 : std::pow (10.0, calc_scale_exp (x_max - 1)); 1231 : std::pow (10.0, calc_scale_exp (x_max - 1));
1232 1232
1233 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan, 1233 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan,
1234 int_or_inf_or_nan, r_fw, i_fw); 1234 int_or_inf_or_nan, r_fw, i_fw);
1235 } 1235 }
1381 1381
1382 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs); 1382 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs);
1383 1383
1384 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs); 1384 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs);
1385 1385
1386 scale = (x_max == 0 || all_ints) ? 1.0 1386 scale = (x_max == 0 || all_ints) ? 1.0
1387 : std::pow (10.0, calc_scale_exp (x_max - 1)); 1387 : std::pow (10.0, calc_scale_exp (x_max - 1));
1388 1388
1389 set_range_format (x_max, x_min, all_ints, fw); 1389 set_range_format (x_max, x_min, all_ints, fw);
1390 } 1390 }
1391 1391
1486 for (int i = sizeof (double) - 1; i >= 0; i--) 1486 for (int i = sizeof (double) - 1; i >= 0; i--)
1487 os << std::setw (2) << static_cast<int> (tmp.i[i]); 1487 os << std::setw (2) << static_cast<int> (tmp.i[i]);
1488 } 1488 }
1489 1489
1490 os.fill (ofill); 1490 os.fill (ofill);
1491 os.setf (oflags); 1491 os.setf (oflags);
1492 } 1492 }
1493 else if (bit_format) 1493 else if (bit_format)
1494 { 1494 {
1495 equiv tmp; 1495 equiv tmp;
1496 tmp.d = d; 1496 tmp.d = d;
1960 pr_scale_header (os, scale); 1960 pr_scale_header (os, scale);
1961 1961
1962 // kluge. Get the true width of a number. 1962 // kluge. Get the true width of a number.
1963 int zero_fw; 1963 int zero_fw;
1964 1964
1965 { 1965 {
1966 std::ostringstream tmp_oss; 1966 std::ostringstream tmp_oss;
1967 pr_float (tmp_oss, 0.0, fw, scale); 1967 pr_float (tmp_oss, 0.0, fw, scale);
1968 zero_fw = tmp_oss.str ().length (); 1968 zero_fw = tmp_oss.str ().length ();
1969 } 1969 }
1970 1970
2158 { 2158 {
2159 int r_fw, i_fw; 2159 int r_fw, i_fw;
2160 double scale = 1.0; 2160 double scale = 1.0;
2161 set_format (cm, r_fw, i_fw, scale); 2161 set_format (cm, r_fw, i_fw, scale);
2162 int column_width = i_fw + r_fw; 2162 int column_width = i_fw + r_fw;
2163 column_width += (rat_format || bank_format || hex_format 2163 column_width += (rat_format || bank_format || hex_format
2164 || bit_format) ? 2 : 7; 2164 || bit_format) ? 2 : 7;
2165 octave_idx_type total_width = nc * column_width; 2165 octave_idx_type total_width = nc * column_width;
2166 octave_idx_type max_width = command_editor::terminal_cols (); 2166 octave_idx_type max_width = command_editor::terminal_cols ();
2167 2167
2168 if (pr_as_read_syntax) 2168 if (pr_as_read_syntax)
2256 os << " "; 2256 os << " ";
2257 2257
2258 pr_complex (os, cm(i,j), r_fw, i_fw, scale); 2258 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
2259 } 2259 }
2260 2260
2261 if (i < nr - 1) 2261 if (i < nr - 1)
2262 os << "\n"; 2262 os << "\n";
2263 } 2263 }
2264 } 2264 }
2265 } 2265 }
2266 } 2266 }
2294 { 2294 {
2295 int r_fw, i_fw; 2295 int r_fw, i_fw;
2296 double scale = 1.0; 2296 double scale = 1.0;
2297 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); 2297 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale);
2298 int column_width = i_fw + r_fw; 2298 int column_width = i_fw + r_fw;
2299 column_width += (rat_format || bank_format || hex_format 2299 column_width += (rat_format || bank_format || hex_format
2300 || bit_format) ? 2 : 7; 2300 || bit_format) ? 2 : 7;
2301 octave_idx_type total_width = nc * column_width; 2301 octave_idx_type total_width = nc * column_width;
2302 octave_idx_type max_width = command_editor::terminal_cols (); 2302 octave_idx_type max_width = command_editor::terminal_cols ();
2303 2303
2304 if (pr_as_read_syntax) 2304 if (pr_as_read_syntax)
2371 pr_scale_header (os, scale); 2371 pr_scale_header (os, scale);
2372 2372
2373 // kluge. Get the true width of a number. 2373 // kluge. Get the true width of a number.
2374 int zero_fw; 2374 int zero_fw;
2375 2375
2376 { 2376 {
2377 std::ostringstream tmp_oss; 2377 std::ostringstream tmp_oss;
2378 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale); 2378 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale);
2379 zero_fw = tmp_oss.str ().length (); 2379 zero_fw = tmp_oss.str ().length ();
2380 } 2380 }
2381 2381
2400 pr_complex (os, cm(i,j), r_fw, i_fw, scale); 2400 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
2401 else 2401 else
2402 os << std::setw (zero_fw) << '0'; 2402 os << std::setw (zero_fw) << '0';
2403 } 2403 }
2404 2404
2405 if (i < nr - 1) 2405 if (i < nr - 1)
2406 os << "\n"; 2406 os << "\n";
2407 } 2407 }
2408 } 2408 }
2409 } 2409 }
2410 } 2410 }
2560 } 2560 }
2561 } 2561 }
2562 2562
2563 void 2563 void
2564 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax) 2564 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax)
2565 { 2565 {
2566 octave_print_internal (os, double (d), pr_as_read_syntax); 2566 octave_print_internal (os, double (d), pr_as_read_syntax);
2567 } 2567 }
2568 2568
2569 // FIXME -- write single precision versions of the printing functions. 2569 // FIXME -- write single precision versions of the printing functions.
2570 2570
2571 void 2571 void
2572 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax) 2572 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax)
2573 { 2573 {
2574 octave_print_internal (os, double (d), pr_as_read_syntax); 2574 octave_print_internal (os, double (d), pr_as_read_syntax);
2575 } 2575 }
2576 2576
2577 void 2577 void
2578 octave_print_internal (std::ostream& os, const FloatMatrix& m, 2578 octave_print_internal (std::ostream& os, const FloatMatrix& m,
2579 bool pr_as_read_syntax, int extra_indent) 2579 bool pr_as_read_syntax, int extra_indent)
2580 { 2580 {
2581 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent); 2581 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent);
2582 } 2582 }
2583 2583
2584 void 2584 void
2585 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m, 2585 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
2586 bool pr_as_read_syntax, int extra_indent) 2586 bool pr_as_read_syntax, int extra_indent)
2587 { 2587 {
2588 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent); 2588 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent);
2589 } 2589 }
2590 2590
2591 void 2591 void
2592 octave_print_internal (std::ostream& os, const FloatNDArray& nda, 2592 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
2593 bool pr_as_read_syntax, int extra_indent) 2593 bool pr_as_read_syntax, int extra_indent)
2594 { 2594 {
2595 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent); 2595 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent);
2596 } 2596 }
2597 2597
2598 void 2598 void
2599 octave_print_internal (std::ostream& os, const FloatComplex& c, 2599 octave_print_internal (std::ostream& os, const FloatComplex& c,
2600 bool pr_as_read_syntax) 2600 bool pr_as_read_syntax)
2601 { 2601 {
2602 octave_print_internal (os, Complex (c), pr_as_read_syntax); 2602 octave_print_internal (os, Complex (c), pr_as_read_syntax);
2603 } 2603 }
2604 2604
2605 void 2605 void
2606 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm, 2606 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
2607 bool pr_as_read_syntax, int extra_indent) 2607 bool pr_as_read_syntax, int extra_indent)
2975 for (int i = sz - 1; i >= 0; i--) 2975 for (int i = sz - 1; i >= 0; i--)
2976 os << std::setw (2) << static_cast<int> (tmpi[i]); 2976 os << std::setw (2) << static_cast<int> (tmpi[i]);
2977 } 2977 }
2978 2978
2979 os.fill (ofill); 2979 os.fill (ofill);
2980 os.setf (oflags); 2980 os.setf (oflags);
2981 } 2981 }
2982 else if (bit_format) 2982 else if (bit_format)
2983 { 2983 {
2984 if (oct_mach_info::words_big_endian ()) 2984 if (oct_mach_info::words_big_endian ())
2985 { 2985 {
3211 bool isneg = false; 3211 bool isneg = false;
3212 int digits = 0; 3212 int digits = 0;
3213 3213
3214 for (octave_idx_type i = 0; i < dims.numel (); i++) 3214 for (octave_idx_type i = 0; i < dims.numel (); i++)
3215 { 3215 {
3216 int new_digits = static_cast<int> 3216 int new_digits = static_cast<int>
3217 (gnulib::floor (log10 (double (abs (nda(i).value ()))) + 1.0)); 3217 (gnulib::floor (log10 (double (abs (nda(i).value ()))) + 1.0));
3218 3218
3219 if (new_digits > digits) 3219 if (new_digits > digits)
3220 digits = new_digits; 3220 digits = new_digits;
3221 3221
3302 extra_indent); 3302 extra_indent);
3303 3303
3304 for (octave_idx_type ii = 0; ii < n_rows; ii++) 3304 for (octave_idx_type ii = 0; ii < n_rows; ii++)
3305 { 3305 {
3306 os << std::setw (extra_indent) << ""; 3306 os << std::setw (extra_indent) << "";
3307 3307
3308 for (octave_idx_type jj = col; jj < lim; jj++) 3308 for (octave_idx_type jj = col; jj < lim; jj++)
3309 { 3309 {
3310 octave_quit (); 3310 octave_quit ();
3311 os << " "; 3311 os << " ";
3312 pr_int (os, page(ii,jj), fw); 3312 pr_int (os, page(ii,jj), fw);
3516 print_usage (); 3516 print_usage ();
3517 3517
3518 return retval; 3518 return retval;
3519 } 3519 }
3520 3520
3521 /* 3521 /*
3522 %!test 3522 %!test
3523 %! format short 3523 %! format short
3524 %! fd = tmpfile (); 3524 %! fd = tmpfile ();
3525 %! for r = [0, Inf -Inf, NaN] 3525 %! for r = [0, Inf -Inf, NaN]
3526 %! for i = [0, Inf -Inf, NaN] 3526 %! for i = [0, Inf -Inf, NaN]
3527 %! fdisp (fd, complex (r, i)); 3527 %! fdisp (fd, complex (r, i));
3528 %! endfor 3528 %! endfor
3529 %! endfor 3529 %! endfor
3530 %! fclose (fd); 3530 %! fclose (fd);
3531 */ 3531 */
3532 3532
3533 static void 3533 static void
3534 init_format_state (void) 3534 init_format_state (void)
3535 { 3535 {
3536 free_format = false; 3536 free_format = false;