summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2016-02-10 21:40:08 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2016-02-10 21:40:08 +0100
commitaa18beccff3b2f2680575c02f30467be0a557f13 (patch)
tree014ffb8174f3165c6450f49283e47ba219e342da
parent78c378c97c51600cac1cf42edd050aceb2366026 (diff)
parente5517e67eea79fbbd886110ff6dc993842852cf8 (diff)
downloadscala-aa18beccff3b2f2680575c02f30467be0a557f13.tar.gz
scala-aa18beccff3b2f2680575c02f30467be0a557f13.tar.bz2
scala-aa18beccff3b2f2680575c02f30467be0a557f13.zip
Merge pull request #4924 from ShaneDelmore/SI-9452
SI-9452: Extend BigDecimal with Ordered for java interop
-rw-r--r--src/library/scala/math/BigDecimal.scala18
-rw-r--r--src/library/scala/math/BigInt.scala23
-rw-r--r--test/files/run/numbereq.scala3
-rw-r--r--test/junit/scala/math/BigDecimalTest.scala5
-rw-r--r--test/junit/scala/math/BigIntTest.scala16
5 files changed, 30 insertions, 35 deletions
diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala
index 371fd59a93..e769dfb8cb 100644
--- a/src/library/scala/math/BigDecimal.scala
+++ b/src/library/scala/math/BigDecimal.scala
@@ -397,7 +397,7 @@ object BigDecimal {
* @version 1.1
*/
final class BigDecimal(val bigDecimal: BigDec, val mc: MathContext)
-extends ScalaNumber with ScalaNumericConversions with Serializable {
+extends ScalaNumber with ScalaNumericConversions with Serializable with Ordered[BigDecimal] {
def this(bigDecimal: BigDec) = this(bigDecimal, BigDecimal.defaultMathContext)
import BigDecimal.RoundingMode._
import BigDecimal.{decimal, binary, exact}
@@ -537,22 +537,6 @@ extends ScalaNumber with ScalaNumericConversions with Serializable {
*/
def compare (that: BigDecimal): Int = this.bigDecimal compareTo that.bigDecimal
- /** Less-than-or-equals comparison of BigDecimals
- */
- def <= (that: BigDecimal): Boolean = compare(that) <= 0
-
- /** Greater-than-or-equals comparison of BigDecimals
- */
- def >= (that: BigDecimal): Boolean = compare(that) >= 0
-
- /** Less-than of BigDecimals
- */
- def < (that: BigDecimal): Boolean = compare(that) < 0
-
- /** Greater-than comparison of BigDecimals
- */
- def > (that: BigDecimal): Boolean = compare(that) > 0
-
/** Addition of BigDecimals
*/
def + (that: BigDecimal): BigDecimal = new BigDecimal(this.bigDecimal add that.bigDecimal, mc)
diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala
index abc7371d9f..3ae3b9bf6c 100644
--- a/src/library/scala/math/BigInt.scala
+++ b/src/library/scala/math/BigInt.scala
@@ -109,7 +109,12 @@ object BigInt {
* @author Martin Odersky
* @version 1.0, 15/07/2003
*/
-final class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericConversions with Serializable {
+final class BigInt(val bigInteger: BigInteger)
+ extends ScalaNumber
+ with ScalaNumericConversions
+ with Serializable
+ with Ordered[BigInt]
+{
/** Returns the hash code for this BigInt. */
override def hashCode(): Int =
if (isValidLong) unifiedPrimitiveHashcode()
@@ -176,22 +181,6 @@ final class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNum
*/
def compare (that: BigInt): Int = this.bigInteger.compareTo(that.bigInteger)
- /** Less-than-or-equals comparison of BigInts
- */
- def <= (that: BigInt): Boolean = compare(that) <= 0
-
- /** Greater-than-or-equals comparison of BigInts
- */
- def >= (that: BigInt): Boolean = compare(that) >= 0
-
- /** Less-than of BigInts
- */
- def < (that: BigInt): Boolean = compare(that) < 0
-
- /** Greater-than comparison of BigInts
- */
- def > (that: BigInt): Boolean = compare(that) > 0
-
/** Addition of BigInts
*/
def + (that: BigInt): BigInt = new BigInt(this.bigInteger.add(that.bigInteger))
diff --git a/test/files/run/numbereq.scala b/test/files/run/numbereq.scala
index 7ce4b23cf8..1f12d0643e 100644
--- a/test/files/run/numbereq.scala
+++ b/test/files/run/numbereq.scala
@@ -1,6 +1,7 @@
object Test {
def mkNumbers(x: Int): List[AnyRef] = {
- val base = List(
+ //Use explicit AnyRef to workaround known limitation of type inference with F-Bounds
+ val base = List[AnyRef](
BigDecimal(x),
BigInt(x),
new java.lang.Double(x.toDouble),
diff --git a/test/junit/scala/math/BigDecimalTest.scala b/test/junit/scala/math/BigDecimalTest.scala
index a9e2481f37..5de02cbe0c 100644
--- a/test/junit/scala/math/BigDecimalTest.scala
+++ b/test/junit/scala/math/BigDecimalTest.scala
@@ -260,4 +260,9 @@ class BigDecimalTest {
testPrecision()
testRounded()
}
+
+ @Test
+ def testIsComparable() {
+ assert(BigDecimal(0.1).isInstanceOf[java.lang.Comparable[_]])
+ }
}
diff --git a/test/junit/scala/math/BigIntTest.scala b/test/junit/scala/math/BigIntTest.scala
new file mode 100644
index 0000000000..5a5694a775
--- /dev/null
+++ b/test/junit/scala/math/BigIntTest.scala
@@ -0,0 +1,16 @@
+package scala.math
+
+import java.math.{BigInteger => BI, MathContext => MC}
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class BigIntTest {
+
+ @Test
+ def testIsComparable() {
+ assert(BigInt(1).isInstanceOf[java.lang.Comparable[_]])
+ }
+}