scala.runtime.RichInt

final class RichInt extends AnyVal with ScalaNumberProxy[Int] with RangedProxy[Int]

Type Members

type ResultWithoutStep = collection.immutable.Range

  • Definition Classes
    • RichInt → RangedProxy

Deprecated Value Members From scala.Any

final def ##(): Int

Equivalent to x.hashCode except for boxed numeric types and null . For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException .

  • returns
    • a hash value consistent with ==
  • Definition Classes
    • Any

(defined at scala.Any###)

Value Members From scala.math.Ordered

def <(that: Int): Boolean

Returns true if this is less than that

  • Definition Classes
    • Ordered

(defined at scala.math.Ordered)

def <=(that: Int): Boolean

Returns true if this is less than or equal to that .

  • Definition Classes
    • Ordered

(defined at scala.math.Ordered)

def >(that: Int): Boolean

Returns true if this is greater than that .

  • Definition Classes
    • Ordered

(defined at scala.math.Ordered)

def >=(that: Int): Boolean

Returns true if this is greater than or equal to that .

  • Definition Classes
    • Ordered

(defined at scala.math.Ordered)

def compareTo(that: Int): Int

Result of comparing this with operand that .

  • Definition Classes
    • Ordered → Comparable

(defined at scala.math.Ordered)

Value Members From scala.math.ScalaNumericAnyConversions

def unifiedPrimitiveEquals(x: Any): Boolean

Should only be called after all known non-primitive types have been excluded. This method won’t dispatch anywhere else after checking against the primitives to avoid infinite recursion between equals and this on unknown “Number” variants.

Additionally, this should only be called if the numeric type is happy to be converted to Long, Float, and Double. If for instance a BigInt much larger than the Long range is sent here, it will claim equality with whatever Long is left in its lower 64 bits. Or a BigDecimal with more precision than Double can hold: same thing. There’s no way given the interface available here to prevent this error.

  • Attributes
    • protected
  • Definition Classes
    • ScalaNumericAnyConversions

(defined at scala.math.ScalaNumericAnyConversions)

Value Members From scala.runtime.OrderedProxy

def compare(y: Int): Int

Result of comparing this with operand that .

Implement this method to determine how instances of A will be sorted.

Returns x where:

  • x < 0 when this < that
  • x == 0 when this == that
  • x > 0 when this > that

  • Definition Classes
    • OrderedProxy → Ordered

(defined at scala.runtime.OrderedProxy)

Instance Constructors From scala.runtime.RichInt

new RichInt(self: Int)

(defined at scala.runtime.RichInt)

Value Members From scala.runtime.RichInt

def max(that: Int): Int

Returns this if this > that or that otherwise.

  • Definition Classes
    • RichInt → ScalaNumberProxy

(defined at scala.runtime.RichInt)

def min(that: Int): Int

Returns this if this < that or that otherwise.

  • Definition Classes
    • RichInt → ScalaNumberProxy

(defined at scala.runtime.RichInt)

def num: IntIsIntegral.type

  • Attributes
    • protected
  • Definition Classes
    • RichInt → ScalaNumberProxy

(defined at scala.runtime.RichInt)

def to(end: Int): Inclusive

  • end
    • The final bound of the range to make.
  • returns
    • A scala.collection.immutable.Range from this up to and including end .
  • Definition Classes
    • RichInt → RangedProxy

(defined at scala.runtime.RichInt)

def to(end: Int, step: Int): Inclusive

  • end
    • The final bound of the range to make.
  • step
    • The number to increase by for each step of the range.
  • returns
    • A scala.collection.immutable.Range from this up to and including end .
  • Definition Classes
    • RichInt → RangedProxy

(defined at scala.runtime.RichInt)

def until(end: Int): collection.immutable.Range

  • end
    • The final bound of the range to make.
  • returns
    • A scala.collection.immutable.Range from this up to but not including end .
  • Definition Classes
    • RichInt → RangedProxy

(defined at scala.runtime.RichInt)

def until(end: Int, step: Int): collection.immutable.Range

  • end
    • The final bound of the range to make.
  • step
    • The number to increase by for each step of the range.
  • returns
    • A scala.collection.immutable.Range from this up to but not including end .
  • Definition Classes
    • RichInt → RangedProxy (defined at scala.runtime.RichInt)

Full Source:

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala
package runtime

import scala.collection.immutable.Range

// Note that this does not implement IntegralProxy[Int] so that it can return
// the Int-specific Range class from until/to.
final class RichInt(val self: Int) extends AnyVal with ScalaNumberProxy[Int] with RangedProxy[Int] {
  protected def num = scala.math.Numeric.IntIsIntegral
  protected def ord = scala.math.Ordering.Int

  override def doubleValue() = self.toDouble
  override def floatValue()  = self.toFloat
  override def longValue()   = self.toLong
  override def intValue()    = self
  override def byteValue()   = self.toByte
  override def shortValue()  = self.toShort

  /** Returns `'''true'''` if this number has no decimal component.
    * Always `'''true'''` for `RichInt`.
    */
  def isWhole() = true

  override def isValidInt   = true
  def isValidLong  = true

  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)
  
  /** 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")
  def round: Int = self

  def toBinaryString: String = java.lang.Integer.toBinaryString(self)
  def toHexString: String    = java.lang.Integer.toHexString(self)
  def toOctalString: String  = java.lang.Integer.toOctalString(self)

  type ResultWithoutStep = Range

  /**
    * @param end The final bound of the range to make.
    * @return A [[scala.collection.immutable.Range]] from `this` up to but
    *         not including `end`.
    */
  def until(end: Int): Range = Range(self, end)

  /**
    * @param end The final bound of the range to make.
    * @param step The number to increase by for each step of the range.
    * @return A [[scala.collection.immutable.Range]] from `this` up to but
    *         not including `end`.
    */
  def until(end: Int, step: Int): Range = Range(self, end, step)

  /** like `until`, but includes the last index */
  /**
    * @param end The final bound of the range to make.
    * @return A [[scala.collection.immutable.Range]] from `'''this'''` up to
    *         and including `end`.
    */
  def to(end: Int): Range.Inclusive = Range.inclusive(self, end)

  /**
    * @param end The final bound of the range to make.
    * @param step The number to increase by for each step of the range.
    * @return A [[scala.collection.immutable.Range]] from `'''this'''` up to
    *         and including `end`.
    */
  def to(end: Int, step: Int): Range.Inclusive = Range.inclusive(self, end, step)
}