test/java/util/Formatter/BasicDouble.java

Print this page
rev 7490 : 6469160: (fmt) general (%g) formatting of zero (0.0) with precision 0 or 1 throws ArrayOutOfBoundsException
Summary: For zero value ensure than an unpadded zero character is passed to Formatter.addZeros()
Reviewed-by: TBD
Contributed-by: Brian Burkhalter <brian.burkhalter@oracle.com>


1106 
1107 
1108 
1109 
1110 
1111 
1112 
1113 
1114 
1115 
1116 
1117 
1118 
1119 
1120 
1121 
1122 
1123 
1124 
1125 









1126         //---------------------------------------------------------------------
1127         // %f - float, double, Double, BigDecimal
1128         //---------------------------------------------------------------------
1129         test("%.3f", "3141592.654", mult(pi, 1000000.0));
1130         test("%.3f", "-3141592.654", mult(pi, -1000000.0));
1131         test("%,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1132         test(Locale.FRANCE, "%,.4f", "3\u00a0141\u00a0592,6536", mult(pi, 1000000.0));
1133         test("%,.4f", "-3,141,592.6536", mult(pi, -1000000.0));
1134         test("%(.4f", "3141592.6536", mult(pi, 1000000.0));
1135         test("%(.4f", "(3141592.6536)", mult(pi, -1000000.0));
1136         test("%(,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1137         test("%(,.4f", "(3,141,592.6536)", mult(pi, -1000000.0));
1138 
1139 
1140 
1141 
1142         //---------------------------------------------------------------------
1143         // %g
1144         //
1145         // Floating-point conversions applicable to float, double, and


1151         test("%.0g", "1e+01", ten);
1152         test("%G", "3.14159", pi);
1153         test("%10.3g", "      3.14", pi);
1154         test("%10.3g", "     -3.14", negate(pi));
1155         test("%010.3g", "0000003.14", pi);
1156         test("%010.3g", "-000003.14", negate(pi));
1157         test("%-12.3g", "3.14        ", pi);
1158         test("%-12.3g", "-3.14       ", negate(pi));
1159         test("%.3g", "3.14", pi);
1160         test("%.3g", "-3.14", negate(pi));
1161         test("%.3g", "3.14e+08", mult(pi, 100000000.0));
1162         test("%.3g", "-3.14e+08", mult(pi, -100000000.0));
1163 
1164         test("%.3g", "1.00e-05", recip(create(100000.0)));
1165         test("%.3g", "-1.00e-05", recip(create(-100000.0)));
1166         test("%.0g", "-1e-05", recip(create(-100000.0)));
1167         test("%.0g", "1e+05", create(100000.0));
1168         test("%.3G", "1.00E-05", recip(create(100000.0)));
1169         test("%.3G", "-1.00E-05", recip(create(-100000.0)));
1170 







1171         test("%3.0g", "1e-06", 0.000001);
1172         test("%3.0g", "1e-05", 0.00001);
1173         test("%3.0g", "1e-05", 0.0000099);
1174         test("%3.1g", "1e-05", 0.0000099);
1175         test("%3.2g", "9.9e-06", 0.0000099);
1176         test("%3.0g", "0.0001", 0.0001);
1177         test("%3.0g", "9e-05",  0.00009);
1178         test("%3.0g", "0.0001", 0.000099);
1179         test("%3.1g", "0.0001", 0.000099);
1180         test("%3.2g", "9.9e-05", 0.000099);
1181         test("%3.0g", "0.001", 0.001);
1182         test("%3.0g", "0.001", 0.00099);
1183         test("%3.1g", "0.001", 0.00099);
1184         test("%3.2g", "0.00099", 0.00099);
1185         test("%3.3g", "0.00100", 0.001);
1186         test("%3.4g", "0.001000", 0.001);
1187         test("%3.0g", "0.01", 0.01);
1188         test("%3.0g", "0.1", 0.1);
1189         test("%3.0g", "0.9", 0.9);
1190         test("%3.1g", "0.9", 0.9);




1106 
1107 
1108 
1109 
1110 
1111 
1112 
1113 
1114 
1115 
1116 
1117 
1118 
1119 
1120 
1121 
1122 
1123 
1124 
1125 
1126 
1127 
1128 
1129 
1130 
1131 
1132 
1133 
1134 
1135         //---------------------------------------------------------------------
1136         // %f - float, double, Double, BigDecimal
1137         //---------------------------------------------------------------------
1138         test("%.3f", "3141592.654", mult(pi, 1000000.0));
1139         test("%.3f", "-3141592.654", mult(pi, -1000000.0));
1140         test("%,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1141         test(Locale.FRANCE, "%,.4f", "3\u00a0141\u00a0592,6536", mult(pi, 1000000.0));
1142         test("%,.4f", "-3,141,592.6536", mult(pi, -1000000.0));
1143         test("%(.4f", "3141592.6536", mult(pi, 1000000.0));
1144         test("%(.4f", "(3141592.6536)", mult(pi, -1000000.0));
1145         test("%(,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1146         test("%(,.4f", "(3,141,592.6536)", mult(pi, -1000000.0));
1147 
1148 
1149 
1150 
1151         //---------------------------------------------------------------------
1152         // %g
1153         //
1154         // Floating-point conversions applicable to float, double, and


1160         test("%.0g", "1e+01", ten);
1161         test("%G", "3.14159", pi);
1162         test("%10.3g", "      3.14", pi);
1163         test("%10.3g", "     -3.14", negate(pi));
1164         test("%010.3g", "0000003.14", pi);
1165         test("%010.3g", "-000003.14", negate(pi));
1166         test("%-12.3g", "3.14        ", pi);
1167         test("%-12.3g", "-3.14       ", negate(pi));
1168         test("%.3g", "3.14", pi);
1169         test("%.3g", "-3.14", negate(pi));
1170         test("%.3g", "3.14e+08", mult(pi, 100000000.0));
1171         test("%.3g", "-3.14e+08", mult(pi, -100000000.0));
1172 
1173         test("%.3g", "1.00e-05", recip(create(100000.0)));
1174         test("%.3g", "-1.00e-05", recip(create(-100000.0)));
1175         test("%.0g", "-1e-05", recip(create(-100000.0)));
1176         test("%.0g", "1e+05", create(100000.0));
1177         test("%.3G", "1.00E-05", recip(create(100000.0)));
1178         test("%.3G", "-1.00E-05", recip(create(-100000.0)));
1179 
1180         test("%.1g", "-0", -0.0);
1181         test("%3.0g", " -0", -0.0);
1182         test("%.1g", "0", 0.0);
1183         test("%3.0g", "  0", 0.0);
1184         test("%.1g", "0", +0.0);
1185         test("%3.0g", "  0", +0.0);
1186 
1187         test("%3.0g", "1e-06", 0.000001);
1188         test("%3.0g", "1e-05", 0.00001);
1189         test("%3.0g", "1e-05", 0.0000099);
1190         test("%3.1g", "1e-05", 0.0000099);
1191         test("%3.2g", "9.9e-06", 0.0000099);
1192         test("%3.0g", "0.0001", 0.0001);
1193         test("%3.0g", "9e-05",  0.00009);
1194         test("%3.0g", "0.0001", 0.000099);
1195         test("%3.1g", "0.0001", 0.000099);
1196         test("%3.2g", "9.9e-05", 0.000099);
1197         test("%3.0g", "0.001", 0.001);
1198         test("%3.0g", "0.001", 0.00099);
1199         test("%3.1g", "0.001", 0.00099);
1200         test("%3.2g", "0.00099", 0.00099);
1201         test("%3.3g", "0.00100", 0.001);
1202         test("%3.4g", "0.001000", 0.001);
1203         test("%3.0g", "0.01", 0.01);
1204         test("%3.0g", "0.1", 0.1);
1205         test("%3.0g", "0.9", 0.9);
1206         test("%3.1g", "0.9", 0.9);