Skip to content

Commit cc64343

Browse files
committed
Used Math class in other locations within FastMoney.
1 parent 4493e16 commit cc64343

File tree

4 files changed

+239
-247
lines changed

4 files changed

+239
-247
lines changed

src/main/java/org/javamoney/moneta/FastMoney.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ public FastMoney multiply(Number multiplicand) {
364364
if (isOne(multiplicand)) {
365365
return this;
366366
}
367-
return new FastMoney(Math.round(this.number * multiplicand.doubleValue()), getCurrency());
367+
return new FastMoney(Math.multiplyExact(this.number, getInternalNumber(multiplicand, false)),
368+
getCurrency());
368369
}
369370

370371
/*
@@ -373,7 +374,7 @@ public FastMoney multiply(Number multiplicand) {
373374
*/
374375
@Override
375376
public FastMoney negate() {
376-
return new FastMoney(this.number * -1, getCurrency());
377+
return new FastMoney(Math.multiplyExact(this.number, -1), getCurrency());
377378
}
378379

379380
/*
@@ -385,7 +386,7 @@ public FastMoney plus() {
385386
if (this.number >= 0) {
386387
return this;
387388
}
388-
return new FastMoney(this.number * -1, getCurrency());
389+
return new FastMoney(Math.multiplyExact(this.number, -1), getCurrency());
389390
}
390391

391392
/*
@@ -398,8 +399,8 @@ public FastMoney subtract(MonetaryAmount subtrahend) {
398399
if (subtrahend.isZero()) {
399400
return this;
400401
}
401-
long subtrahendAsLong = getInternalNumber(subtrahend.getNumber(), false);
402-
return new FastMoney(Math.addExact(this.number, -1L * subtrahendAsLong), getCurrency());
402+
return new FastMoney(Math.subtractExact(this.number, getInternalNumber(subtrahend.getNumber(), false)),
403+
getCurrency());
403404
}
404405

405406
/*
@@ -412,7 +413,7 @@ public FastMoney remainder(Number divisor) {
412413
if (isOne(divisor)) {
413414
return new FastMoney(0, getCurrency());
414415
}
415-
return new FastMoney(this.number % getInternalNumber(divisor, true), getCurrency());
416+
return new FastMoney(this.number % getInternalNumber(divisor, false), getCurrency());
416417
}
417418

418419
private boolean isOne(Number number) {

0 commit comments

Comments
 (0)