Mercurial > hg > octave-thorsten
comparison src/pr-output.cc @ 1309:c0187e1c02f9
[project @ 1995-06-25 04:00:46 by jwe]
author | jwe |
---|---|
date | Sun, 25 Jun 1995 04:03:14 +0000 |
parents | dac3c9c58b1a |
children | 611d403c7f3d |
comparison
equal
deleted
inserted
replaced
1308:8c8a83cf184a | 1309:c0187e1c02f9 |
---|---|
65 static int bank_format = 0; | 65 static int bank_format = 0; |
66 | 66 |
67 // Nonzero means print data in hexadecimal format. | 67 // Nonzero means print data in hexadecimal format. |
68 static int hex_format = 0; | 68 static int hex_format = 0; |
69 | 69 |
70 // Nonzero means print data in binary-bit-pattern format. | |
71 static int bit_format = 0; | |
72 | |
70 // Nonzero means don't put newlines around the column number headers. | 73 // Nonzero means don't put newlines around the column number headers. |
71 static int compact_format = 0; | 74 static int compact_format = 0; |
72 | 75 |
73 // Nonzero means use an e format. | 76 // Nonzero means use an e format. |
74 static int print_e = 0; | 77 static int print_e = 0; |
86 if (a.elem (i, j) < 0.0) | 89 if (a.elem (i, j) < 0.0) |
87 return 1; | 90 return 1; |
88 return 0; | 91 return 0; |
89 } | 92 } |
90 | 93 |
91 static int | 94 // XXX FIXME XXX -- these should probably be somewhere else. |
95 | |
96 int | |
92 any_element_is_inf_or_nan (const Matrix& a) | 97 any_element_is_inf_or_nan (const Matrix& a) |
93 { | 98 { |
94 int nr = a.rows (); | 99 int nr = a.rows (); |
95 int nc = a.columns (); | 100 int nc = a.columns (); |
96 for (int j = 0; j < nc; j++) | 101 for (int j = 0; j < nc; j++) |
101 return 1; | 106 return 1; |
102 } | 107 } |
103 return 0; | 108 return 0; |
104 } | 109 } |
105 | 110 |
106 static int | 111 int |
107 any_element_is_inf_or_nan (const ComplexMatrix& a) | 112 any_element_is_inf_or_nan (const ComplexMatrix& a) |
108 { | 113 { |
109 int nr = a.rows (); | 114 int nr = a.rows (); |
110 int nc = a.columns (); | 115 int nc = a.columns (); |
111 for (int j = 0; j < nc; j++) | 116 for (int j = 0; j < nc; j++) |
224 else if (hex_format) | 229 else if (hex_format) |
225 { | 230 { |
226 fw = 2 * sizeof (double); | 231 fw = 2 * sizeof (double); |
227 rd = 0; | 232 rd = 0; |
228 } | 233 } |
234 else if (bit_format) | |
235 { | |
236 fw = 8 * sizeof (double); | |
237 rd = 0; | |
238 } | |
229 else if (xisnan (d) || D_NINT (d) == d) | 239 else if (xisnan (d) || D_NINT (d) == d) |
230 { | 240 { |
231 fw = digits; | 241 fw = digits; |
232 if (inf_or_nan && fw < 3) | 242 if (inf_or_nan && fw < 3) |
233 fw = 3; | 243 fw = 3; |
253 if (inf_or_nan && fw < 3) | 263 if (inf_or_nan && fw < 3) |
254 fw = 3; | 264 fw = 3; |
255 fw += sign; | 265 fw += sign; |
256 } | 266 } |
257 | 267 |
258 if (! (bank_format || hex_format) | 268 if (! (bank_format || hex_format || bit_format) |
259 && (fw > user_pref.output_max_field_width || print_e)) | 269 && (fw > user_pref.output_max_field_width || print_e)) |
260 { | 270 { |
261 int exp_field = 4; | 271 int exp_field = 4; |
262 if (digits > 100) | 272 if (digits > 100) |
263 exp_field++; | 273 exp_field++; |
325 else if (hex_format) | 335 else if (hex_format) |
326 { | 336 { |
327 fw = 2 * sizeof (double); | 337 fw = 2 * sizeof (double); |
328 rd = 0; | 338 rd = 0; |
329 } | 339 } |
340 else if (bit_format) | |
341 { | |
342 fw = 8 * sizeof (double); | |
343 rd = 0; | |
344 } | |
330 else if (all_elements_are_int_or_inf_or_nan (m)) | 345 else if (all_elements_are_int_or_inf_or_nan (m)) |
331 { | 346 { |
332 int digits = x_max > x_min ? x_max : x_min; | 347 int digits = x_max > x_min ? x_max : x_min; |
333 fw = digits <= 0 ? 1 : digits; | 348 fw = digits <= 0 ? 1 : digits; |
334 if (inf_or_nan && fw < 3) | 349 if (inf_or_nan && fw < 3) |
373 if (inf_or_nan && fw < 3) | 388 if (inf_or_nan && fw < 3) |
374 fw = 3; | 389 fw = 3; |
375 fw += sign; | 390 fw += sign; |
376 } | 391 } |
377 | 392 |
378 if (! (bank_format ||hex_format) | 393 if (! (bank_format ||hex_format || bit_format) |
379 && (fw > user_pref.output_max_field_width || print_e)) | 394 && (fw > user_pref.output_max_field_width || print_e)) |
380 { | 395 { |
381 int exp_field = 4; | 396 int exp_field = 4; |
382 if (x_max > 100 || x_min > 100) | 397 if (x_max > 100 || x_min > 100) |
383 exp_field++; | 398 exp_field++; |
463 { | 478 { |
464 r_fw = 2 * sizeof (double); | 479 r_fw = 2 * sizeof (double); |
465 i_fw = 2 * sizeof (double); | 480 i_fw = 2 * sizeof (double); |
466 rd = 0; | 481 rd = 0; |
467 } | 482 } |
483 else if (bit_format) | |
484 { | |
485 r_fw = 8 * sizeof (double); | |
486 i_fw = 8 * sizeof (double); | |
487 rd = 0; | |
488 } | |
468 else if (inf_or_nan || (D_NINT (rp) == rp && D_NINT (ip) == ip)) | 489 else if (inf_or_nan || (D_NINT (rp) == rp && D_NINT (ip) == ip)) |
469 { | 490 { |
470 int digits = x_max > x_min ? x_max : x_min; | 491 int digits = x_max > x_min ? x_max : x_min; |
471 i_fw = r_fw = digits <= 0 ? 1 : digits; | 492 i_fw = r_fw = digits <= 0 ? 1 : digits; |
472 if (inf_or_nan && i_fw < 3) | 493 if (inf_or_nan && i_fw < 3) |
511 if (inf_or_nan && i_fw < 3) | 532 if (inf_or_nan && i_fw < 3) |
512 i_fw = r_fw = 3; | 533 i_fw = r_fw = 3; |
513 r_fw += sign; | 534 r_fw += sign; |
514 } | 535 } |
515 | 536 |
516 if (! (bank_format || hex_format) | 537 if (! (bank_format || hex_format || bit_format) |
517 && (r_fw > user_pref.output_max_field_width || print_e)) | 538 && (r_fw > user_pref.output_max_field_width || print_e)) |
518 { | 539 { |
519 int exp_field = 4; | 540 int exp_field = 4; |
520 if (x_max > 100 || x_min > 100) | 541 if (x_max > 100 || x_min > 100) |
521 exp_field++; | 542 exp_field++; |
607 { | 628 { |
608 r_fw = 2 * sizeof (double); | 629 r_fw = 2 * sizeof (double); |
609 i_fw = 2 * sizeof (double); | 630 i_fw = 2 * sizeof (double); |
610 rd = 0; | 631 rd = 0; |
611 } | 632 } |
633 else if (bit_format) | |
634 { | |
635 r_fw = 8 * sizeof (double); | |
636 i_fw = 8 * sizeof (double); | |
637 rd = 0; | |
638 } | |
612 else if (all_elements_are_int_or_inf_or_nan (rp) | 639 else if (all_elements_are_int_or_inf_or_nan (rp) |
613 && all_elements_are_int_or_inf_or_nan (ip)) | 640 && all_elements_are_int_or_inf_or_nan (ip)) |
614 { | 641 { |
615 int digits = x_max > x_min ? x_max : x_min; | 642 int digits = x_max > x_min ? x_max : x_min; |
616 i_fw = r_fw = digits <= 0 ? 1 : digits; | 643 i_fw = r_fw = digits <= 0 ? 1 : digits; |
656 if (inf_or_nan && i_fw < 3) | 683 if (inf_or_nan && i_fw < 3) |
657 i_fw = r_fw = 3; | 684 i_fw = r_fw = 3; |
658 r_fw += sign; | 685 r_fw += sign; |
659 } | 686 } |
660 | 687 |
661 if (! (bank_format || hex_format) | 688 if (! (bank_format || hex_format || bit_format) |
662 && (r_fw > user_pref.output_max_field_width || print_e)) | 689 && (r_fw > user_pref.output_max_field_width || print_e)) |
663 { | 690 { |
664 int exp_field = 4; | 691 int exp_field = 4; |
665 if (x_max > 100 || x_min > 100) | 692 if (x_max > 100 || x_min > 100) |
666 exp_field++; | 693 exp_field++; |
753 else if (hex_format) | 780 else if (hex_format) |
754 { | 781 { |
755 fw = 2 * sizeof (double); | 782 fw = 2 * sizeof (double); |
756 rd = 0; | 783 rd = 0; |
757 } | 784 } |
785 else if (bit_format) | |
786 { | |
787 fw = 8 * sizeof (double); | |
788 rd = 0; | |
789 } | |
758 else if (all_elements_are_ints (r)) | 790 else if (all_elements_are_ints (r)) |
759 { | 791 { |
760 int digits = x_max > x_min ? x_max : x_min; | 792 int digits = x_max > x_min ? x_max : x_min; |
761 fw = sign + digits; | 793 fw = sign + digits; |
762 rd = 0; | 794 rd = 0; |
795 rd = rd_max > rd_min ? rd_max : rd_min; | 827 rd = rd_max > rd_min ? rd_max : rd_min; |
796 | 828 |
797 fw = sign + ld + 1 + rd; | 829 fw = sign + ld + 1 + rd; |
798 } | 830 } |
799 | 831 |
800 if (! (bank_format || hex_format) | 832 if (! (bank_format || hex_format || bit_format) |
801 && (fw > user_pref.output_max_field_width || print_e)) | 833 && (fw > user_pref.output_max_field_width || print_e)) |
802 { | 834 { |
803 int exp_field = 4; | 835 int exp_field = 4; |
804 if (x_max > 100 || x_min > 100) | 836 if (x_max > 100 || x_min > 100) |
805 exp_field++; | 837 exp_field++; |
829 union equiv | 861 union equiv |
830 { | 862 { |
831 double d; | 863 double d; |
832 unsigned char i[sizeof (double)]; | 864 unsigned char i[sizeof (double)]; |
833 }; | 865 }; |
866 | |
867 #define PRINT_CHAR_BITS(os, c) \ | |
868 do \ | |
869 { \ | |
870 unsigned char ctmp = c; \ | |
871 char stmp[9]; \ | |
872 stmp[0] = (c & 0x80) ? '1' : '0'; \ | |
873 stmp[1] = (c & 0x40) ? '1' : '0'; \ | |
874 stmp[2] = (c & 0x20) ? '1' : '0'; \ | |
875 stmp[3] = (c & 0x10) ? '1' : '0'; \ | |
876 stmp[4] = (c & 0x08) ? '1' : '0'; \ | |
877 stmp[5] = (c & 0x04) ? '1' : '0'; \ | |
878 stmp[6] = (c & 0x02) ? '1' : '0'; \ | |
879 stmp[7] = (c & 0x01) ? '1' : '0'; \ | |
880 stmp[8] = '\0'; \ | |
881 os.form ("%s", stmp); \ | |
882 } \ | |
883 while (0) | |
884 | |
885 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ | |
886 do \ | |
887 { \ | |
888 unsigned char ctmp = c; \ | |
889 char stmp[9]; \ | |
890 stmp[0] = (c & 0x01) ? '1' : '0'; \ | |
891 stmp[1] = (c & 0x02) ? '1' : '0'; \ | |
892 stmp[2] = (c & 0x04) ? '1' : '0'; \ | |
893 stmp[3] = (c & 0x08) ? '1' : '0'; \ | |
894 stmp[4] = (c & 0x10) ? '1' : '0'; \ | |
895 stmp[5] = (c & 0x20) ? '1' : '0'; \ | |
896 stmp[6] = (c & 0x40) ? '1' : '0'; \ | |
897 stmp[7] = (c & 0x80) ? '1' : '0'; \ | |
898 stmp[8] = '\0'; \ | |
899 os.form ("%s", stmp); \ | |
900 } \ | |
901 while (0) | |
834 | 902 |
835 static inline void | 903 static inline void |
836 pr_any_float (const char *fmt, ostream& os, double d, int fw = 0) | 904 pr_any_float (const char *fmt, ostream& os, double d, int fw = 0) |
837 { | 905 { |
838 if (d == -0.0) | 906 if (d == -0.0) |
861 } | 929 } |
862 else | 930 else |
863 { | 931 { |
864 for (int i = sizeof (double) - 1; i >= 0; i--) | 932 for (int i = sizeof (double) - 1; i >= 0; i--) |
865 os.form ("%02x", (int) tmp.i[i]); | 933 os.form ("%02x", (int) tmp.i[i]); |
934 } | |
935 } | |
936 else if (bit_format) | |
937 { | |
938 equiv tmp; | |
939 tmp.d = d; | |
940 | |
941 // Unless explicitly asked for, always print in big-endian | |
942 // format. | |
943 | |
944 // XXX FIXME XXX -- is it correct to swap bytes for VAX | |
945 // formats and not for Cray? | |
946 | |
947 if (native_float_format == OCTAVE_IEEE_BIG | |
948 || native_float_format == OCTAVE_CRAY | |
949 || native_float_format == OCTAVE_UNKNOWN_FLT_FMT) | |
950 { | |
951 for (int i = 0; i < sizeof (double); i++) | |
952 PRINT_CHAR_BITS (os, tmp.i[i]); | |
953 } | |
954 else | |
955 { | |
956 if (bit_format > 1) | |
957 { | |
958 for (int i = 0; i < sizeof (double); i++) | |
959 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); | |
960 } | |
961 else | |
962 { | |
963 for (int i = sizeof (double) - 1; i >= 0; i--) | |
964 PRINT_CHAR_BITS (os, tmp.i[i]); | |
965 } | |
866 } | 966 } |
867 } | 967 } |
868 else if (xisinf (d)) | 968 else if (xisinf (d)) |
869 { | 969 { |
870 char *s; | 970 char *s; |
910 double r = c.real (); | 1010 double r = c.real (); |
911 pr_float (os, r, r_fw); | 1011 pr_float (os, r, r_fw); |
912 if (! bank_format) | 1012 if (! bank_format) |
913 { | 1013 { |
914 double i = c.imag (); | 1014 double i = c.imag (); |
915 if (! hex_format && i < 0) | 1015 if (! (hex_format || bit_format) && i < 0) |
916 { | 1016 { |
917 os << " - "; | 1017 os << " - "; |
918 i = -i; | 1018 i = -i; |
919 pr_imag_float (os, i, i_fw); | 1019 pr_imag_float (os, i, i_fw); |
920 } | 1020 } |
921 else | 1021 else |
922 { | 1022 { |
923 if (hex_format) | 1023 if (hex_format || bit_format) |
924 os << " "; | 1024 os << " "; |
925 else | 1025 else |
926 os << " + "; | 1026 os << " + "; |
927 | 1027 |
928 pr_imag_float (os, i, i_fw); | 1028 pr_imag_float (os, i, i_fw); |
1170 else | 1270 else |
1171 { | 1271 { |
1172 int r_fw, i_fw; | 1272 int r_fw, i_fw; |
1173 set_format (cm, r_fw, i_fw); | 1273 set_format (cm, r_fw, i_fw); |
1174 int column_width = i_fw + r_fw; | 1274 int column_width = i_fw + r_fw; |
1175 column_width += (bank_format || hex_format) ? 2 : 7; | 1275 column_width += (bank_format || hex_format|| bit_format) ? 2 : 7; |
1176 int total_width = nc * column_width; | 1276 int total_width = nc * column_width; |
1177 int max_width = terminal_columns (); | 1277 int max_width = terminal_columns (); |
1178 | 1278 |
1179 if (pr_as_read_syntax) | 1279 if (pr_as_read_syntax) |
1180 max_width -= 4; | 1280 max_width -= 4; |
1371 { | 1471 { |
1372 free_format = 0; | 1472 free_format = 0; |
1373 plus_format = 0; | 1473 plus_format = 0; |
1374 bank_format = 0; | 1474 bank_format = 0; |
1375 hex_format = 0; | 1475 hex_format = 0; |
1476 bit_format = 0; | |
1376 print_e = 0; | 1477 print_e = 0; |
1377 print_big_e = 0; | 1478 print_big_e = 0; |
1378 } | 1479 } |
1379 | 1480 |
1380 static void | 1481 static void |
1459 else if (strcmp (*argv, "native-hex") == 0) | 1560 else if (strcmp (*argv, "native-hex") == 0) |
1460 { | 1561 { |
1461 init_format_state (); | 1562 init_format_state (); |
1462 hex_format = 2; | 1563 hex_format = 2; |
1463 } | 1564 } |
1565 else if (strcmp (*argv, "bit") == 0) | |
1566 { | |
1567 init_format_state (); | |
1568 bit_format = 1; | |
1569 } | |
1570 else if (strcmp (*argv, "native-bit") == 0) | |
1571 { | |
1572 init_format_state (); | |
1573 bit_format = 2; | |
1574 } | |
1464 else if (strcmp (*argv, "+") == 0 || strcmp (*argv, "plus") == 0) | 1575 else if (strcmp (*argv, "+") == 0 || strcmp (*argv, "plus") == 0) |
1465 { | 1576 { |
1466 init_format_state (); | 1577 init_format_state (); |
1467 plus_format = 1; | 1578 plus_format = 1; |
1468 } | 1579 } |