diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/runtime/RichDouble.scala | 12 | ||||
-rw-r--r-- | src/library/scala/runtime/RichFloat.scala | 12 | ||||
-rw-r--r-- | src/library/scala/runtime/RichLong.scala | 8 |
3 files changed, 32 insertions, 0 deletions
diff --git a/src/library/scala/runtime/RichDouble.scala b/src/library/scala/runtime/RichDouble.scala index 0a9cda40ec..f702b9e3da 100644 --- a/src/library/scala/runtime/RichDouble.scala +++ b/src/library/scala/runtime/RichDouble.scala @@ -35,4 +35,16 @@ final class RichDouble(val self: Double) extends FractionalProxy[Double] { def isInfinity: Boolean = java.lang.Double.isInfinite(self) def isPosInfinity: Boolean = isInfinity && self > 0.0 def isNegInfinity: Boolean = isInfinity && self < 0.0 + + override def isValidByte = self.toByte.toDouble == self + override def isValidShort = self.toShort.toDouble == self + override def isValidChar = self.toChar.toDouble == self + override def isValidInt = self.toInt.toDouble == self + // override def isValidLong = { val l = self.toLong; l.toDouble == self && l != Long.MaxValue } + // override def isValidFloat = self.toFloat.toDouble == self + // override def isValidDouble = !java.lang.Double.isNaN(self) + override def isWhole = { + val l = self.toLong + l.toDouble == self || l == Long.MaxValue && self < Double.PositiveInfinity || l == Long.MinValue && self > Double.NegativeInfinity + } } diff --git a/src/library/scala/runtime/RichFloat.scala b/src/library/scala/runtime/RichFloat.scala index c6478ec0c9..6b72a9dd55 100644 --- a/src/library/scala/runtime/RichFloat.scala +++ b/src/library/scala/runtime/RichFloat.scala @@ -36,4 +36,16 @@ final class RichFloat(val self: Float) extends FractionalProxy[Float] { def isInfinity: Boolean = java.lang.Float.isInfinite(self) def isPosInfinity: Boolean = isInfinity && self > 0.0f def isNegInfinity: Boolean = isInfinity && self < 0.0f + + override def isValidByte = self.toByte.toFloat == self + override def isValidShort = self.toShort.toFloat == self + override def isValidChar = self.toChar.toFloat == self + override def isValidInt = { val i = self.toInt; i.toFloat == self && i != Int.MaxValue } + // override def isValidLong = { val l = self.toLong; l.toFloat == self && l != Long.MaxValue } + // override def isValidFloat = !java.lang.Float.isNaN(self) + // override def isValidDouble = !java.lang.Float.isNaN(self) + override def isWhole = { + val l = self.toLong + l.toFloat == self || l == Long.MaxValue && self < Float.PositiveInfinity || l == Long.MinValue && self > Float.NegativeInfinity + } } diff --git a/src/library/scala/runtime/RichLong.scala b/src/library/scala/runtime/RichLong.scala index f93d9459d1..5784934ffd 100644 --- a/src/library/scala/runtime/RichLong.scala +++ b/src/library/scala/runtime/RichLong.scala @@ -12,4 +12,12 @@ final class RichLong(val self: Long) extends IntegralProxy[Long] { def toBinaryString: String = java.lang.Long.toBinaryString(self) def toHexString: String = java.lang.Long.toHexString(self) def toOctalString: String = java.lang.Long.toOctalString(self) + + override def isValidByte = self.toByte.toLong == self + override def isValidShort = self.toShort.toLong == self + override def isValidChar = self.toChar.toLong == self + override def isValidInt = self.toInt.toLong == self + // override def isValidLong = true + // override def isValidFloat = self.toFloat.toLong == self && self != Long.MaxValue + // override def isValidDouble = self.toDouble.toLong == self && self != Long.MaxValue } |