8289260: BigDecimal movePointLeft() and movePointRight() do not follow their API spec

Reviewed-by: darcy
This commit is contained in:
Raffaello Giulietti 2022-07-06 16:22:18 +00:00 committed by Joe Darcy
parent 9f37ba44b8
commit 35387d5cb6
2 changed files with 108 additions and 2 deletions

View file

@ -2993,7 +2993,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
* @throws ArithmeticException if scale overflows.
*/
public BigDecimal movePointLeft(int n) {
if (n == 0) return this;
if (n == 0 && scale >= 0) return this;
// Cannot use movePointRight(-n) in case of n==Integer.MIN_VALUE
int newScale = checkScale((long)scale + n);
@ -3017,7 +3017,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
* @throws ArithmeticException if scale overflows.
*/
public BigDecimal movePointRight(int n) {
if (n == 0) return this;
if (n == 0 && scale >= 0) return this;
// Cannot use movePointLeft(-n) in case of n==Integer.MIN_VALUE
int newScale = checkScale((long)scale - n);