Packages

object Rational extends Serializable

The Rational companion object defines the origin (zero), one and minus one as well as some utility functions.

Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Rational
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. val _0: Rational

    Zero (0) as a Rational number

  5. val _1: Rational

    One (1) as a Rational number

  6. val _1_big: BigDecimal

    One in BigDecimal

  7. val _1n: Rational

    Negative one (-1) as a Rational number

  8. def abs(x: Rational): Rational

    Return the absolute value of that rational number.

    Return the absolute value of that rational number.

    x

    that rational number

  9. def apply(qs: String): Rational

    Create a rational number from its primary string representation "a/b".

    Create a rational number from its primary string representation "a/b". Examples: "2/3", "2".

    qs

    the string form of a rational number

  10. def apply(qt: (Long, Long)): Rational

    Create a rational number from a pair of Longs.

    Create a rational number from a pair of Longs.

    qt

    the tuple form of a rational number

  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  13. def create(qs: String): Rational

    Create a rational number from its secondary string representation "(a, b)".

    Create a rational number from its secondary string representation "(a, b)". Examples: "(2, 3)", "(2, 1)".

    qs

    the string form of a rational number

  14. implicit def double2Rational(d: Double): Rational

    Implicit conversion from 'Double' to 'Rational'.

    Implicit conversion from 'Double' to 'Rational'.

    d

    the Double parameter to convert

  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  17. 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

  18. 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

  19. def fromDouble2(y: Double, md: Long = maxDen): Rational

    Create a rational number from a Double.

    Create a rational number from a Double. FIX: if den not a power of 2, it goes to 'md'.

    y

    the double used to create the rational number.

    md

    the maximum denominator

    See also

    http://rosettacode.org/wiki/Convert_decimal_number_to_rational

  20. 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.

  21. def fromInt(n: Int): Rational

    Create a rational number from an Int.

    Create a rational number from an Int.

    n

    the integer used to create the rational number.

  22. 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.

  23. def from_BigDecimal(y: BigDecimal, md: Long = Long.MaxValue): (Long, Long)

    Determine the numerator and denonimator of the closest rational number to the given BigDecimal number.

    Determine the numerator and denonimator of the closest rational number to the given BigDecimal number.

    y

    the BigDecimal used to create the rational number

    md

    the maximum denominator

  24. def from_Double(y: Double, md: Long = maxDen): (Long, Long)

    Determine the numerator and denonimator of the closest rational number to the given BigDecimal number.

    Determine the numerator and denonimator of the closest rational number to the given BigDecimal number.

    y

    the double used to create the rational number

    md

    the maximum denominator

    See also

    http://stackoverflow.com/questions/5124743/algorithm-for-simplifying- decimal-to-fractions/5128558#5128558

  25. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  27. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  28. def make(s: String): Rational

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

    Make 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

  29. def max(q: Rational, p: Rational): Rational

    Return the maximum of two rational numbers, q and p.

    Return the maximum of two rational numbers, q and p.

    q

    the first rational number to compare

    p

    the second rational number to compare

  30. val maxDen: Long

    Denominator (2 ~^ 54) big enough to capture largest Double significand (53 bits)

  31. def min(q: Rational, p: Rational): Rational

    Return the minimum of two rational numbers, q and p.

    Return the minimum of two rational numbers, q and p.

    q

    the first rational number to compare

    p

    the second rational number to compare

  32. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  33. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  34. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  35. implicit val num: Rational

    Implicit numeric value for establishing type

  36. implicit val ord: Ordering[Rational]

    Ordering for rational numbers

  37. def signum(r: Rational): Rational

    Return the signum (sgn) of a rational number.

    Return the signum (sgn) of a rational number. The values may be -1, 0, or 1.

    r

    the rational number to obtain the sigum of

  38. def sqrt(x: Rational): Rational

    Return the square root of that rational number.

    Return the square root of that rational number.

    x

    that rational number

  39. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  40. def toString(): String
    Definition Classes
    AnyRef → Any
  41. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  42. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  43. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped