The Rat class is used to represent and operate on rational numbers. Internally, a rational number is represented as two long integers. Externally, two forms are supported:
a/b = 2/3 via: Rat ("2/3"), 'toString'
(a, b) = (2, 3) via: create ("(2, 3)") 'toString2'
A Rat number can be created without loss of precision using the constructor, apply, create or fromBigDecimal methods. Other methods may lose precision.
Value parameters
- den
-
the denominator (e.g., 3L)
- num
-
the numerator (e.g., 2L)
Attributes
- Companion
- object
- Graph
-
- Supertypes
Members list
Type members
Inherited classlikes
Attributes
- Inherited from:
- Fractional
- Supertypes
Attributes
- Inherited from:
- Numeric
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
This inner class defines comparison operators available for T.
This inner class defines comparison operators available for T.
It can't extend AnyVal because it is not a top-level class or a member of a statically accessible object.
Attributes
- Inherited from:
- Ordering
- Supertypes
-
class Objecttrait Matchableclass Any
Value members
Concrete methods
Multiply two rational numbers, this * q.
Multiply two rational numbers, this * q.
Value parameters
- q
-
multiply this times rational q
Attributes
Multiply a rational number times a long, this * l.
Multiply a rational number times a long, this * l.
Value parameters
- l
-
multiply this times long l
Attributes
Add two rational numbers, this + q.
Add two rational numbers, this + q.
Value parameters
- q
-
add rational q to this
Attributes
Add a rational number plus a long, this + l.
Add a rational number plus a long, this + l.
Value parameters
- l
-
add long l to this
Attributes
Subtract two rational numbers, this - q.
Subtract two rational numbers, this - q.
Value parameters
- q
-
subtract rational q from this
Attributes
Subtract: this rational number minus a long, this - l.
Subtract: this rational number minus a long, this - l.
Value parameters
- l
-
subtract long l from this
Attributes
Divide two rational numbers, this / q.
Divide two rational numbers, this / q.
Value parameters
- q
-
divide this by rational q
Attributes
Divide a rational number div a long, this / l
Divide a rational number div a long, this / l
Value parameters
- l
-
divide this by long l
Attributes
Return whether two rational numbers are nearly equal.
Return whether two rational numbers are nearly equal.
Value parameters
- q
-
the compare 'this' with q
Attributes
Return the absolute value of this rational number.
Return the absolute value of this rational number.
Attributes
Compare two rational numbers (negative for <, zero for ==, positive for >).
Compare two rational numbers (negative for <, zero for ==, positive for >).
Value parameters
- p
-
the second rational number to compare
- q
-
the first rational number to compare
Attributes
Compare this rational number with that rational number 'q'.
Compare this rational number with that rational number 'q'.
Value parameters
- q
-
that rational number
Attributes
Override equals to determine whether this rational number equals rational 'c'.
Override equals to determine whether this rational number equals rational 'c'.
Value parameters
- c
-
the rational number to compare with this
Attributes
- Definition Classes
-
Equals -> Comparator -> Any
Create a rational number from a BigDecimal number.
Create a rational number from a BigDecimal number.
Value parameters
- y
-
the
BigDecimalused to create the rational number
Attributes
Create a rational number from a Double.
Create a rational number from a Double.
Value parameters
- y
-
the
Doubleused to create the rational number
Attributes
- See also
-
Rat.double2Rat
Create a rational number from a Float. Float is currently not fully supported.
Create a rational number from a Float. Float is currently not fully supported.
Value parameters
- y
-
the
Floatused to create the rational number
Attributes
Create a rational number from an Int.
Create a rational number from an Int.
Value parameters
- n
-
the
Intused to create the rational number
Attributes
Create a rational number from a Long.
Create a rational number from a Long.
Value parameters
- n
-
the
Longused to create the rational number
Attributes
Must also override hashCode to be be compatible with equals.
Must also override hashCode to be be compatible with equals.
Attributes
- Definition Classes
-
Any
Determine whether 'this' is within the given bounds
Determine whether 'this' is within the given bounds
Value parameters
- lim
-
the given (lower, upper) bounds
Attributes
Determine whether 'this' is in the given set.
Determine whether 'this' is in the given set.
Value parameters
- lim
-
the given set of values
Attributes
Determine whether this rational number is integral.
Determine whether this rational number is integral.
Attributes
Return the maximum of this and that rational numbers.
Return the maximum of this and that rational numbers.
Value parameters
- q
-
that rational number to compare with this
Attributes
Return the minimum of this and that rational numbers.
Return the minimum of this and that rational numbers.
Value parameters
- q
-
that rational number to compare with this
Attributes
Determine whether 'this' is not within the given bounds
Determine whether 'this' is not within the given bounds
Value parameters
- lim
-
the given (lower, upper) bounds
Attributes
Determine whether 'this' is not in the given set.
Determine whether 'this' is not in the given set.
Value parameters
- lim
-
the given set of values
Attributes
Parse the string to create a rational number.
Parse the string to create a rational number.
Attributes
Take the reciprocal of this rational number by swapping num and den.
Take the reciprocal of this rational number by swapping num and den.
Attributes
Reduce the magnitude of the numerator and denonimator by dividing both by their Greatest Common Divisor (GCD).
Reduce the magnitude of the numerator and denonimator by dividing both by their Greatest Common Divisor (GCD).
Attributes
Take the l-th root of the rational number q.
Take the l-th root of the rational number q.
Value parameters
- l
-
the long root
Attributes
Return the square root of that rational number.
Return the square root of that rational number.
Value parameters
- x
-
that rational number
Attributes
Convert that/this rational number to a BigDecimal number.
Convert that/this rational number to a BigDecimal number.
Value parameters
- q
-
that rational number to convert
Attributes
Convert that/this rational number to a Double.
Convert that/this rational number to a Double.
Value parameters
- q
-
that rational number to convert
Attributes
Convert that/this rational number to a Float.
Convert that/this rational number to a Float.
Value parameters
- q
-
that rational number to convert
Attributes
Convert that/this rational number to an Int.
Convert that/this rational number to an Int.
Value parameters
- q
-
that rational number to convert
Attributes
Convert this rational number to a Long.
Convert this rational number to a Long.
Value parameters
- q
-
that rational number to convert
Attributes
Convert that/this rational number to a Rat.
Convert that/this rational number to a Rat.
Value parameters
- q
-
that rational number to convert
Attributes
Convert this rational number to a String of the form 'a/b'.
Convert this rational number to a String of the form 'a/b'.
Attributes
- Definition Classes
-
Any
Convert this rational number to a String of the form '(a, b)'.
Convert this rational number to a String of the form '(a, b)'.
Attributes
Raise a rational number to the q-th power.
Raise a rational number to the q-th power.
Value parameters
- q
-
the rational power/exponent
Attributes
Raise a rational number to the l-th power.
Raise a rational number to the l-th power.
Value parameters
- l
-
the long power/exponent
Attributes
Raise a rational number to the q-th power. Extended to handle a negative base.
Raise a rational number to the q-th power. Extended to handle a negative base.
Value parameters
- q
-
the rational power/exponent
Attributes
- See also
-
pow_in CommonFunctions.
Compare 'this' rational number with that rational number 'q' for inequality.
Compare 'this' rational number with that rational number 'q' for inequality.
Value parameters
- q
-
that rational number
Attributes
Compare 'this' rational number with that rational number 'q' for less than or equal to.
Compare 'this' rational number with that rational number 'q' for less than or equal to.
Value parameters
- q
-
that rational number
Attributes
Inherited methods
Returns true if this is less than that
Returns true if this is less than that
Attributes
- Inherited from:
- Ordered
Returns true if this is less than or equal to that.
Returns true if this is less than or equal to that.
Attributes
- Inherited from:
- Ordered
Returns true if this is greater than that.
Returns true if this is greater than that.
Attributes
- Inherited from:
- Ordered
Returns true if this is greater than or equal to that.
Returns true if this is greater than or equal to that.
Attributes
- Inherited from:
- Ordered
Result of comparing this with operand that.
Result of comparing this with operand that.
Attributes
- Inherited from:
- Ordered
Returns true if x == y in the ordering.
Returns true if x == y in the ordering.
Attributes
- Definition Classes
-
Ordering -> PartialOrdering -> Equiv
- Inherited from:
- Ordering
Returns true if x > y in the ordering.
Returns true if x > y in the ordering.
Attributes
- Definition Classes
-
Ordering -> PartialOrdering
- Inherited from:
- Ordering
Returns true if x >= y in the ordering.
Returns true if x >= y in the ordering.
Attributes
- Definition Classes
-
Ordering -> PartialOrdering
- Inherited from:
- Ordering
Returns whether or not the other ordering is the opposite ordering of this one.
Returns whether or not the other ordering is the opposite ordering of this one.
Equivalent to other == this.reverse.
Implementations should only override this method if they are overriding reverse as well.
Attributes
- Inherited from:
- Ordering
Returns true if x < y in the ordering.
Returns true if x < y in the ordering.
Attributes
- Definition Classes
-
Ordering -> PartialOrdering
- Inherited from:
- Ordering
Returns true if x <= y in the ordering.
Returns true if x <= y in the ordering.
Attributes
- Definition Classes
-
Ordering -> PartialOrdering
- Inherited from:
- Ordering
Returns x if x >= y, otherwise y.
Returns x if x >= y, otherwise y.
Attributes
- Inherited from:
- Ordering
Returns x if x <= y, otherwise y.
Returns x if x <= y, otherwise y.
Attributes
- Inherited from:
- Ordering
Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:
Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:
def compare(x:U, y:U) = Ordering[T].compare(f(x), f(y))
Attributes
- Inherited from:
- Ordering
Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.
Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.
Value parameters
- other
-
an Ordering to use if this Ordering returns zero
Attributes
- Example
-
case class Pair(a: Int, b: Int) val pairOrdering = Ordering.by[Pair, Int](_.a) .orElse(Ordering.by[Pair, Int](_.b)) - Inherited from:
- Ordering
Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:
Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:
Ordering[S].compare(f(x), f(y))
This function is equivalent to passing the result of Ordering.by(f) to orElse.
Attributes
- Example
-
case class Pair(a: Int, b: Int) val pairOrdering = Ordering.by[Pair, Int](_.a) .orElseBy[Int](_.b) - Inherited from:
- Ordering
An iterator over the names of all the elements of this product.
An iterator over the names of all the elements of this product.
Attributes
- Inherited from:
- Product
An iterator over all the elements of this product.
An iterator over all the elements of this product.
Attributes
- Returns
-
in the default implementation, an
Iterator[Any] - Inherited from:
- Product
Returns the opposite ordering of this one.
Returns the opposite ordering of this one.
Implementations overriding this method MUST override isReverseOf as well if they change the behavior at all (for example, caching does not require overriding it).
Attributes
- Definition Classes
-
Ordering -> PartialOrdering
- Inherited from:
- Ordering
Attributes
- Inherited from:
- Comparator
Attributes
- Inherited from:
- Comparator
Attributes
- Inherited from:
- Comparator
Attributes
- Inherited from:
- Comparator
Attributes
- Inherited from:
- Comparator
Attributes
- Inherited from:
- Comparator
Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).
Returns whether a comparison between x and y is defined, and if so the result of compare(x, y).
Attributes
- Inherited from:
- Ordering
Implicits
Inherited implicits
Attributes
- Definition Classes
-
Fractional -> Numeric
- Inherited from:
- Fractional
This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.
This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.
Attributes
- Inherited from:
- Ordering