Skip to content

Commit 82310cd

Browse files
committed
JAVAMONEY-93 throw arithmetic exception for Double.NaN
1 parent dc65cb5 commit 82310cd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/org/javamoney/moneta/spi/ConvertBigDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BigDecimal getDecimal(Number num) {
4242
@Override
4343
BigDecimal getDecimal(Number num) {
4444
double d = num.doubleValue();
45-
if (d == Double.NaN || d == Double.POSITIVE_INFINITY || d == Double.NEGATIVE_INFINITY) {
45+
if (Double.isNaN(d)|| Double.isInfinite(d)) {
4646
throw new ArithmeticException("NaN, POSITIVE_INFINITY and NEGATIVE_INFINITY cannot be used as " +
4747
"parameters for monetary operations.");
4848
}

src/test/java/org/javamoney/moneta/FastMoneyTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,4 +1137,18 @@ public void testFromInversed(){
11371137
assertEquals(m, m2);
11381138
}
11391139

1140+
@Test(expectedExceptions = ArithmeticException.class)
1141+
public void testCreatingFromDoubleNan(){
1142+
FastMoney.of(Double.NaN, "XXX");
1143+
}
1144+
1145+
@Test(expectedExceptions = ArithmeticException.class)
1146+
public void testCreatingFromDoublePositiveInfinity(){
1147+
FastMoney.of(Double.POSITIVE_INFINITY, "XXX");
1148+
}
1149+
1150+
@Test(expectedExceptions = ArithmeticException.class)
1151+
public void testCreatingFromDoubleNegativeInfinity(){
1152+
FastMoney.of(Double.NEGATIVE_INFINITY, "XXX");
1153+
}
11401154
}

0 commit comments

Comments
 (0)