diff options
author | Paul Phillips <paulp@improving.org> | 2009-06-11 17:52:07 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-06-11 17:52:07 +0000 |
commit | b72cc0bda59df3b73afb128b24d86b0cbb1fbf43 (patch) | |
tree | 1737dde76e04c7eaa6c299eec2f1f19231b3c1b3 /src/library/scala/BigInt.scala | |
parent | e638fb866212108c09d4d09b9a26e24800b2b5f7 (diff) | |
download | scala-b72cc0bda59df3b73afb128b24d86b0cbb1fbf43.tar.gz scala-b72cc0bda59df3b73afb128b24d86b0cbb1fbf43.tar.bz2 scala-b72cc0bda59df3b73afb128b24d86b0cbb1fbf43.zip |
Lots and lots of BigInt and BigDecimal code att...
Lots and lots of BigInt and BigDecimal code attempting to make it all
consistent and equality correct and consistent (to the extent that's
even possible.) I'll be glad when this is over.
Diffstat (limited to 'src/library/scala/BigInt.scala')
-rw-r--r-- | src/library/scala/BigInt.scala | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/library/scala/BigInt.scala b/src/library/scala/BigInt.scala index ac8b4c40a7..abed8c748d 100644 --- a/src/library/scala/BigInt.scala +++ b/src/library/scala/BigInt.scala @@ -108,7 +108,9 @@ object BigInt { * @version 1.0, 15/07/2003 */ @serializable -class BigInt(val bigInteger: BigInteger) extends java.lang.Number { +class BigInt(val bigInteger: BigInteger) extends java.lang.Number +{ + import BigDecimal.equalsOwnLongValue /** Returns the hash code for this BigInt. */ override def hashCode(): Int = this.bigInteger.hashCode() @@ -116,12 +118,15 @@ class BigInt(val bigInteger: BigInteger) extends java.lang.Number { /** Compares this BigInt with the specified value for equality. */ override def equals (that: Any): Boolean = that match { - case that: BigInt => this equals that - case that: java.lang.Double => this.bigInteger.doubleValue == that.doubleValue - case that: java.lang.Float => this.bigInteger.floatValue == that.floatValue - case that: java.lang.Number => this equals BigInt(that.longValue) - case that: java.lang.Character => this equals BigInt(that.charValue.asInstanceOf[Int]) - case _ => false + case that: BigInt => this equals that + case that: BigInteger => this equals new BigInt(that) + case that: BigDecimal => this equals that + case that: java.math.BigDecimal => this equals BigDecimal(that) + case that: java.lang.Double => this equals BigDecimal(that.doubleValue) + case that: java.lang.Float => this equals BigDecimal(that.floatValue) + case that: java.lang.Number => equalsOwnLongValue(that) && (this equals BigInt(that.longValue)) + case that: java.lang.Character => this equals BigInt(that.charValue.asInstanceOf[Int]) + case _ => false } /** Compares this BigInt with the specified BigInt for equality. @@ -129,6 +134,13 @@ class BigInt(val bigInteger: BigInteger) extends java.lang.Number { def equals (that: BigInt): Boolean = this.bigInteger.compareTo(that.bigInteger) == 0 + /** Compares this BigInt with the specified BigDecimal for equality. + */ + def equals(that: BigDecimal): Boolean = that.toBigIntExact match { + case None => false + case Some(x) => this equals x + } + /** Compares this BigInt with the specified BigInt */ def compare (that: BigInt): Int = this.bigInteger.compareTo(that.bigInteger) |