1 /* |
1 /* |
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
288 } |
288 } |
289 |
289 |
290 return failures; |
290 return failures; |
291 } |
291 } |
292 |
292 |
|
293 private static int arithmeticExceptionTest() { |
|
294 int failures = 0; |
|
295 BigDecimal x; |
|
296 try { |
|
297 // |
|
298 // The string representation "1e2147483647", which is equivalent |
|
299 // to 10^Integer.MAX_VALUE, is used to create an augend with an |
|
300 // unscaled value of 1 and a scale of -Integer.MAX_VALUE. The |
|
301 // addend "1" has an unscaled value of 1 with a scale of 0. The |
|
302 // addition is performed exactly and is specified to have a |
|
303 // preferred scale of max(-Integer.MAX_VALUE, 0). As the scale |
|
304 // of the result is 0, a value with Integer.MAX_VALUE + 1 digits |
|
305 // would need to be created. Therefore the next statement is |
|
306 // expected to overflow with an ArithmeticException. |
|
307 // |
|
308 x = new BigDecimal("1e2147483647").add(new BigDecimal(1)); |
|
309 failures++; |
|
310 } catch (ArithmeticException ae) { |
|
311 } |
|
312 return failures; |
|
313 } |
|
314 |
293 public static void main(String argv[]) { |
315 public static void main(String argv[]) { |
294 int failures = 0; |
316 int failures = 0; |
295 |
317 |
296 failures += extremaTests(); |
318 failures += extremaTests(); |
297 failures += roundingGradationTests(); |
319 failures += roundingGradationTests(); |
298 failures += precisionConsistencyTest(); |
320 failures += precisionConsistencyTest(); |
|
321 failures += arithmeticExceptionTest(); |
299 |
322 |
300 if (failures > 0) { |
323 if (failures > 0) { |
301 throw new RuntimeException("Incurred " + failures + |
324 throw new RuntimeException("Incurred " + failures + |
302 " failures while testing rounding add."); |
325 " failures while testing rounding add."); |
303 } |
326 } |