RationalOps

com.phasmidsoftware.number.core.inner.Rational.RationalOps
implicit class RationalOps(x: Int)

Implicit class RationalOps to allow an Int to be treated as a Rational for the purpose of allowing operations with right-hand Rational arguments or for division by an Int. A particular case is rational division where we must convert the numerator to Rational so that we don't end up with 0 as the result of an Int division.

Value parameters

x

an Int

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def *(r: Rational): Rational

Method to multiply x by r.

Method to multiply x by r.

Value parameters

r

the multiplicand.

Attributes

Returns

the result of x * r.

def +(r: Rational): Rational

Method to increment x by r.

Method to increment x by r.

Value parameters

r

the addend.

Attributes

Returns

the result of x + r.

def :/(denominator: Long): Rational

Method to divide by Rational. We cannot just use "/" as that will bind to Int and result in 0. Therefore, we use the special ":/" operator which will work as long as RationalOps is imported.

Method to divide by Rational. We cannot just use "/" as that will bind to Int and result in 0. Therefore, we use the special ":/" operator which will work as long as RationalOps is imported.

Value parameters

denominator

the denominator of the resulting Rational. Any Int will be implicitly converted to a Long.

Attributes

Returns

the Rational whose value is x/y

Concrete fields

lazy val invert: Rational

Computes the multiplicative inverse of the Rational representation of the given integer. The result is equivalent to 1 divided by the Rational value of the integer.

Computes the multiplicative inverse of the Rational representation of the given integer. The result is equivalent to 1 divided by the Rational value of the integer.

Attributes

Returns

the inverted Rational representation of the integer.