scalation.math

Rational

case class Rational(num: Long, den: Long) extends Fractional[Rational] with Ordered[Rational] with Product with Serializable

This class is used to represent rational numbers as 2 long integers. (a, b), e.g., (2, 3) meaning 2 / 3. Arbitrary rational number can be created without loss of precision via the two constructors or the fromBigDecimal method.

num

the numerator

den

the denominator

Linear Supertypes
Product, Equals, Ordered[Rational], Comparable[Rational], Fractional[Rational], Numeric[Rational], Ordering[Rational], Serializable, Serializable, PartialOrdering[Rational], Equiv[Rational], Comparator[Rational], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Rational
  2. Product
  3. Equals
  4. Ordered
  5. Comparable
  6. Fractional
  7. Numeric
  8. Ordering
  9. Serializable
  10. Serializable
  11. PartialOrdering
  12. Equiv
  13. Comparator
  14. AnyRef
  15. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Rational(s: String)

    Construct a rational number from a String of the form "12.

    Construct a rational number from a String of the form "12.3E+7".

    s

    the given String representation of a number

    See also

    http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html #BigDecimal%28java.lang.String%29

  2. new Rational(y: (Long, Long))

    Construct a rational number from a tuple of two Longs.

    Construct a rational number from a tuple of two Longs.

    y

    the tuple of two Longs

  3. new Rational(num: Long, den: Long = 1L)

    num

    the numerator

    den

    the denominator

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def *(l: Long): Rational

    Multiply a rational number times a long.

    Multiply a rational number times a long.

    l

    multiply this times long l

  5. def *(q: Rational): Rational

    Multiply two rational numbers (this * q).

    Multiply two rational numbers (this * q).

    q

    multiply this times rational q

  6. def +(l: Long): Rational

    Add a rational number plus a long.

    Add a rational number plus a long.

    l

    add long l to this

  7. def +(q: Rational): Rational

    Add two rational numbers (this + q)

    Add two rational numbers (this + q)

    q

    add rational q to this

  8. def -(l: Long): Rational

    Subtract: a rational number minus a long.

    Subtract: a rational number minus a long.

    l

    subtract long l from this

  9. def -(q: Rational): Rational

    Subtract two rational numbers (this - q).

    Subtract two rational numbers (this - q).

    q

    subtract rational q from this

  10. def /(l: Long): Rational

    Divide a rational number div a long.

    Divide a rational number div a long.

    l

    divide this by long l

  11. def /(q: Rational): Rational

    Divide two rational numbers (this / q)

    Divide two rational numbers (this / q)

    q

    divide this by rational q

  12. def <(that: Rational): Boolean

    Definition Classes
    Ordered
  13. def <=(that: Rational): Boolean

    Definition Classes
    Ordered
  14. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  16. def >(that: Rational): Boolean

    Definition Classes
    Ordered
  17. def >=(that: Rational): Boolean

    Definition Classes
    Ordered
  18. def abs: Rational

    Return the absolute value of this rational number.

  19. def abs(x: Rational): Rational

    Definition Classes
    Numeric
  20. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  21. def canEqual(arg0: Any): Boolean

    Definition Classes
    Rational → Equals
  22. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. def compare(q: Rational): Int

    Compare this rational number with that rational number q.

    Compare this rational number with that rational number q.

    q

    that rational number

    Definition Classes
    Rational → Ordered
  24. def compare(q: Rational, p: Rational): Int

    Compare two rational numbers (negative for <, zero for ==, positive for >).

    Compare two rational numbers (negative for <, zero for ==, positive for >).

    q

    the first rational number to compare

    p

    the second rational number to compare

    Definition Classes
    Rational → Ordering → Comparator
  25. def compareTo(that: Rational): Int

    Definition Classes
    Ordered → Comparable
  26. val den: Long

    the denominator

  27. def div(q: Rational, l: Long): Rational

  28. def div(q: Rational, p: Rational): Rational

    Definition Classes
    Rational → Fractional
  29. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  30. def equals(c: Any): Boolean

    Override equals to determine whether this rational number equals rational c.

    Override equals to determine whether this rational number equals rational c.

    c

    the rational number to compare with this

    Definition Classes
    Rational → Equals → Comparator → AnyRef → Any
  31. def equiv(x: Rational, y: Rational): Boolean

    Definition Classes
    Ordering → PartialOrdering → Equiv
  32. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  33. def fromBigDecimal(y: BigDecimal): Rational

    Create a rational number from a BigDecimal number.

    Create a rational number from a BigDecimal number.

    y

    the BigDecimal used to create the rational number

  34. def fromDouble(y: Double): Rational

    Create a rational number from a Double.

    Create a rational number from a Double.

    y

    the Double used to create the rational number

  35. def fromFloat(y: Float): Rational

    Create a rational number from a Float.

    Create a rational number from a Float.

    y

    the Float used to create the rational number

  36. def fromInt(n: Int): Rational

    Create a rational number from an Int.

    Create a rational number from an Int.

    n

    the Int used to create the rational number

    Definition Classes
    Rational → Numeric
  37. def fromLong(n: Long): Rational

    Create a rational number from a Long.

    Create a rational number from a Long.

    n

    the Long used to create the rational number

  38. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  39. def gt(x: Rational, y: Rational): Boolean

    Definition Classes
    Ordering → PartialOrdering
  40. def gteq(x: Rational, y: Rational): Boolean

    Definition Classes
    Ordering → PartialOrdering
  41. def hashCode(): Int

    Must also override hashCode to be be compatible with equals.

    Must also override hashCode to be be compatible with equals.

    Definition Classes
    Rational → AnyRef → Any
  42. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  43. def isIntegral: Boolean

    Determine whether this rational number is integral.

  44. def lt(x: Rational, y: Rational): Boolean

    Definition Classes
    Ordering → PartialOrdering
  45. def lteq(x: Rational, y: Rational): Boolean

    Definition Classes
    Ordering → PartialOrdering
  46. def max(q: Rational): Rational

    Return the maximum of this and that rational numbers.

    Return the maximum of this and that rational numbers.

    q

    that rational number to compare with this

  47. def max(x: Rational, y: Rational): Rational

    Definition Classes
    Ordering
  48. def min(q: Rational): Rational

    Return the minimum of this and that rational numbers.

    Return the minimum of this and that rational numbers.

    q

    that rational number to compare with this

  49. def min(x: Rational, y: Rational): Rational

    Definition Classes
    Ordering
  50. def minus(q: Rational, l: Long): Rational

  51. def minus(q: Rational, p: Rational): Rational

    Definition Classes
    Rational → Numeric
  52. implicit def mkNumericOps(lhs: Rational): FractionalOps

    Definition Classes
    Fractional → Numeric
  53. implicit def mkOrderingOps(lhs: Rational): Ops

    Definition Classes
    Ordering
  54. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  55. def negate(q: Rational): Rational

    Definition Classes
    Rational → Numeric
  56. final def notify(): Unit

    Definition Classes
    AnyRef
  57. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  58. val num: Long

    the numerator

  59. def on[U](f: (U) ⇒ Rational): Ordering[U]

    Definition Classes
    Ordering
  60. def one: Rational

    Definition Classes
    Numeric
  61. def plus(q: Rational, l: Long): Rational

  62. def plus(q: Rational, p: Rational): Rational

    Definition Classes
    Rational → Numeric
  63. def pow(q: Rational, l: Long): Rational

  64. def pow(q: Rational, p: Rational): Rational

  65. def productArity: Int

    Definition Classes
    Rational → Product
  66. def productElement(arg0: Int): Any

    Definition Classes
    Rational → Product
  67. def productIterator: Iterator[Any]

    Definition Classes
    Product
  68. def productPrefix: String

    Definition Classes
    Rational → Product
  69. def reduce(): Rational

    Reduce the mangnitude of the numerator and denonimator by dividing both by their Greatest Common Divisor (GCD).

  70. def reverse: Ordering[Rational]

    Definition Classes
    Ordering → PartialOrdering
  71. def root(q: Rational, l: Long): Rational

  72. def signum(x: Rational): Int

    Definition Classes
    Numeric
  73. def sqrt: Rational

    Return the square root of that rational number.

  74. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  75. def times(q: Rational, l: Long): Rational

  76. def times(q: Rational, p: Rational): Rational

    Definition Classes
    Rational → Numeric
  77. def toBigDecimal: BigDecimal

  78. def toBigDecimal(q: Rational): BigDecimal

    Convert that/this rational number to a BigDecimal number.

    Convert that/this rational number to a BigDecimal number.

    q

    that rational number to convert

  79. def toDouble: Double

  80. def toDouble(q: Rational): Double

    Convert that/this rational number to a Double.

    Convert that/this rational number to a Double.

    q

    that rational number to convert

    Definition Classes
    Rational → Numeric
  81. def toFloat: Float

  82. def toFloat(q: Rational): Float

    Convert that/this rational number to a Float.

    Convert that/this rational number to a Float.

    q

    that rational number to convert

    Definition Classes
    Rational → Numeric
  83. def toInt: Int

  84. def toInt(q: Rational): Int

    Convert that/this rational number to an Int.

    Convert that/this rational number to an Int.

    q

    that rational number to convert

    Definition Classes
    Rational → Numeric
  85. def toLong: Long

  86. def toLong(q: Rational): Long

    Convert this rational number to a Long.

    Convert this rational number to a Long.

    q

    that rational number to convert

    Definition Classes
    Rational → Numeric
  87. def toString(): String

    Convert this rational number to a String.

    Convert this rational number to a String.

    Definition Classes
    Rational → AnyRef → Any
  88. def tryCompare(x: Rational, y: Rational): Some[Int]

    Definition Classes
    Ordering → PartialOrdering
  89. def unary_-(): Rational

    Compute the unary minus (-).

  90. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  91. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  92. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  93. def zero: Rational

    Definition Classes
    Numeric
  94. def ~^(l: Long): Rational

    Raise a rational number to the l-th power.

    Raise a rational number to the l-th power.

    l

    the long power/exponent

  95. def ~^(q: Rational): Rational

    Raise a rational number to the q-th power.

    Raise a rational number to the q-th power.

    q

    the rational power/exponent

Deprecated Value Members

  1. def productElements: Iterator[Any]

    Definition Classes
    Product
    Annotations
    @deprecated
    Deprecated

    (Since version 2.8.0) use productIterator instead

Inherited from Product

Inherited from Equals

Inherited from Ordered[Rational]

Inherited from Comparable[Rational]

Inherited from Fractional[Rational]

Inherited from Numeric[Rational]

Inherited from Ordering[Rational]

Inherited from Serializable

Inherited from Serializable

Inherited from PartialOrdering[Rational]

Inherited from Equiv[Rational]

Inherited from Comparator[Rational]

Inherited from AnyRef

Inherited from Any