Skip to content

Commit

Permalink
Drop commented out sign/signum in Rich*, leave a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jan 29, 2021
1 parent 0e74a14 commit 6fb7b5c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/library/scala/runtime/RichByte.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ final class RichByte(val self: Byte) extends AnyVal with ScalaWholeNumberProxy[B

override def isValidByte = true

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine signum and sign too but forwards binary compatibility doesn't allow us to.
override def abs: Byte = math.abs(self).toByte
override def max(that: Byte): Byte = math.max(self, that).toByte
override def min(that: Byte): Byte = math.min(self, that).toByte
//override def signum: Int = math.signum(self.toInt)
//override def sign: Byte = math.signum(self.toInt).toByte
}
6 changes: 3 additions & 3 deletions src/library/scala/runtime/RichChar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ final class RichChar(val self: Char) extends AnyVal with IntegralProxy[Char] {

override def isValidChar = true

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine signum and sign too but forwards binary compatibility doesn't allow us to.
override def abs: Char = self
override def max(that: Char): Char = math.max(self.toInt, that.toInt).toChar
override def min(that: Char): Char = math.min(self.toInt, that.toInt).toChar
//override def signum: Int = math.signum(self.toInt)
//override def sign: Char = math.signum(self.toInt).toChar

def asDigit: Int = Character.digit(self, Character.MAX_RADIX)

Expand Down
5 changes: 3 additions & 2 deletions src/library/scala/runtime/RichDouble.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ final class RichDouble(val self: Double) extends AnyVal with FractionalProxy[Dou
def isPosInfinity: Boolean = Double.PositiveInfinity == self
def isNegInfinity: Boolean = Double.NegativeInfinity == self

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine sign too but forwards binary compatibility doesn't allow us to.
override def abs: Double = math.abs(self)
override def max(that: Double): Double = math.max(self, that)
override def min(that: Double): Double = math.min(self, that)
@deprecated("signum does not handle -0.0 or Double.NaN; use `sign` method instead", since = "2.13.0")
override def signum: Int = math.signum(self).toInt
//override def sign: Double = math.signum(self)

def round: Long = math.round(self)
def ceil: Double = math.ceil(self)
Expand Down
5 changes: 3 additions & 2 deletions src/library/scala/runtime/RichFloat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ final class RichFloat(val self: Float) extends AnyVal with FractionalProxy[Float
def isPosInfinity: Boolean = Float.PositiveInfinity == self
def isNegInfinity: Boolean = Float.NegativeInfinity == self

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine sign too but forwards binary compatibility doesn't allow us to.
override def abs: Float = math.abs(self)
override def max(that: Float): Float = math.max(self, that)
override def min(that: Float): Float = math.min(self, that)
@deprecated("signum does not handle -0.0f or Float.NaN; use `sign` method instead", since = "2.13.0")
override def signum: Int = math.signum(self).toInt
//override def sign: Float = math.signum(self)

def round: Int = math.round(self)
def ceil: Float = math.ceil(self.toDouble).toFloat
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/runtime/RichInt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ final class RichInt(val self: Int) extends AnyVal with ScalaNumberProxy[Int] wit
override def isValidInt = true
def isValidLong = true

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine signum and sign too but forwards binary compatibility doesn't allow us to.
override def abs: Int = math.abs(self)
override def max(that: Int): Int = math.max(self, that)
override def min(that: Int): Int = math.min(self, that)
//override def signum: Int = math.signum(self)
//override def sign: Int = math.signum(self)

/** There is no reason to round an `Int`, but this method is provided to avoid accidental loss of precision from a detour through `Float`. */
@deprecated("this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value?", "2.11.0")
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/runtime/RichLong.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ final class RichLong(val self: Long) extends AnyVal with IntegralProxy[Long] {
// override def isValidFloat = self.toFloat.toLong == self && self != Long.MaxValue
// override def isValidDouble = self.toDouble.toLong == self && self != Long.MaxValue

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine signum and sign too but forwards binary compatibility doesn't allow us to.
override def abs: Long = math.abs(self)
override def max(that: Long): Long = math.max(self, that)
override def min(that: Long): Long = math.min(self, that)
//override def signum: Int = math.signum(self).toInt
//override def sign: Long = math.signum(self)

/** There is no reason to round a `Long`, but this method is provided to avoid accidental conversion to `Int` through `Float`. */
@deprecated("this is an integer type; there is no reason to round it. Perhaps you meant to call this on a floating-point value?", "2.11.0")
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/runtime/RichShort.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ final class RichShort(val self: Short) extends AnyVal with ScalaWholeNumberProxy

override def isValidShort = true

// These are all redefined to avoid VC boxing (they also avoid the indirection through `num`)
// These method are all overridden and redefined to call out to scala.math to avoid 3 allocations:
// the primitive boxing, the value class boxing and instantiation of the Numeric num.
// We'd like to redefine signum and sign too but forwards binary compatibility doesn't allow us to.
override def abs: Short = math.abs(self.toInt).toShort
override def max(that: Short): Short = math.max(self.toInt, that.toInt).toShort
override def min(that: Short): Short = math.min(self.toInt, that.toInt).toShort
//override def signum: Int = math.signum(self.toInt)
//override def sign: Short = math.signum(self.toInt).toShort
}

0 comments on commit 6fb7b5c

Please sign in to comment.