Rational

com.phasmidsoftware.lascala.values.Rational
See theRational companion class
object Rational

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Rational.type

Members list

Type members

Classlikes

final implicit class RationalHelper(val sc: StringContext) extends AnyVal

Implicit class RationalHelper to support the strings of form r"22/7", etc.

Implicit class RationalHelper to support the strings of form r"22/7", etc.

Value parameters

sc

the StringContext

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
trait RationalIsFractional[N] extends Fractional[Rational[N]]

Trait which enables Rational[N] to be used in type classes where the context type is a Fractional (or Numeric or Ordering).

Trait which enables Rational[N] to be used in type classes where the context type is a Fractional (or Numeric or Ordering).

Attributes

Supertypes
trait Fractional[Rational[N]]
trait Numeric[Rational[N]]
trait Ordering[Rational[N]]
trait PartialOrdering[Rational[N]]
trait Equiv[Rational[N]]
trait Serializable
trait Comparator[Rational[N]]
class Object
trait Matchable
class Any
Show all
Known subtypes

Attributes

Supertypes
trait Fractional[Rational[N]]
trait Numeric[Rational[N]]
trait Ordering[Rational[N]]
trait PartialOrdering[Rational[N]]
trait Equiv[Rational[N]]
trait Serializable
trait Comparator[Rational[N]]
class Object
trait Matchable
class Any
Show all
Known subtypes

Attributes

Supertypes
trait RationalIsFractional[BigInt]
trait Fractional[Rational[BigInt]]
trait Numeric[Rational[BigInt]]
trait Ordering[Rational[BigInt]]
trait PartialOrdering[Rational[BigInt]]
trait Equiv[Rational[BigInt]]
trait Serializable
trait Comparator[Rational[BigInt]]
class Object
trait Matchable
class Any
Show all
Self type

Implicit objects which extend RationalIsFractional. BTW, it's OK for them to share the same name.

Implicit objects which extend RationalIsFractional. BTW, it's OK for them to share the same name.

Attributes

Supertypes
trait Fractional[Rational[Int]]
trait Numeric[Rational[Int]]
trait Ordering[Rational[Int]]
trait PartialOrdering[Rational[Int]]
trait Equiv[Rational[Int]]
trait Serializable
trait Comparator[Rational[Int]]
class Object
trait Matchable
class Any
Show all
Self type

Attributes

Supertypes
trait RationalIsFractional[Long]
trait Fractional[Rational[Long]]
trait Numeric[Rational[Long]]
trait Ordering[Rational[Long]]
trait PartialOrdering[Rational[Long]]
trait Equiv[Rational[Long]]
trait Serializable
trait Comparator[Rational[Long]]
class Object
trait Matchable
class Any
Show all
Self type

Value members

Concrete methods

def NaN[N : FiniteIntegral]: Rational[Int]
def apply[N : FiniteIntegral](n: N, d: N): Rational[N]
def apply[N : FiniteIntegral](x: N): Rational[N]

Apply method to form a Rational from a FiniteIntegral

Apply method to form a Rational from a FiniteIntegral

Value parameters

x

the FiniteIntegral

Attributes

Returns

the Rational corresponding to x

def apply[N : FiniteIntegral](x: BigDecimal): Rational[N]

Apply method to form a Rational from a BigDecimal

Apply method to form a Rational from a BigDecimal

Value parameters

x

the BigDecimal

Attributes

Returns

the Rational corresponding to x

def apply[N : FiniteIntegral](x: Double): Rational[N]

Apply method to form a Rational from a Double

Apply method to form a Rational from a Double

Value parameters

x

the BigDecimal

Attributes

Returns

the Rational corresponding to x

def apply[N : FiniteIntegral](x: String): Rational[N]

Apply method to form a Rational from a String

Apply method to form a Rational from a String

Value parameters

x

the String

Attributes

Returns

the Rational corresponding to x

def compare[N : FiniteIntegral](x: Rational[N], y: Rational[N]): Int

Method to compare two Rational[N] numbers

Method to compare two Rational[N] numbers

Value parameters

x

the first Rational[N]

y

the second Rational[N]

Attributes

Returns

(x-y).signum

def convertToM[N, M](n: N)(implicit fn: FiniteIntegral[N], fm: FiniteIntegral[M]): M
def fromFractional[N : FiniteIntegral, M : Fractional](x: M): Rational[N]
def max[N : FiniteIntegral](r1: Rational[N], r2: Rational[N]): Rational[N]
def min[N : FiniteIntegral](r1: Rational[N], r2: Rational[N]): Rational[N]
def normalize[N](n: N, d: N)(implicit evidence$1: FiniteIntegral[N], builder: (N, N) => Rational[N]): Rational[N]

Method to form normalized Rational[N] from the given numerator and denominator

Method to form normalized Rational[N] from the given numerator and denominator

Value parameters

d

the denominator

n

the numerator

Attributes

Returns

a Rational[N] corresponding to n/d where n and d have no common factors

def one[N : FiniteIntegral]: Rational[N]
def plus[N](x: Rational[N], y: Rational[N])(implicit evidence$1: FiniteIntegral[N], builder: (N, N) => Rational[N]): Rational[N]

Method to add two Rational[N] objects together. The order of the parameters is immaterial.

Method to add two Rational[N] objects together. The order of the parameters is immaterial.

Value parameters

x

one of the Rational[N]s

y

the other Rational[N]

Attributes

Returns

a new Rational[N] which is the sum of x and y

def ten[N : FiniteIntegral]: Rational[N]
def times[N](x: Rational[N], y: Rational[N])(implicit evidence$1: FiniteIntegral[N], builder: (N, N) => Rational[N]): Rational[N]

Method to multiply two Rational[N] objects together. The order of the parameters is immaterial.

Method to multiply two Rational[N] objects together. The order of the parameters is immaterial.

Value parameters

x

one of the Rational[N]s

y

the other Rational[N]

Attributes

Returns

a new Rational[N] which is the product of x and y

def toBigInt[N : FiniteIntegral](x: Rational[N]): BigInt

Method to convert a Rational (x) into a BigInt

Method to convert a Rational (x) into a BigInt

Value parameters

x

the Rational to convert

Attributes

Returns

if x is whole, then the corresponding BigInt is returned.

def toInt[N : FiniteIntegral](x: Rational[N]): Int

Method to convert a Rational (x) into an Int

Method to convert a Rational (x) into an Int

Value parameters

x

the Rational to convert

Attributes

Returns

if x is whole and if x fits into the range of an Int, then the corresponding Int is returned; otherwise, we throw a FiniteIntegralException

def toLong[N : FiniteIntegral](x: Rational[N]): Long

Method to convert a Rational (x) into a Long

Method to convert a Rational (x) into a Long

Value parameters

x

the Rational to convert

Attributes

Returns

if x is whole, then the corresponding Long is returned; otherwise, we throw a FiniteIntegralException

def unapply[N](r: Rational[N]): Some[(N, N)]

Implicits

Implicits

final implicit def RationalHelper(sc: StringContext): RationalHelper

Implicit class RationalHelper to support the strings of form r"22/7", etc.

Implicit class RationalHelper to support the strings of form r"22/7", etc.

Value parameters

sc

the StringContext

Attributes

implicit def builder[N : FiniteIntegral](n: N, d: N): Rational[N]
implicit def doubleToRational[N : FiniteIntegral](x: Double): Rational[N]

Implicit conversion method from Double=>Rational[N]. This is used for example when comparing a Rational[N] value with an Double

Implicit conversion method from Double=>Rational[N]. This is used for example when comparing a Rational[N] value with an Double

Value parameters

x

a Double

Attributes

Returns

a Rational[N] with the same value as x, or at least as close as possible

implicit def intToRational[N : FiniteIntegral](x: Int): Rational[N]

Implicit conversion method from Int=>Rational. This is used for example when comparing a Rational value with an Int

Implicit conversion method from Int=>Rational. This is used for example when comparing a Rational value with an Int

Value parameters

x

an Int

Attributes

Returns

a Rational with the same value as x

implicit def longToRational[N : FiniteIntegral](x: Long): Rational[N]

Implicit conversion method from Long=>Rational[N]. This is used for example when comparing a Rational[N] value with an Long

Implicit conversion method from Long=>Rational[N]. This is used for example when comparing a Rational[N] value with an Long

Value parameters

x

an Long

Attributes

Returns

a Rational[N] with the same value as x