From 6900ffe884573fef394e2886e35361e2e1e951d5 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 15 Nov 2010 04:59:04 +0000 Subject: Cleaned up some hangover from equality struggle... Cleaned up some hangover from equality struggles of yore. Deprecated now pointless vals. Close #3998, no review. --- src/library/scala/math/BigDecimal.scala | 7 +++++-- src/library/scala/math/BigInt.scala | 8 ++++++-- src/library/scala/math/ScalaNumericConversions.scala | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala index e1d44862e4..3fcc00222b 100644 --- a/src/library/scala/math/BigDecimal.scala +++ b/src/library/scala/math/BigDecimal.scala @@ -23,10 +23,12 @@ import annotation.migration object BigDecimal { private val minCached = -512 private val maxCached = 512 - val defaultMathContext = MathContext.UNLIMITED + @deprecated("Use Long.MinValue") val MinLong = new BigDecimal(BigDec valueOf Long.MinValue, defaultMathContext) + + @deprecated("Use Long.MaxValue") val MaxLong = new BigDecimal(BigDec valueOf Long.MaxValue, defaultMathContext) /** Cache ony for defaultMathContext using BigDecimals in a small range. */ @@ -181,8 +183,9 @@ extends ScalaNumber with ScalaNumericConversions 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) + case _ => fitsInLong && unifiedPrimitiveEquals(that) } + private def fitsInLong = isWhole && this <= Long.MaxValue && this >= Long.MinValue protected[math] def isWhole = (this remainder 1) == BigDecimal(0) def underlying = bigDecimal diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index a21057c400..bd20891019 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -23,7 +23,10 @@ object BigInt { private val maxCached = 1024 private val cache = new Array[BigInt](maxCached - minCached + 1) + @deprecated("Use Long.MinValue") val MinLong = BigInt(Long.MinValue) + + @deprecated("Use Long.MaxValue") val MaxLong = BigInt(Long.MaxValue) /** Constructs a BigInt whose value is equal to that of the @@ -115,7 +118,7 @@ class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericCo { /** Returns the hash code for this BigInt. */ override def hashCode(): Int = - if (this >= BigInt.MinLong && this <= BigInt.MaxLong) unifiedPrimitiveHashcode + if (fitsInLong) unifiedPrimitiveHashcode else bigInteger.## /** Compares this BigInt with the specified value for equality. @@ -123,8 +126,9 @@ class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericCo override def equals(that: Any): Boolean = that match { case that: BigInt => this equals that case that: BigDecimal => that.toBigIntExact exists (this equals _) - case x => (this <= BigInt.MaxLong && this >= BigInt.MinLong) && unifiedPrimitiveEquals(x) + case x => fitsInLong && unifiedPrimitiveEquals(x) } + private def fitsInLong = this >= Long.MinValue && this <= Long.MaxValue protected[math] def isWhole = true def underlying = bigInteger diff --git a/src/library/scala/math/ScalaNumericConversions.scala b/src/library/scala/math/ScalaNumericConversions.scala index 34698ea39f..e83ce0446f 100644 --- a/src/library/scala/math/ScalaNumericConversions.scala +++ b/src/library/scala/math/ScalaNumericConversions.scala @@ -22,10 +22,10 @@ trait ScalaNumericConversions extends ScalaNumber { def toFloat = floatValue def toDouble = doubleValue - def isValidByte = isWhole && (toByte == toInt) - def isValidShort = isWhole && (toShort == toInt) - def isValidInt = isWhole && (toInt == toLong) - def isValidChar = isWhole && (toInt >= Char.MinValue && toInt <= Char.MaxValue) + def isValidByte = isWhole && (toInt == toByte) + def isValidShort = isWhole && (toInt == toShort) + def isValidInt = isWhole && (toLong == toInt) + def isValidChar = isWhole && (toInt >= Char.MinValue && toInt <= Char.MaxValue) protected def unifiedPrimitiveHashcode() = { val lv = toLong -- cgit v1.2.3