comparison src/pr-output.cc @ 3013:66a1cede95e7

[project @ 1997-06-02 19:35:05 by jwe]
author jwe
date Mon, 02 Jun 1997 19:41:17 +0000
parents 66ef74ee5d9f
children 38de16594cb4
comparison
equal deleted inserted replaced
3012:0ea30e0e86cc 3013:66a1cede95e7
28 #include <cstdio> 28 #include <cstdio>
29 #include <cstring> 29 #include <cstring>
30 30
31 #include <string> 31 #include <string>
32 32
33 #include <iomanip.h>
33 #include <iostream.h> 34 #include <iostream.h>
34 #include <strstream.h> 35 #include <strstream.h>
35 36
36 #include "CMatrix.h" 37 #include "CMatrix.h"
37 #include "Range.h" 38 #include "Range.h"
880 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ 881 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
881 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ 882 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
882 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ 883 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
883 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ 884 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
884 stmp[8] = '\0'; \ 885 stmp[8] = '\0'; \
885 os.form ("%s", stmp); \ 886 os << stmp; \
886 } \ 887 } \
887 while (0) 888 while (0)
888 889
889 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ 890 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
890 do \ 891 do \
898 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ 899 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
899 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ 900 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
900 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ 901 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
901 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ 902 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
902 stmp[8] = '\0'; \ 903 stmp[8] = '\0'; \
903 os.form ("%s", stmp); \ 904 os << stmp; \
904 } \ 905 } \
905 while (0) 906 while (0)
906 907
907 static void 908 static void
908 pr_any_float (const char *fmt, ostream& os, double d, int fw = 0) 909 pr_any_float (const char *fmt, ostream& os, double d, int fw = 0)
927 // format. 928 // format.
928 929
929 // XXX FIXME XXX -- is it correct to swap bytes for VAX 930 // XXX FIXME XXX -- is it correct to swap bytes for VAX
930 // formats and not for Cray? 931 // formats and not for Cray?
931 932
933 // XXX FIXME XXX -- will bad things happen if we are
934 // interrupted before resetting the format flags and fill
935 // character?
936
932 oct_mach_info::float_format flt_fmt = 937 oct_mach_info::float_format flt_fmt =
933 oct_mach_info::native_float_format (); 938 oct_mach_info::native_float_format ();
939
940 char ofill = os.fill ('0');
941
942 ios::fmtflags oflags = os.setf (ios::right);
943 os.setf (ios::hex, ios::basefield);
934 944
935 if (hex_format > 1 945 if (hex_format > 1
936 || flt_fmt == oct_mach_info::ieee_big_endian 946 || flt_fmt == oct_mach_info::ieee_big_endian
937 || flt_fmt == oct_mach_info::cray 947 || flt_fmt == oct_mach_info::cray
938 || flt_fmt == oct_mach_info::unknown) 948 || flt_fmt == oct_mach_info::unknown)
939 { 949 {
940 for (size_t i = 0; i < sizeof (double); i++) 950 for (size_t i = 0; i < sizeof (double); i++)
941 os.form ("%02x", static_cast<int> (tmp.i[i])); 951 os << setw (2) << static_cast<int> (tmp.i[i]);
942 } 952 }
943 else 953 else
944 { 954 {
945 for (int i = sizeof (double) - 1; i >= 0; i--) 955 for (int i = sizeof (double) - 1; i >= 0; i--)
946 os.form ("%02x", static_cast<int> (tmp.i[i])); 956 os << setw (2) << static_cast<int> (tmp.i[i]);
947 } 957 }
958
959 os.fill (ofill);
960 os.setf (oflags);
948 } 961 }
949 else if (bit_format) 962 else if (bit_format)
950 { 963 {
951 equiv tmp; 964 equiv tmp;
952 tmp.d = d; 965 tmp.d = d;
988 s = "-Inf"; 1001 s = "-Inf";
989 else 1002 else
990 s = "Inf"; 1003 s = "Inf";
991 1004
992 if (fw > 0) 1005 if (fw > 0)
993 os.form ("%*s", fw, s); 1006 os << setw (fw) << s;
994 else 1007 else
995 os << s; 1008 os << s;
996 } 1009 }
997 else if (xisnan (d)) 1010 else if (xisnan (d))
998 { 1011 {
999 if (fw > 0) 1012 if (fw > 0)
1000 os.form ("%*s", fw, "NaN"); 1013 os << setw (fw) << "NaN";
1001 else 1014 else
1002 os << "NaN"; 1015 os << "NaN";
1003 } 1016 }
1004 else 1017 else
1005 os.form (fmt, d); 1018 os.form (fmt, d);
1076 if (col != 0 && ! compact_format) 1089 if (col != 0 && ! compact_format)
1077 os << "\n\n"; 1090 os << "\n\n";
1078 1091
1079 int num_cols = lim - col; 1092 int num_cols = lim - col;
1080 1093
1081 os.form ("%*s", extra_indent, ""); 1094 os << setw (extra_indent) << "";
1082 1095
1083 if (num_cols == 1) 1096 if (num_cols == 1)
1084 os << " Column " << col + 1 << ":\n"; 1097 os << " Column " << col + 1 << ":\n";
1085 else if (num_cols == 2) 1098 else if (num_cols == 2)
1086 os << " Columns " << col + 1 << " and " << lim << ":\n"; 1099 os << " Columns " << col + 1 << " and " << lim << ":\n";
1224 pr_col_num_header (os, total_width, max_width, lim, col, 1237 pr_col_num_header (os, total_width, max_width, lim, col,
1225 extra_indent); 1238 extra_indent);
1226 1239
1227 for (int i = 0; i < nr; i++) 1240 for (int i = 0; i < nr; i++)
1228 { 1241 {
1229 os.form ("%*s", extra_indent, ""); 1242 os << setw (extra_indent) << "";
1230 1243
1231 for (int j = col; j < lim; j++) 1244 for (int j = col; j < lim; j++)
1232 { 1245 {
1233 os << " "; 1246 os << " ";
1234 1247
1377 pr_col_num_header (os, total_width, max_width, lim, col, 1390 pr_col_num_header (os, total_width, max_width, lim, col,
1378 extra_indent); 1391 extra_indent);
1379 1392
1380 for (int i = 0; i < nr; i++) 1393 for (int i = 0; i < nr; i++)
1381 { 1394 {
1382 os.form ("%*s", extra_indent, ""); 1395 os << setw (extra_indent) << "";
1383 1396
1384 for (int j = col; j < lim; j++) 1397 for (int j = col; j < lim; j++)
1385 { 1398 {
1386 os << " "; 1399 os << " ";
1387 1400
1474 int lim = col + inc < num_elem ? col + inc : num_elem; 1487 int lim = col + inc < num_elem ? col + inc : num_elem;
1475 1488
1476 pr_col_num_header (os, total_width, max_width, lim, col, 1489 pr_col_num_header (os, total_width, max_width, lim, col,
1477 extra_indent); 1490 extra_indent);
1478 1491
1479 os.form ("%*s", extra_indent, ""); 1492 os << setw (extra_indent) << "";
1480 1493
1481 for (int i = col; i < lim; i++) 1494 for (int i = col; i < lim; i++)
1482 { 1495 {
1483 double val = base + i * increment; 1496 double val = base + i * increment;
1484 os << " "; 1497 os << " ";