summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/math/BigDecimal.scala7
-rw-r--r--test/files/run/equality.scala2
2 files changed, 6 insertions, 3 deletions
diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala
index b8dbe03db0..7312c0d2c0 100644
--- a/src/library/scala/math/BigDecimal.scala
+++ b/src/library/scala/math/BigDecimal.scala
@@ -178,9 +178,10 @@ extends ScalaNumber with ScalaNumericConversions
/** Compares this BigDecimal with the specified value for equality.
*/
override def equals (that: Any): Boolean = that match {
- case that: BigDecimal => this equals that
- case that: BigInt => this.toBigIntExact exists (that equals _)
- case x => (this <= BigDecimal.MaxLong && this >= BigDecimal.MinLong) && unifiedPrimitiveEquals(x)
+ case that: BigDecimal => this equals that
+ case that: BigInt => this.toBigIntExact exists (that equals _)
+ case _: Float | _: Double => unifiedPrimitiveEquals(that)
+ case x => isWhole && this <= BigDecimal.MaxLong && this >= BigDecimal.MinLong && unifiedPrimitiveEquals(x)
}
protected[math] def isWhole = (this remainder 1) == BigDecimal(0)
diff --git a/test/files/run/equality.scala b/test/files/run/equality.scala
index 6498b232e1..ff59898821 100644
--- a/test/files/run/equality.scala
+++ b/test/files/run/equality.scala
@@ -34,5 +34,7 @@ object Test
// negatives
val bigLong = new java.util.concurrent.atomic.AtomicLong(Long.MaxValue)
assert(-1 != bigLong && bigLong != -1) // bigLong.intValue() == -1
+ assert(BigDecimal(1.1) != 1L)
+ assert(1L != BigDecimal(1.1))
}
}