Mercurial > octave
comparison libinterp/corefcn/pr-output.cc @ 30216:c2132e0147ff
maint: use ALL_CAPS for static const variables used as constants.
* pr-output.cc (pr_output_traits): Rename "const int" class variable "digits10"
to "DIGITS10". Rename class variable "max_field_width" to "MAX_FIELD_WIDTH".
author | Rik <rik@octave.org> |
---|---|
date | Mon, 27 Sep 2021 20:30:57 -0700 |
parents | 428cccc75cc9 |
children | 81d26e8481a6 |
comparison
equal
deleted
inserted
replaced
30215:8398d31dab76 | 30216:c2132e0147ff |
---|---|
359 } | 359 } |
360 | 360 |
361 template <typename> | 361 template <typename> |
362 struct pr_output_traits | 362 struct pr_output_traits |
363 { | 363 { |
364 static const int digits10; | 364 static const int DIGITS10; |
365 static const int max_field_width; | 365 static const int MAX_FIELD_WIDTH; |
366 }; | 366 }; |
367 | 367 |
368 template <> | 368 template <> |
369 struct pr_output_traits<double> | 369 struct pr_output_traits<double> |
370 { | 370 { |
371 static const int digits10; | 371 static const int DIGITS10; |
372 static const int max_field_width; | 372 static const int MAX_FIELD_WIDTH; |
373 }; | 373 }; |
374 | 374 |
375 const int pr_output_traits<double>::digits10 = 16; | 375 const int pr_output_traits<double>::DIGITS10 = 16; |
376 const int pr_output_traits<double>::max_field_width = 21; | 376 const int pr_output_traits<double>::MAX_FIELD_WIDTH = 21; |
377 | 377 |
378 template <> | 378 template <> |
379 struct pr_output_traits<float> | 379 struct pr_output_traits<float> |
380 { | 380 { |
381 static const int digits10; | 381 static const int DIGITS10; |
382 static const int max_field_width; | 382 static const int MAX_FIELD_WIDTH; |
383 }; | 383 }; |
384 | 384 |
385 const int pr_output_traits<float>::digits10 = 8; | 385 const int pr_output_traits<float>::DIGITS10 = 8; |
386 const int pr_output_traits<float>::max_field_width = 13; | 386 const int pr_output_traits<float>::MAX_FIELD_WIDTH = 13; |
387 | 387 |
388 // FIXME: it would be nice to share more code among these functions,.. | 388 // FIXME: it would be nice to share more code among these functions,.. |
389 | 389 |
390 // Works for double and float. | 390 // Works for double and float. |
391 | 391 |
393 static inline float_display_format | 393 static inline float_display_format |
394 make_real_format (int digits, bool inf_or_nan, bool int_only) | 394 make_real_format (int digits, bool inf_or_nan, bool int_only) |
395 { | 395 { |
396 float_format fmt; | 396 float_format fmt; |
397 | 397 |
398 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 398 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10); |
399 | 399 |
400 int fw = 0, ld = 0, rd = 0; | 400 int fw = 0, ld = 0, rd = 0; |
401 | 401 |
402 if (rat_format) | 402 if (rat_format) |
403 { | 403 { |
452 fw = ld + 1 + rd; | 452 fw = ld + 1 + rd; |
453 } | 453 } |
454 | 454 |
455 if (! (rat_format || bank_format || hex_format || bit_format) | 455 if (! (rat_format || bank_format || hex_format || bit_format) |
456 && (print_e || print_g || print_eng | 456 && (print_e || print_g || print_eng |
457 || ld + rd > pr_output_traits<T>::digits10 | 457 || ld + rd > pr_output_traits<T>::DIGITS10 |
458 || fw > pr_output_traits<T>::max_field_width | 458 || fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
459 || ld + rd > (1.5 * prec))) | 459 || ld + rd > (1.5 * prec))) |
460 { | 460 { |
461 if (print_g) | 461 if (print_g) |
462 fmt = float_format (prec, prec); | 462 fmt = float_format (prec, prec); |
463 else | 463 else |
542 T scale = ((x_max == 0 || int_or_inf_or_nan) | 542 T scale = ((x_max == 0 || int_or_inf_or_nan) |
543 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | 543 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
544 | 544 |
545 float_format fmt; | 545 float_format fmt; |
546 | 546 |
547 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 547 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10); |
548 | 548 |
549 int fw = 0, ld = 0, rd = 0; | 549 int fw = 0, ld = 0, rd = 0; |
550 | 550 |
551 if (rat_format) | 551 if (rat_format) |
552 { | 552 { |
635 } | 635 } |
636 | 636 |
637 if (! (rat_format || bank_format || hex_format || bit_format) | 637 if (! (rat_format || bank_format || hex_format || bit_format) |
638 && (print_e || print_eng || print_g | 638 && (print_e || print_eng || print_g |
639 || (! Vfixed_point_format | 639 || (! Vfixed_point_format |
640 && (ld + rd > pr_output_traits<T>::digits10 | 640 && (ld + rd > pr_output_traits<T>::DIGITS10 |
641 || fw > pr_output_traits<T>::max_field_width | 641 || fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
642 || ld + rd > (1.5 * prec))))) | 642 || ld + rd > (1.5 * prec))))) |
643 { | 643 { |
644 if (print_g) | 644 if (print_g) |
645 fmt = float_format (prec+6, prec); | 645 fmt = float_format (prec+6, prec); |
646 else | 646 else |
724 bool inf_or_nan, int int_only) | 724 bool inf_or_nan, int int_only) |
725 { | 725 { |
726 float_format r_fmt; | 726 float_format r_fmt; |
727 float_format i_fmt; | 727 float_format i_fmt; |
728 | 728 |
729 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 729 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10); |
730 | 730 |
731 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; | 731 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; |
732 | 732 |
733 if (rat_format) | 733 if (rat_format) |
734 { | 734 { |
821 r_fw = i_fw + 1; | 821 r_fw = i_fw + 1; |
822 } | 822 } |
823 | 823 |
824 if (! (rat_format || bank_format || hex_format || bit_format) | 824 if (! (rat_format || bank_format || hex_format || bit_format) |
825 && (print_e || print_eng || print_g | 825 && (print_e || print_eng || print_g |
826 || ld + rd > pr_output_traits<T>::digits10 | 826 || ld + rd > pr_output_traits<T>::DIGITS10 |
827 || r_fw > pr_output_traits<T>::max_field_width | 827 || r_fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
828 || i_fw > pr_output_traits<T>::max_field_width | 828 || i_fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
829 || ld + rd > (1.5 * prec))) | 829 || ld + rd > (1.5 * prec))) |
830 { | 830 { |
831 if (print_g) | 831 if (print_g) |
832 { | 832 { |
833 int width = prec + 6; | 833 int width = prec + 6; |
950 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | 950 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
951 | 951 |
952 float_format r_fmt; | 952 float_format r_fmt; |
953 float_format i_fmt; | 953 float_format i_fmt; |
954 | 954 |
955 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 955 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10); |
956 | 956 |
957 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; | 957 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; |
958 | 958 |
959 if (rat_format) | 959 if (rat_format) |
960 { | 960 { |
1059 } | 1059 } |
1060 | 1060 |
1061 if (! (rat_format || bank_format || hex_format || bit_format) | 1061 if (! (rat_format || bank_format || hex_format || bit_format) |
1062 && (print_e || print_eng || print_g | 1062 && (print_e || print_eng || print_g |
1063 || (! Vfixed_point_format | 1063 || (! Vfixed_point_format |
1064 && (ld + rd > pr_output_traits<T>::digits10 | 1064 && (ld + rd > pr_output_traits<T>::DIGITS10 |
1065 || r_fw > pr_output_traits<T>::max_field_width | 1065 || r_fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
1066 || i_fw > pr_output_traits<T>::max_field_width | 1066 || i_fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
1067 || ld + rd > (1.5 * prec))))) | 1067 || ld + rd > (1.5 * prec))))) |
1068 { | 1068 { |
1069 if (print_g) | 1069 if (print_g) |
1070 { | 1070 { |
1071 int width = prec + 6; | 1071 int width = prec + 6; |
1193 double scale = ((x_max == 0 || all_ints) | 1193 double scale = ((x_max == 0 || all_ints) |
1194 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | 1194 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
1195 | 1195 |
1196 float_format fmt; | 1196 float_format fmt; |
1197 | 1197 |
1198 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 1198 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10); |
1199 | 1199 |
1200 int fw = 0, ld = 0, rd = 0; | 1200 int fw = 0, ld = 0, rd = 0; |
1201 | 1201 |
1202 if (rat_format) | 1202 if (rat_format) |
1203 { | 1203 { |
1280 } | 1280 } |
1281 | 1281 |
1282 if (! (rat_format || bank_format || hex_format || bit_format) | 1282 if (! (rat_format || bank_format || hex_format || bit_format) |
1283 && (print_e || print_eng || print_g | 1283 && (print_e || print_eng || print_g |
1284 || (! Vfixed_point_format | 1284 || (! Vfixed_point_format |
1285 && (ld + rd > pr_output_traits<T>::digits10 | 1285 && (ld + rd > pr_output_traits<T>::DIGITS10 |
1286 || fw > pr_output_traits<T>::max_field_width | 1286 || fw > pr_output_traits<T>::MAX_FIELD_WIDTH |
1287 || ld + rd > (1.5 * prec))))) | 1287 || ld + rd > (1.5 * prec))))) |
1288 { | 1288 { |
1289 if (print_g) | 1289 if (print_g) |
1290 fmt = float_format (prec+6, prec); | 1290 fmt = float_format (prec+6, prec); |
1291 else | 1291 else |