comparison src/pr-output.cc @ 7465:8d6ab12f8fda

format Range output more like N-d arrays
author John W. Eaton <jwe@octave.org>
date Sat, 09 Feb 2008 03:37:39 -0500
parents 2eb392d058bb
children 9369589f2ba5
comparison
equal deleted inserted replaced
7464:2a1cb886ec98 7465:8d6ab12f8fda
1086 double scale; 1086 double scale;
1087 set_format (cm, r_fw, i_fw, scale); 1087 set_format (cm, r_fw, i_fw, scale);
1088 } 1088 }
1089 1089
1090 static void 1090 static void
1091 set_range_format (bool sign, int x_max, int x_min, int all_ints, int& fw) 1091 set_range_format (int x_max, int x_min, int all_ints, int& fw)
1092 { 1092 {
1093 static float_format fmt; 1093 static float_format fmt;
1094 1094
1095 int prec = Voutput_precision; 1095 int prec = Voutput_precision;
1096 1096
1102 rd = 0; 1102 rd = 0;
1103 } 1103 }
1104 else if (bank_format) 1104 else if (bank_format)
1105 { 1105 {
1106 int digits = x_max > x_min ? x_max : x_min; 1106 int digits = x_max > x_min ? x_max : x_min;
1107 fw = sign + digits < 0 ? 4 : digits + 3; 1107 fw = digits < 0 ? 5 : digits + 4;
1108 rd = 2; 1108 rd = 2;
1109 } 1109 }
1110 else if (hex_format) 1110 else if (hex_format)
1111 { 1111 {
1112 fw = 2 * sizeof (double); 1112 fw = 2 * sizeof (double);
1118 rd = 0; 1118 rd = 0;
1119 } 1119 }
1120 else if (all_ints) 1120 else if (all_ints)
1121 { 1121 {
1122 int digits = x_max > x_min ? x_max : x_min; 1122 int digits = x_max > x_min ? x_max : x_min;
1123 fw = sign + digits; 1123 fw = digits + 1;
1124 rd = fw; 1124 rd = fw;
1125 } 1125 }
1126 else if (Vfixed_point_format && ! print_g) 1126 else if (Vfixed_point_format && ! print_g)
1127 { 1127 {
1128 rd = prec; 1128 rd = prec;
1129 fw = rd + 2 + sign; 1129 fw = rd + 3;
1130 } 1130 }
1131 else 1131 else
1132 { 1132 {
1133 int ld_max, rd_max; 1133 int ld_max, rd_max;
1134 if (x_max > 0) 1134 if (x_max > 0)
1159 } 1159 }
1160 1160
1161 ld = ld_max > ld_min ? ld_max : ld_min; 1161 ld = ld_max > ld_min ? ld_max : ld_min;
1162 rd = rd_max > rd_min ? rd_max : rd_min; 1162 rd = rd_max > rd_min ? rd_max : rd_min;
1163 1163
1164 fw = sign + 1 + ld + 1 + rd; 1164 fw = ld + rd + 3;
1165 } 1165 }
1166 1166
1167 if (! (rat_format || bank_format || hex_format || bit_format) 1167 if (! (rat_format || bank_format || hex_format || bit_format)
1168 && (print_e 1168 && (print_e
1169 || print_g 1169 || print_g
1175 { 1175 {
1176 int exp_field = 4; 1176 int exp_field = 4;
1177 if (x_max > 100 || x_min > 100) 1177 if (x_max > 100 || x_min > 100)
1178 exp_field++; 1178 exp_field++;
1179 1179
1180 fw = sign + 2 + prec + exp_field; 1180 fw = 3 + prec + exp_field;
1181 1181
1182 fmt = float_format (fw, prec - 1, std::ios::scientific); 1182 fmt = float_format (fw, prec - 1, std::ios::scientific);
1183 } 1183 }
1184 1184
1185 if (print_big_e) 1185 if (print_big_e)
1210 double tmp = r_max; 1210 double tmp = r_max;
1211 r_max = r_min; 1211 r_max = r_min;
1212 r_min = tmp; 1212 r_min = tmp;
1213 } 1213 }
1214 1214
1215 bool sign = (r_min < 0.0);
1216
1217 bool all_ints = r.all_elements_are_ints (); 1215 bool all_ints = r.all_elements_are_ints ();
1218 1216
1219 double max_abs = r_max < 0.0 ? -r_max : r_max; 1217 double max_abs = r_max < 0.0 ? -r_max : r_max;
1220 double min_abs = r_min < 0.0 ? -r_min : r_min; 1218 double min_abs = r_min < 0.0 ? -r_min : r_min;
1221 1219
1225 int x_min = min_abs == 0.0 1223 int x_min = min_abs == 0.0
1226 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); 1224 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0));
1227 1225
1228 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1); 1226 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1);
1229 1227
1230 set_range_format (sign, x_max, x_min, all_ints, fw); 1228 set_range_format (x_max, x_min, all_ints, fw);
1231 } 1229 }
1232 1230
1233 static inline void 1231 static inline void
1234 set_format (const Range& r) 1232 set_format (const Range& r)
1235 { 1233 {