diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-07-05 17:26:38 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-07-05 17:26:38 -0700 |
commit | 34d36108bf152469a934408da2b55c1df9c70a7a (patch) | |
tree | 3d1097375bba276ef659cbe207f607b63e5366ff | |
parent | 171a1d8bc859947d80d4728c251abe330dbe9802 (diff) | |
parent | efc6854f7df46a479cbdd2c40e777edd6ee36d33 (diff) | |
download | scala-34d36108bf152469a934408da2b55c1df9c70a7a.tar.gz scala-34d36108bf152469a934408da2b55c1df9c70a7a.tar.bz2 scala-34d36108bf152469a934408da2b55c1df9c70a7a.zip |
Merge pull request #831 from dgruntz/issue/6033
SI-6033 Closed. Provides implicit conversion from BigInteger to BigInt
-rw-r--r-- | src/library/scala/math/BigInt.scala | 11 | ||||
-rw-r--r-- | test/files/pos/t6033.scala | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index af2ab04576..4471e417d9 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -87,6 +87,11 @@ object BigInt { def apply(x: String, radix: Int): BigInt = new BigInt(new BigInteger(x, radix)) + /** Translates a `java.math.BigInteger` into a BigInt. + */ + def apply(x: BigInteger): BigInt = + new BigInt(x) + /** Returns a positive BigInt that is probably prime, with the specified bitLength. */ def probablePrime(bitLength: Int, rnd: scala.util.Random): BigInt = @@ -96,9 +101,13 @@ object BigInt { */ implicit def int2bigInt(i: Int): BigInt = apply(i) - /** Implicit conversion from long to BigInt + /** Implicit conversion from `Long` to `BigInt`. */ implicit def long2bigInt(l: Long): BigInt = apply(l) + + /** Implicit conversion from `java.math.BigInteger` to `scala.BigInt`. + */ + implicit def javaBigInteger2bigInt(x: BigInteger): BigInt = apply(x) } /** diff --git a/test/files/pos/t6033.scala b/test/files/pos/t6033.scala new file mode 100644 index 0000000000..60142af6be --- /dev/null +++ b/test/files/pos/t6033.scala @@ -0,0 +1,5 @@ +object Test extends App { + val b = new java.math.BigInteger("123") + val big1 = BigInt(b) + val big2: BigInt = b +} |