Rat

scalation.Rat
See theRat companion class
object Rat

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

Attributes

Companion
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Rat.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror

Value members

Concrete methods

def abs(x: Rat): Rat

Return the absolute value of that rational number.

Return the absolute value of that rational number.

Value parameters

x

that rational number

Attributes

def apply(qt: (Long, Long)): Rat

Create a rational number from a pair of Longs.

Create a rational number from a pair of Longs.

Value parameters

qt

the tuple form of a rational number

Attributes

def apply(qs: String): Rat

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

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

Value parameters

qs

the string form of a rational number

Attributes

def create(qs: String): Rat

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

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

Value parameters

qs

the string form of a rational number

Attributes

def fromBigDecimal(y: BigDecimal): Rat

Create a rational number from a BigDecimal number.

Create a rational number from a BigDecimal number.

Value parameters

md

the maximum denominator

y

the BigDecimal used to create the rational number

Attributes

def fromDouble(y: Double): Rat

Create a rational number from a Double.

Create a rational number from a Double.

Value parameters

md

the maximum denominator

y

the double used to create the rational number

Attributes

def fromDouble2(y: Double, md: Long = ...): Rat

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

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

Value parameters

md

the maximum denominator

y

the double used to create the rational number.

Attributes

See also
def fromDouble3(y: Double): Rat

Create a rational number with a small odd denominator from a Double y by running through possible odd denominators d from 1 to max_d and creating two candidate numerators n for each d, one with n/d below and other above.

Create a rational number with a small odd denominator from a Double y by running through possible odd denominators d from 1 to max_d and creating two candidate numerators n for each d, one with n/d below and other above.

Value parameters

y

the double used to create the rational number.

Attributes

def fromFloat(y: Float): Rat

Create a rational number from a Float.

Create a rational number from a Float.

Value parameters

y

the float used to create the rational number.

Attributes

def fromInt(n: Int): Rat

Create a rational number from an Int.

Create a rational number from an Int.

Value parameters

n

the integer used to create the rational number.

Attributes

def fromLong(n: Long): Rat

Create a rational number from a Long.

Create a rational number from a Long.

Value parameters

n

the long used to create the rational number.

Attributes

def from_BigDecimal(y: BigDecimal, md: Long = ...): (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.

Value parameters

md

the maximum denominator

y

the BigDecimal used to create the rational number

Attributes

def from_Double(y: Double, md: Long = ...): (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.

Value parameters

md

the maximum denominator

y

the double used to create the rational number

Attributes

See also
def make(s: String): Rat

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

Value parameters

s

the given String representation of a number

Attributes

See also
def max(q: Rat, p: Rat): Rat

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

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

Value parameters

p

the second rational number to compare

q

the first rational number to compare

Attributes

def min(q: Rat, p: Rat): Rat

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

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

Value parameters

p

the second rational number to compare

q

the first rational number to compare

Attributes

def signum(r: Rat): Rat

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

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

Value parameters

r

the rational number to obtain the sigum of

Attributes

def sqrt(x: Rat): Rat

Return the square root of that rational number.

Return the square root of that rational number.

Value parameters

x

that rational number

Attributes

Concrete fields

val _0: Rat

Zero (0) as a Rat number

Zero (0) as a Rat number

Attributes

val _1: Rat

One (1) as a Rat number

One (1) as a Rat number

Attributes

val _1_big: BigDecimal

One in BigDecimal

One in BigDecimal

Attributes

val _1n: Rat

Negative one (-1) as a Rat number

Negative one (-1) as a Rat number

Attributes

val maxDen: Long

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

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

Attributes

val ord: Ordering[Rat]

Ordering for rational numbers

Ordering for rational numbers

Attributes