182 df.setMultiplier(3); 183 check("1000.000", new BigDecimal("333.333")); 184 185 // Confirm that ArithmeticException is handled properly 186 // From: 10000.0000 187 // To: 303.0303 188 df.setMultiplier(33); 189 check("10000.0000", new BigDecimal("303.0303")); 190 } 191 192 /** 193 * Test for division by zero (BigDecimal) 194 */ 195 void test_Parse_in_DecimalFormat_BigDecimal_DivisionByZero() { 196 df = new DecimalFormat(); 197 df.setParseBigDecimal(true); 198 df.setMultiplier(0); 199 200 // From: 1000.000 201 // To: Double.POSITIVE_INFINITY 202 check("1000.000", new Double(Double.POSITIVE_INFINITY)); 203 204 // From: -1000 205 // To: Double.NEGATIVE_INFINITY 206 check("-1000", new Double(Double.NEGATIVE_INFINITY)); 207 208 // From: -0.00 209 // To: Double.NaN 210 check("-0.00", new Double(Double.NaN)); 211 } 212 213 /** 214 * Test for division by zero (Double) 215 */ 216 void test_Parse_in_DecimalFormat_Double_DivisionByZero() { 217 df = new DecimalFormat(); 218 df.setParseBigDecimal(false); 219 df.setMultiplier(0); 220 221 // From: 1000.000 222 // To: Double.POSITIVE_INFINITY 223 check("1000.000", new Double(Double.POSITIVE_INFINITY)); 224 225 // From: -1000.000 226 // To: Double.NEGATIVE_INFINITY 227 check("-1000.000", new Double(Double.NEGATIVE_INFINITY)); 228 229 // From: 0.0 230 // To: Double.NaN 231 check("0.0", new Double(Double.NaN)); 232 233 // From: -0.0 (Double) 234 // To: Double.NaN 235 check("-0.0", new Double(Double.NaN)); 236 237 // From: Double.NaN 238 // To: Double.NaN 239 check("\ufffd", new Double(Double.NaN)); 240 241 // From: Double.POSITIVE_INFINITY 242 // To: Double.NaN 243 check("\u221e", new Double(Double.POSITIVE_INFINITY)); 244 245 // From: Double.NEGATIVE_INFINITY 246 // To: Double.NaN 247 check("-\u221e", new Double(Double.NEGATIVE_INFINITY)); 248 } 249 250 /** 251 * Test for division by zero (Long) 252 */ 253 void test_Parse_in_DecimalFormat_Long_DivisionByZero() { 254 df = new DecimalFormat(); 255 df.setParseBigDecimal(false); 256 df.setMultiplier(0); 257 258 // From: 1000 259 // To: Double.POSITIVE_INFINITY 260 check("1000", new Double(Double.POSITIVE_INFINITY)); 261 262 // From: -1000 263 // To: Double.NEGATIVE_INFINITY 264 check("-1000", new Double(Double.NEGATIVE_INFINITY)); 265 266 // From: -000 (Long) 267 // To: Double.NaN 268 check("-000", new Double(Double.NaN)); 269 } 270 271 /** 272 * Test for normal big numbers which don't have the fraction part 273 */ 274 void test_Parse_in_DecimalFormat_BigInteger() { 275 df = new DecimalFormat(); 276 df.setParseBigDecimal(true); 277 278 // From: 123...890 279 // To: BigDecimal 123...890 280 check(nonsep_int + nonsep_int, new BigDecimal(nonsep_int + nonsep_int)); 281 282 // From: 123,4...7,890 283 // To: BigDecimal 1234...7890 284 check(sep_int + "," + sep_int, new BigDecimal(nonsep_int + nonsep_int)); 285 286 // From: -000...000123...890 287 // To: BigDecimal -123...890 288 check("-" + nonsep_zero + nonsep_int, new BigDecimal("-" + nonsep_int)); 333 334 /** 335 * Test for special numbers 336 * Double.NaN 337 * Double.POSITIVE_INFINITY 338 * Double.NEGATIVE_INFINITY 339 */ 340 void test_Parse_in_DecimalFormat_SpecialNumber() { 341 df = new DecimalFormat(); 342 df.setParseBigDecimal(true); 343 344 String[] numbers = { 345 "0", "0.0", "25", "25.0", "25.5", "\u221e", "\ufffd", 346 "-0", "-0.0", "-25", "-25.0", "-25.5", "-\u221e", 347 }; 348 int multipliers[] = {5, -5}; 349 Number[][] expected = { 350 { 351 new BigDecimal("0"), new BigDecimal("0.0"), new BigDecimal("5"), 352 new BigDecimal("5.0"), new BigDecimal("5.1"), 353 new Double(Double.POSITIVE_INFINITY), new Double(Double.NaN), 354 new BigDecimal("0"), new BigDecimal("0.0"), 355 new BigDecimal("-5"), new BigDecimal("-5.0"), 356 new BigDecimal("-5.1"), 357 new Double(Double.NEGATIVE_INFINITY), new Double(Double.NaN), 358 }, 359 { 360 new BigDecimal("0"), new BigDecimal("0.0"), 361 new BigDecimal("-5"), new BigDecimal("-5.0"), 362 new BigDecimal("-5.1"), 363 new Double(Double.NEGATIVE_INFINITY), new Double(Double.NaN), 364 new BigDecimal("0"), new BigDecimal("0.0"), new BigDecimal("5"), 365 new BigDecimal("5.0"), new BigDecimal("5.1"), 366 new Double(Double.POSITIVE_INFINITY), 367 }, 368 }; 369 370 for (int i = 0; i < multipliers.length; i++) { 371 df.setMultiplier(multipliers[i]); 372 for (int j = 0; j < numbers.length; j++) { 373 check(String.valueOf(numbers[j]), expected[i][j]); 374 } 375 } 376 } 377 378 /** 379 * Test for special numbers 380 */ 381 void test_Parse_in_DecimalFormat_Other() { 382 df = new DecimalFormat(); 383 df.setParseBigDecimal(true); 384 385 String[] numbers = { 386 "-9223372036854775808", // Long.MIN_VALUE | 182 df.setMultiplier(3); 183 check("1000.000", new BigDecimal("333.333")); 184 185 // Confirm that ArithmeticException is handled properly 186 // From: 10000.0000 187 // To: 303.0303 188 df.setMultiplier(33); 189 check("10000.0000", new BigDecimal("303.0303")); 190 } 191 192 /** 193 * Test for division by zero (BigDecimal) 194 */ 195 void test_Parse_in_DecimalFormat_BigDecimal_DivisionByZero() { 196 df = new DecimalFormat(); 197 df.setParseBigDecimal(true); 198 df.setMultiplier(0); 199 200 // From: 1000.000 201 // To: Double.POSITIVE_INFINITY 202 check("1000.000", Double.POSITIVE_INFINITY); 203 204 // From: -1000 205 // To: Double.NEGATIVE_INFINITY 206 check("-1000", Double.NEGATIVE_INFINITY); 207 208 // From: -0.00 209 // To: Double.NaN 210 check("-0.00", Double.NaN); 211 } 212 213 /** 214 * Test for division by zero (Double) 215 */ 216 void test_Parse_in_DecimalFormat_Double_DivisionByZero() { 217 df = new DecimalFormat(); 218 df.setParseBigDecimal(false); 219 df.setMultiplier(0); 220 221 // From: 1000.000 222 // To: Double.POSITIVE_INFINITY 223 check("1000.000", Double.POSITIVE_INFINITY); 224 225 // From: -1000.000 226 // To: Double.NEGATIVE_INFINITY 227 check("-1000.000", Double.NEGATIVE_INFINITY); 228 229 // From: 0.0 230 // To: Double.NaN 231 check("0.0", Double.NaN); 232 233 // From: -0.0 (Double) 234 // To: Double.NaN 235 check("-0.0", Double.NaN); 236 237 // From: Double.NaN 238 // To: Double.NaN 239 check("\ufffd", Double.NaN); 240 241 // From: Double.POSITIVE_INFINITY 242 // To: Double.NaN 243 check("\u221e", Double.POSITIVE_INFINITY); 244 245 // From: Double.NEGATIVE_INFINITY 246 // To: Double.NaN 247 check("-\u221e", Double.NEGATIVE_INFINITY); 248 } 249 250 /** 251 * Test for division by zero (Long) 252 */ 253 void test_Parse_in_DecimalFormat_Long_DivisionByZero() { 254 df = new DecimalFormat(); 255 df.setParseBigDecimal(false); 256 df.setMultiplier(0); 257 258 // From: 1000 259 // To: Double.POSITIVE_INFINITY 260 check("1000", Double.POSITIVE_INFINITY); 261 262 // From: -1000 263 // To: Double.NEGATIVE_INFINITY 264 check("-1000", Double.NEGATIVE_INFINITY); 265 266 // From: -000 (Long) 267 // To: Double.NaN 268 check("-000", Double.NaN); 269 } 270 271 /** 272 * Test for normal big numbers which don't have the fraction part 273 */ 274 void test_Parse_in_DecimalFormat_BigInteger() { 275 df = new DecimalFormat(); 276 df.setParseBigDecimal(true); 277 278 // From: 123...890 279 // To: BigDecimal 123...890 280 check(nonsep_int + nonsep_int, new BigDecimal(nonsep_int + nonsep_int)); 281 282 // From: 123,4...7,890 283 // To: BigDecimal 1234...7890 284 check(sep_int + "," + sep_int, new BigDecimal(nonsep_int + nonsep_int)); 285 286 // From: -000...000123...890 287 // To: BigDecimal -123...890 288 check("-" + nonsep_zero + nonsep_int, new BigDecimal("-" + nonsep_int)); 333 334 /** 335 * Test for special numbers 336 * Double.NaN 337 * Double.POSITIVE_INFINITY 338 * Double.NEGATIVE_INFINITY 339 */ 340 void test_Parse_in_DecimalFormat_SpecialNumber() { 341 df = new DecimalFormat(); 342 df.setParseBigDecimal(true); 343 344 String[] numbers = { 345 "0", "0.0", "25", "25.0", "25.5", "\u221e", "\ufffd", 346 "-0", "-0.0", "-25", "-25.0", "-25.5", "-\u221e", 347 }; 348 int multipliers[] = {5, -5}; 349 Number[][] expected = { 350 { 351 new BigDecimal("0"), new BigDecimal("0.0"), new BigDecimal("5"), 352 new BigDecimal("5.0"), new BigDecimal("5.1"), 353 Double.POSITIVE_INFINITY, Double.NaN, 354 new BigDecimal("0"), new BigDecimal("0.0"), 355 new BigDecimal("-5"), new BigDecimal("-5.0"), 356 new BigDecimal("-5.1"), 357 Double.NEGATIVE_INFINITY, Double.NaN, 358 }, 359 { 360 new BigDecimal("0"), new BigDecimal("0.0"), 361 new BigDecimal("-5"), new BigDecimal("-5.0"), 362 new BigDecimal("-5.1"), 363 Double.NEGATIVE_INFINITY, Double.NaN, 364 new BigDecimal("0"), new BigDecimal("0.0"), new BigDecimal("5"), 365 new BigDecimal("5.0"), new BigDecimal("5.1"), 366 Double.POSITIVE_INFINITY, 367 }, 368 }; 369 370 for (int i = 0; i < multipliers.length; i++) { 371 df.setMultiplier(multipliers[i]); 372 for (int j = 0; j < numbers.length; j++) { 373 check(String.valueOf(numbers[j]), expected[i][j]); 374 } 375 } 376 } 377 378 /** 379 * Test for special numbers 380 */ 381 void test_Parse_in_DecimalFormat_Other() { 382 df = new DecimalFormat(); 383 df.setParseBigDecimal(true); 384 385 String[] numbers = { 386 "-9223372036854775808", // Long.MIN_VALUE |