Rational

com.phasmidsoftware.number.core.inner.Rational
See theRational companion object
case class Rational extends NumberLike

Rational: a case class that represents rational numbers by a BigInt numerator and a BigInt denominator. The numerator (n) and the denominator (d) may not share a common factor: if you try to construct a Rational with new where there is a common factor, then an exception will be thrown. However, all the apply methods ensure valid Rational instances by factoring out any common factors. Similarly, the denominator may not be negative: again, the apply methods will take care of this situation. This is the reason that the constructor of Rational is marked package-private.

The domain of Rational includes values with a zero value in the denominator and any numerator (either -ve or +ve infinity) as well as the value with 0 as both the numerator and denominator (NaN).

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait NumberLike
class Object
trait Matchable
class Any
Show all

Members list

Value members

Abstract methods

def abs: Number
Implicitly added by convertToNumber

Method to yield the absolute value of this Number.

Method to yield the absolute value of this Number.

Attributes

Returns

this if its positive, else - this.

def applyFunc(f: Double => Double, dfByDx: Double => Double): Try[Number]
Implicitly added by convertToNumber

Method to apply a function to this Number.

Method to apply a function to this Number.

Value parameters

dfByDx

the first derivative of f.

f

a function Double=>Double.

Attributes

Returns

a Try[Number] which is the result of applying f to this Number.

def asComparedWith(other: Number): Option[Fuzziness[Double]]
Implicitly added by convertToNumber

Return optional Fuzziness of Box shape, such that this would be considered just within the resulting tolerance.

Return optional Fuzziness of Box shape, such that this would be considered just within the resulting tolerance.

Value parameters

other

another Number: the ideal or target value.

Attributes

Returns

an optional relative Fuzziness.

def atan(y: Number): Number
Implicitly added by convertToNumber

Calculate the angle whose opposite length is y and whose adjacent length is this.

Calculate the angle whose opposite length is y and whose adjacent length is this.

Value parameters

y

the opposite length

Attributes

Returns

the angle defined by x = this, y = y

def composeDyadic(other: Number, f: Factor)(op: DyadicOperation): Option[Number]
Implicitly added by convertToNumber

Evaluate a dyadic operator on this and other, using either plus, times, ... according to the value of op. NOTE: this and other must have been aligned by type so that they have the same structure.

Evaluate a dyadic operator on this and other, using either plus, times, ... according to the value of op. NOTE: this and other must have been aligned by type so that they have the same structure.

Value parameters

f

the factor to apply to the result.

op

the appropriate DyadicOperation.

other

the other operand, a Number.

Attributes

Returns

a new Number which is result of applying the appropriate function to the operands this and other.

def cosh: Number
Implicitly added by convertToNumber

Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.

Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.

Attributes

Returns

the cosine.

infix def doAdd(n: Number): Number
Implicitly added by convertToNumber

Add this Number to n.

Add this Number to n.

Value parameters

n

another Number.

Attributes

Returns

the sum of this and n.

infix def doDivide(n: Number): Number
Implicitly added by convertToNumber

Divide this Number by n.

Divide this Number by n.

Value parameters

n

another Number.

Attributes

Returns

this quotient of this and n, i.e., this/n.

infix def doMultiply(n: Number): Number
Implicitly added by convertToNumber

Multiply this Number by n.

Multiply this Number by n.

Value parameters

n

another Number.

Attributes

Returns

the product of this and n.

def doPower(p: Number): Number
Implicitly added by convertToNumber

Raise this Number to the power p.

Raise this Number to the power p.

Value parameters

p

a Number.

Attributes

Returns

this Number raised to the power of p.

def exp: Number
Implicitly added by convertToNumber

Method to raise e to the power of this number. The result will be a Number with NatLog factor.

Method to raise e to the power of this number. The result will be a Number with NatLog factor.

Attributes

Returns

the e to the power of this.

def factor: Factor
Implicitly added by convertToNumber

The factor of this Number. Ordinary numbers are of PureNumber factor, angles have factor Radian, and natural logs have factor NatLog.

The factor of this Number. Ordinary numbers are of PureNumber factor, angles have factor Radian, and natural logs have factor NatLog.

Attributes

Returns

the factor.

def fuzzyCompare(other: Number, confidence: Double = ...): Int
Implicitly added by convertToNumber

Perform a fuzzy comparison where we only require p confidence to know that this and other are effectively the same.

Perform a fuzzy comparison where we only require p confidence to know that this and other are effectively the same.

Value parameters

confidence

the confidence expressed as a fraction of 1 (oneSigma would be a typical value).

other

the Number to be compared with.

Attributes

Returns

-1, 0, 1 as usual.

def isImaginary: Boolean
Implicitly added by convertToNumber

Method to determine if this is an imaginary Number, that's to say a number with negative value and SquareRoot as its factor.

Method to determine if this is an imaginary Number, that's to say a number with negative value and SquareRoot as its factor.

Attributes

Returns

true if imaginary.

def isInteger: Boolean
Implicitly added by convertToNumber

Method to determine if this Number is actually represented is an Integer.

Method to determine if this Number is actually represented is an Integer.

Attributes

Returns

true if exact and integral.

def isPositive: Boolean
Implicitly added by convertToNumber

Method to determine if this Number is positive. Use case: does the String representation not start with a "-"?

Method to determine if this Number is positive. Use case: does the String representation not start with a "-"?

CONSIDER evaluating toString instead.

Attributes

Returns

true if this Number is greater than or equal to 0.

def isProbablyZero(confidence: Double = ...): Boolean
Implicitly added by convertToNumber

Value parameters

confidence

the confidence desired. Ignored if isZero is true.

Attributes

Returns

true if this Number is equivalent to zero with at least p confidence.

def isRational: Boolean
Implicitly added by convertToNumber

Method to determine if this Number is actually represented as a Rational.

Method to determine if this Number is actually represented as a Rational.

Attributes

Returns

true if exact and rational.

def isValid: Boolean
Implicitly added by convertToNumber

Method to determine if this is a valid Number. An invalid number has a value of form Left(Left(Left(None)))

Method to determine if this is a valid Number. An invalid number has a value of form Left(Left(Left(None)))

Attributes

Returns

true if this is a valid Number

def ln: Field
Implicitly added by convertToNumber

Method to determine the natural log of this Number. The result will be a Number with PureNumber factor. CONSIDER renaming this as "ln" but keep in mind that the Java library calls the function "log."

Method to determine the natural log of this Number. The result will be a Number with PureNumber factor. CONSIDER renaming this as "ln" but keep in mind that the Java library calls the function "log."

Attributes

Returns

the natural log of this.

def log(b: Number): Number
Implicitly added by convertToNumber

Returns the log of this Number in base b.

Returns the log of this Number in base b.

Value parameters

b

the base for which to calculate the logarithm

Attributes

Returns

the logarithm of the input number to base b

def make(v: Value, f: Factor): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Both the value and the factor will be changed.

Make a copy of this Number, given the same degree of fuzziness as the original. Both the value and the factor will be changed.

Value parameters

f

the factor.

v

the value.

Attributes

Returns

either a Number.

def make(f: Factor): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the factor will change. This method does not need to be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the factor will change. This method does not need to be followed by a call to specialize.

Value parameters

f

the factor.

Attributes

Returns

either a Number.

def make(v: Value): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Value parameters

v

the value.

Attributes

Returns

either a Number.

def make(v: Int, f: Factor): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Value parameters

f

Factor.

v

the value.

Attributes

Returns

either a Number.

def make(v: Int): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Value parameters

v

the value.

Attributes

Returns

either a Number.

def make(r: Rational, f: Factor): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and the factor will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and the factor will change. This method should be followed by a call to specialize.

Value parameters

f

Factor.

r

a Rational.

Attributes

Returns

either a Number.

def make(v: Rational): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.

Value parameters

v

the value.

Attributes

Returns

either a Number.

def make(v: Double, f: Factor): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.

Value parameters

f

Factor.

v

the value (a Double).

Attributes

Returns

either a Number.

def make(v: Double, f: Factor, fo: Option[Fuzziness[Double]]): Number
Implicitly added by convertToNumber

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.

Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.

Value parameters

f

Factor.

fo

optional fuzz.

v

the value (a Double).

Attributes

Returns

either a Number.

def make(fo: Option[Fuzziness[Double]]): Number
Implicitly added by convertToNumber

Make a copy of this Number, with the same value and factor but with a different value of fuzziness.

Make a copy of this Number, with the same value and factor but with a different value of fuzziness.

Value parameters

fo

the (optional) fuzziness.

Attributes

Returns

a Number.

Implicitly added by convertToNumber

Negative of this Number.

Negative of this Number.

Attributes

def maybeNominalDouble: Option[Double]
Implicitly added by convertToNumber

An optional Double that corresponds to the value of this Number (but ignoring the factor).

An optional Double that corresponds to the value of this Number (but ignoring the factor).

Attributes

Implicitly added by convertToNumber

Method to ensure that the value is within some factor-specific range. In particular, Radian=based numbers are modulated to the range 0..2

Method to ensure that the value is within some factor-specific range. In particular, Radian=based numbers are modulated to the range 0..2

Attributes

Returns

this or an equivalent Number.

Implicitly added by convertToNumber

The nominal value of this Number.

The nominal value of this Number.

Attributes

Returns

the nominalValue.

def probabilityOfZero: Option[Double]
Implicitly added by convertToNumber

Calculates the probability of an event resulting in zero under the given conditions. The method returns an optional value to represent cases where the probability cannot be determined.

Calculates the probability of an event resulting in zero under the given conditions. The method returns an optional value to represent cases where the probability cannot be determined.

Attributes

Returns

An Option containing the probability as a Double if it can be computed, or None if the probability is indeterminate.

def query[T](op: QueryOperation[T], defaultVal: => T): T
Implicitly added by convertToNumber

Evaluate a query operator on this.

Evaluate a query operator on this.

Value parameters

op

the appropriate QueryOperation.

Attributes

Returns

a T.

def scale(f: Factor): Number
Implicitly added by convertToNumber

Method to create a new version of this, but with factor f. NOTE: the result will have the same absolute magnitude as this. In other words, in the case where f is not factor, the numerical value of the result's value will be different from this value.

Method to create a new version of this, but with factor f. NOTE: the result will have the same absolute magnitude as this. In other words, in the case where f is not factor, the numerical value of the result's value will be different from this value.

Value parameters

f

the new factor for the result.

Attributes

Returns

a Number based on this and factor.

def signum(confidence: Double = ...): Int
Implicitly added by convertToNumber

Method to determine the sense of this number: negative, zero, or positive. If this FuzzyNumber cannot be distinguished from zero with p confidence, then

Method to determine the sense of this number: negative, zero, or positive. If this FuzzyNumber cannot be distinguished from zero with p confidence, then

Value parameters

confidence

the confidence desired.

Attributes

Returns

an Int which is negative, zero, or positive according to the magnitude of this.

def signum: Int
Implicitly added by convertToNumber

Method to determine the sense of this number: negative, zero, or positive.

Method to determine the sense of this number: negative, zero, or positive.

Attributes

Returns

an Int which is negative, zero, or positive according to the magnitude of this.

Implicitly added by convertToNumber

Method to make some trivial simplifications of this Number (only if exact).

Method to make some trivial simplifications of this Number (only if exact).

Attributes

Returns

either this Number or a simplified Number.

def sinh: Number
Implicitly added by convertToNumber

Method to determine the sine of this Number. The result will be a Number with PureNumber factor.

Method to determine the sine of this Number. The result will be a Number with PureNumber factor.

Attributes

Returns

the sine of this.

Implicitly added by convertToNumber

Return a Number which uses the most restricted type possible. A Number based on a Double will yield a Number based on a Rational (if the conversion is exact). A Number based on a Rational will yield a Number based on a BigInt (if there is a unit denominator). A Number based on a BigInt will yield a Number based on a Int (if it is sufficiently small).

Return a Number which uses the most restricted type possible. A Number based on a Double will yield a Number based on a Rational (if the conversion is exact). A Number based on a Rational will yield a Number based on a BigInt (if there is a unit denominator). A Number based on a BigInt will yield a Number based on a Int (if it is sufficiently small).

CONSIDER do we really need this in Number?

Attributes

Returns

a Number with the same magnitude as this.

def tanh: Number
Implicitly added by convertToNumber
def thresholdConfidence: Option[Double]
Implicitly added by convertToNumber

Retrieves the optional threshold value for confidence, which can be used to determine a cut-off point for decision-making or validation processes.

Retrieves the optional threshold value for confidence, which can be used to determine a cut-off point for decision-making or validation processes.

Attributes

Returns

An Option[Double] representing the confidence threshold. Some(value) indicates a

def toBigDecimal: Option[BigDecimal]
Implicitly added by convertToNumber

Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.

Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.

Attributes

Returns

an Option of BigDecimal.

def toBigInt: Option[BigInt]
Implicitly added by convertToNumber

Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.

Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.

Attributes

Returns

an Option of BigInt.

def toInt: Option[Int]
Implicitly added by convertToNumber

Method to get the value of this Number as an Int.

Method to get the value of this Number as an Int.

Attributes

Returns

an Option of Int. If this Number cannot be converted to an Int, then None will be returned.

Implicitly added by convertToNumber

Method to get the value of this Number as an (optional) Rational. If this is actually a Double, it will be converted to a Rational according to the implicit conversion from Double to Rational. See Rational.convertDouble(x).

Method to get the value of this Number as an (optional) Rational. If this is actually a Double, it will be converted to a Rational according to the implicit conversion from Double to Rational. See Rational.convertDouble(x).

Attributes

Returns

an Option of Rational.

Implicitly added by convertToNumber

Evaluate a monadic operator on this.

Evaluate a monadic operator on this.

Value parameters

f

the factor to apply to the result.

op

the appropriate MonadicOperation.

Attributes

Returns

a new Number which is result of applying the appropriate function to the operand this.

Concrete methods

def *(that: BigInt): Rational

Multiplies this Rational number by the given BigInt and returns the result as a new Rational.

Multiplies this Rational number by the given BigInt and returns the result as a new Rational.

Value parameters

that

the BigInt to multiply this Rational by

Attributes

Returns

a new Rational resulting from the multiplication

def *(that: Short): Rational

Multiplies this Rational instance by the provided Short value, producing a new Rational instance.

Multiplies this Rational instance by the provided Short value, producing a new Rational instance.

Value parameters

that

the Short value to multiply with this Rational

Attributes

Returns

a new Rational instance representing the product of this Rational and the provided Short

def *(that: Rational): Rational

Multiplies this Rational number by another Rational number.

Multiplies this Rational number by another Rational number.

Value parameters

that

the Rational number to multiply with this Rational number

Attributes

Returns

a new Rational number representing the product of this Rational number and the given Rational number

def *(that: Long): Rational

Multiplies this Rational number by a given Long value and returns the result as a new Rational number.

Multiplies this Rational number by a given Long value and returns the result as a new Rational number.

Value parameters

that

the Long value to multiply with this Rational number

Attributes

Returns

a new Rational number representing the product of this Rational number and the given Long value

def +(that: BigInt): Rational

Adds a BigInt value to this Rational number.

Adds a BigInt value to this Rational number.

Value parameters

that

The BigInt value to be added to this Rational.

Attributes

Returns

A new Rational representing the sum of this Rational and the given BigInt.

def +(that: Rational): Rational
def +(that: Long): Rational

Adds a Long value to this Rational number and returns the resulting Rational.

Adds a Long value to this Rational number and returns the resulting Rational.

Value parameters

that

the Long value to be added to this Rational number

Attributes

Returns

a new Rational representing the sum of this Rational and the given Long value

def -(that: BigInt): Rational

Subtracts a BigInt value from this Rational number and returns the resulting Rational.

Subtracts a BigInt value from this Rational number and returns the resulting Rational.

Value parameters

that

the BigInt value to subtract from this Rational

Attributes

Returns

the result of the subtraction as a Rational

def -(that: Rational): Rational

Subtracts the given Rational number from this Rational number and returns the result.

Subtracts the given Rational number from this Rational number and returns the result.

Value parameters

that

the Rational number to be subtracted from this Rational number

Attributes

Returns

a new Rational representing the result of the subtraction

def /(that: Long): Rational

Divides the current Rational instance by the given Long value and returns a new Rational instance representing the result.

Divides the current Rational instance by the given Long value and returns a new Rational instance representing the result.

Value parameters

that

the Long value to divide the current Rational instance by

Attributes

Returns

a new Rational instance resulting from the division

def /(that: Rational): Rational

Divides this Rational number by another Rational number.

Divides this Rational number by another Rational number.

Value parameters

that

the Rational number to divide by

Attributes

Returns

a new Rational number representing the result of the division

def add(x: Field): Field
Implicitly added by convertToNumber

Add x to this Number and return the result.

Add x to this Number and return the result.

Value parameters

x

the addend.

Attributes

Returns

the sum.

def applyExponent(exponent: Int): Rational

Applies an integer exponent to this Rational instance.

Applies an integer exponent to this Rational instance.

Value parameters

exponent

the exponent to which this Rational will be raised. It can be positive, negative, or zero.

Attributes

Returns

a new Rational that is the result of raising this Rational to the given exponent.

def applySign(negative: Boolean): Rational

Applies a sign to this Rational based on the given boolean value. If the value is true, it negates the current Rational, otherwise, it returns the original instance.

Applies a sign to this Rational based on the given boolean value. If the value is true, it negates the current Rational, otherwise, it returns the original instance.

Value parameters

negative

a boolean indicating whether the Rational should be negated (true) or left as is (false)

Attributes

Returns

a Rational instance with the applied sign

def asNumber: Option[Number]
Implicitly added by convertToNumber

Attributes

Returns

Some(this).

def compare(other: Rational): Int

Compares this Rational instance with another Rational instance and determines their relative order.

Compares this Rational instance with another Rational instance and determines their relative order.

Value parameters

other

the Rational instance to compare with this instance

Attributes

Returns

an Int value: - Negative if this instance is less than the other instance, - Zero if they are equal, - Positive if this instance is greater than the other instance

def divide(x: Field): Field
Implicitly added by convertToNumber

Divide this Number by x and return the result.

Divide this Number by x and return the result.

Value parameters

x

the divisor.

Attributes

Returns

the quotient.

def doMultiple(x: Int): Number
Implicitly added by convertToNumber

Perform an exact scalar multiplication of this Number by the scale factor x. Implemented by doMultiple(Rational) where you should consult NOTE

Perform an exact scalar multiplication of this Number by the scale factor x. Implemented by doMultiple(Rational) where you should consult NOTE

Value parameters

x

an Int.

Attributes

Returns

a new Number which is this Number scaled by z.

Implicitly added by convertToNumber

Perform an exact scalar multiplication of this Number by the scale factor r.

Perform an exact scalar multiplication of this Number by the scale factor r.

NOTE that numbers with Logarithmic factors cannot be scaled exactly in this way.

Value parameters

r

a Rational.

Attributes

Returns

a new Number which is this Number scaled by z.

Implicitly added by convertToNumber

Subtract n from this Number

Subtract n from this Number

Value parameters

n

another Number.

Attributes

Returns

the difference of this and n.

def exceedsPrecision(maybeDelta: Option[Double]): Boolean

Determines if the given delta exceeds the precision of the rational resolution.

Determines if the given delta exceeds the precision of the rational resolution.

Value parameters

maybeDelta

The optional value to be compared against the precision of the rational resolution. This should come from the wiggle room of Absolute fuzz.

Attributes

Returns

True if the absolute value of the input exceeds the precision of the rational resolution, false otherwise. False if maybeDelta is None.

def maybeFactor: Option[Factor]
Implicitly added by convertToNumber

Retrieves an optional Factor instance.

Retrieves an optional Factor instance.

Attributes

Returns

Some(factor).

def mediant(other: Rational): Rational

Method to determine the Mediant of two rational numbers. See Wikipedia: Mediant (Mathematics). The result will always be intermediate in value to this and other. The Mediant plays a role in the Farey Sequence (see Wikipedia) and thus can be used to approximate an irrational number as a rational number.

Method to determine the Mediant of two rational numbers. See Wikipedia: Mediant (Mathematics). The result will always be intermediate in value to this and other. The Mediant plays a role in the Farey Sequence (see Wikipedia) and thus can be used to approximate an irrational number as a rational number.

Value parameters

other

the other number.

Attributes

Returns

the mediant of this and other.

def multiply(x: Field): Field
Implicitly added by convertToNumber

Multiplies the current instance by another Field and returns the result. Handles special cases such as multiplication with zero, one, or specific constants.

Multiplies the current instance by another Field and returns the result. Handles special cases such as multiplication with zero, one, or specific constants.

NOTE this code seems almost identical to the times method in GeneralNumber CONSIDER combining them and using the Factor facilities more.

Value parameters

x

the Field instance to be multiplied with the current instance

Attributes

Returns

the result of the multiplication as a Field

def negateConditional(cond: Boolean): Number
Implicitly added by convertToNumber

Negates the value of the instance conditionally based on the input parameter.

Negates the value of the instance conditionally based on the input parameter.

Value parameters

cond

A boolean parameter that determines whether to negate the value. If true, the negation function makeNegative is applied. Otherwise, the current instance is returned unchanged.

Attributes

Returns

The negated value as a Number if the condition is true, or the current instance if the condition is false.

def power(p: Number): Number
Implicitly added by convertToNumber
def power(p: Field): Field
Implicitly added by convertToNumber

Raise this Number to the power p.

Raise this Number to the power p.

Value parameters

p

a Field.

Attributes

Returns

this Number raised to power p.

def power(p: Int): Rational

Method to calculate the value of this Rational raised to the power of p.

Method to calculate the value of this Rational raised to the power of p.

Value parameters

p

an Int which may be negative, zero, or positive.

Attributes

Returns

this raised to the power of p.

def power(x: Rational): Try[Rational]

Method to get the xth power of this Rational, exactly.

Method to get the xth power of this Rational, exactly.

Value parameters

x

the power (any Rational) whose numerator and denominator can each be represented by an Int.

Attributes

Returns

Success(...) if the result can be calculated exactly, else Failure.

def renderApproximate(maxLength: Int, maybePlaces: Option[Int] = ...): String

Renders a string representation of the object either exactly or approximately, depending on the constraints of the provided parameters.

Renders a string representation of the object either exactly or approximately, depending on the constraints of the provided parameters.

Value parameters

maxLength

The maximum length of the resulting string representation.

maybePlaces

An optional parameter specifying the number of decimal places to use for rendering. If not provided, a default value is inferred based on the constraints.

Attributes

Returns

A string representation of the object padded to the specified maximum length. Throws an exception if the representation cannot fit within the constraints.

def renderAsPercent(places: Int): String

Converts a number to a percentage representation with a specified number of decimal places.

Converts a number to a percentage representation with a specified number of decimal places.

Value parameters

places

The number of decimal places to include in the percentage representation.

Attributes

Returns

A string representation of the number as a percentage with the specified number of decimal places.

def renderConditional(exact: Boolean): (String, Boolean)

Renders a conditional output based on the provided boolean flag. CONSIDER: why not return an Option[String] ? NOTE the parameter exact is always true.

Renders a conditional output based on the provided boolean flag. CONSIDER: why not return an Option[String] ? NOTE the parameter exact is always true.

Value parameters

exact

A boolean flag indicating whether to render the exact output or a default value.

Attributes

Returns

A tuple containing the rendered string and a boolean indicating the success of rendering.

def root(x: Int, epsilon: Option[Double] = ...): Option[Rational]

Method to get the xth root of this Rational. Note that it is not guaranteed to result in an exact value.

Method to get the xth root of this Rational. Note that it is not guaranteed to result in an exact value.

Value parameters

epsilon

if defined, this represents an acceptable error in the calculation (defaults to None).

x

the root to be taken, for example, for the cube root, we set x = 3.

Attributes

Returns

an (optional) Rational result which is the exact root. In the event that it's not possible to get the exact root, then None is returned.

def toLong: Option[Long]
Implicitly added by convertToNumber

Method to get the value of this Number as an Long.

Method to get the value of this Number as an Long.

Attributes

Returns

an Option of Long. If this Number cannot be converted to a Long, then None will be returned.

def unary_-: Field
Implicitly added by convertToNumber

Change the sign of this Number.

Change the sign of this Number.

Attributes

def ∧(that: Int): Rational

Raises this Rational number to the power of the given exponent. NOTE: this is not the caret symbol (that operator is deprecated).

Raises this Rational number to the power of the given exponent. NOTE: this is not the caret symbol (that operator is deprecated).

Value parameters

that

the exponent to which this Rational number will be raised

Attributes

Returns

a new Rational representing the result of raising this Rational to the given exponent

def ∧(that: Rational): Try[Rational]

Raises this Rational number to the power of the given Rational number.

Raises this Rational number to the power of the given Rational number.

Value parameters

that

the Rational number representing the exponent

Attributes

Returns

a Try containing the resulting Rational number if the operation is successful, or a Failure if an error occurs during the calculation

Deprecated methods

def ^(that: Int): Rational

Raises this Rational number to the power of the given exponent. WARNING: this is deprecated in favor of ∧(that: Int) because the precedence for this operator is lower than for multiplication, addition, etc.

Raises this Rational number to the power of the given exponent. WARNING: this is deprecated in favor of ∧(that: Int) because the precedence for this operator is lower than for multiplication, addition, etc.

Value parameters

that

the exponent to which this Rational number will be raised

Attributes

Returns

a new Rational representing the result of raising this Rational to the given exponent

Deprecated
[Since version 1.2.1] use ∧ instead

Inherited methods

def <(that: Number): Boolean
Implicitly added by convertToNumber

Returns true if this is less than that

Returns true if this is less than that

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def <=(that: Number): Boolean
Implicitly added by convertToNumber

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
def >(that: Number): Boolean
Implicitly added by convertToNumber

Returns true if this is greater than that.

Returns true if this is greater than that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def >=(that: Number): Boolean
Implicitly added by convertToNumber

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
def asJavaNumber: Option[Number]
Implicitly added by convertToNumber

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

The method determines whether the current NumberLike object can be represented as a java.lang.Number by leveraging the asNumber method and further evaluating certain conditions:

  • If the NumberLike object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the NumberLike object is a FuzzyNumber with a wiggle value below a specified tolerance, the result is also converted using Value.asJavaNumber.
  • In all other cases, None is returned.

Attributes

Returns

an optional java.lang.Number representation of this object. The result is Some(java.lang.Number) if the conversion is successful under the stated conditions; otherwise, None.

Inherited from:
NumberLike
def asJavaNumber: Option[Number]

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

The method determines whether the current NumberLike object can be represented as a java.lang.Number by leveraging the asNumber method and further evaluating certain conditions:

  • If the NumberLike object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the NumberLike object is a FuzzyNumber with a wiggle value below a specified tolerance, the result is also converted using Value.asJavaNumber.
  • In all other cases, None is returned.

Attributes

Returns

an optional java.lang.Number representation of this object. The result is Some(java.lang.Number) if the conversion is successful under the stated conditions; otherwise, None.

Inherited from:
NumberLike
def compareTo(that: Number): Int
Implicitly added by convertToNumber

Result of comparing this with operand that.

Result of comparing this with operand that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def memberOf(set: NumberSet): Boolean
Implicitly added by convertToNumber

Method to determine if this NumberLike object is a member of the given set.

Method to determine if this NumberLike object is a member of the given set.

Value parameters

set

the candidate NumberSet.

Attributes

Returns

true if this is exact and belongs to set.

Inherited from:
NumberLike
def memberOf: Option[NumberSet]
Implicitly added by convertToNumber

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Attributes

Returns

Some(numberSet) or None if it doesn't belong to any (for example, it is fuzzy).

Inherited from:
NumberLike
def memberOf(set: NumberSet): Boolean

Method to determine if this NumberLike object is a member of the given set.

Method to determine if this NumberLike object is a member of the given set.

Value parameters

set

the candidate NumberSet.

Attributes

Returns

true if this is exact and belongs to set.

Inherited from:
NumberLike
def memberOf: Option[NumberSet]

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Attributes

Returns

Some(numberSet) or None if it doesn't belong to any (for example, it is fuzzy).

Inherited from:
NumberLike
def noFuzz[U >: Double : HasValue]: Fuzziness[U]
Implicitly added by convertToNumber

Creates a fuzziness value with zero magnitude and a Gaussian distribution. This method provides a representation of deterministic or non-fuzzy values by ensuring that the fuzziness magnitude is explicitly zero.

Creates a fuzziness value with zero magnitude and a Gaussian distribution. This method provides a representation of deterministic or non-fuzzy values by ensuring that the fuzziness magnitude is explicitly zero.

Type parameters

U

a supertype of T that also satisfies the HasValue type class constraint.

Attributes

Returns

a Fuzziness[U] instance with zero magnitude and Gaussian shape.

Inherited from:
Fuzz
def productElementNames: Iterator[String]

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
def productIterator: Iterator[Any]

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
def show: String
Implicitly added by convertToNumber

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Attributes

Returns

a String

Inherited from:
NumberLike
def show: String

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Attributes

Returns

a String

Inherited from:
NumberLike

Inherited and Abstract methods

def addFuzz(f: Fuzziness[Double]): Fuzz[Double]
Implicitly added by convertToNumber

Adds the provided fuzziness to the current Fuzz[T] and returns the resulting value. This method may utilize the fuzziness parameter for calculations where applicable.

Adds the provided fuzziness to the current Fuzz[T] and returns the resulting value. This method may utilize the fuzziness parameter for calculations where applicable.

Value parameters

f

the fuzziness to add, represented as a Fuzziness[T].

Attributes

Returns

a Number that represents the result of adding the provided fuzziness.

Inherited from:
Fuzz
def asReal: Option[Real]
Implicitly added by convertToNumber

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Attributes

Returns

an Option[Real].

Inherited from:
Numerical
def compare(that: Number): Int
Implicitly added by convertToNumber

Result of comparing this with operand that.

Result of comparing this with operand that.

Implement this method to determine how instances of A will be sorted.

Returns x where:

  • x &lt; 0 when this &lt; that

  • x == 0 when this == that

  • x > 0 when this > that

Value parameters

that

the instance to compare against

Attributes

Returns

an integer whose sign indicates the ordering relation between this and that

Inherited from:
Ordered
def fuzz: Option[Fuzziness[Double]]
Implicitly added by convertToNumber

Retrieves an optional fuzziness value associated with this instance.

Retrieves an optional fuzziness value associated with this instance.

The fuzziness value, if present, provides information about the level of uncertainty or imprecision, modeled as a Fuzziness[Double].

Attributes

Returns

an Option containing the Fuzziness[Double] value if defined, or None if no fuzziness is specified.

Inherited from:
WithFuzziness
def isExact: Boolean
Implicitly added by convertToNumber

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in the context of No factor, else false.

Inherited from:
NumberLike
def isInfinite: Boolean
Implicitly added by convertToNumber

Method to determine if this Field has infinite magnitude.

Method to determine if this Field has infinite magnitude.

Attributes

Returns

true if the magnitude of this Field is infinite.

Inherited from:
Numerical
def isSame(x: Numerical, confidence: Double = ...): Boolean
Implicitly added by convertToNumber

Method to determine if this Numerical is equivalent to another Numerical object (x).

Method to determine if this Numerical is equivalent to another Numerical object (x).

Value parameters

x

the other Numerical.

Attributes

Returns

true if they are most probably the same, otherwise false.

Inherited from:
Numerical
def isUnity: Boolean
Implicitly added by convertToNumber

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Attributes

Returns

true if the magnitude of this Field is one.

Inherited from:
Numerical
def isZero: Boolean
Implicitly added by convertToNumber

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Attributes

Returns

true if the magnitude of this Field is zero.

Inherited from:
Numerical
Implicitly added by convertToNumber

Method to "normalize" a field.

Method to "normalize" a field.

Attributes

Returns

a Field which is in canonical form.

Inherited from:
Numerical
def render: String
Implicitly added by convertToNumber

Method to render this NumberLike in a presentable manner.

Method to render this NumberLike in a presentable manner.

Attributes

Returns

a String

Inherited from:
NumberLike

Abstract fields

lazy val cos: Number
Implicitly added by convertToNumber

Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.

Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.

Attributes

Returns

the cosine.

lazy val sin: Number
Implicitly added by convertToNumber

Method to determine the sine of this Number. The result will be a Number with PureNumber factor.

Method to determine the sine of this Number. The result will be a Number with PureNumber factor.

Attributes

Returns

the sine of this.

lazy val sqrt: Number
Implicitly added by convertToNumber

Yields the square root of this Number. If possible, the result will be exact.

Yields the square root of this Number. If possible, the result will be exact.

Attributes

Concrete fields

lazy val abs: Rational

The absolute value of this Rational. If the sign of this is negative, the result will be the negation of this. Otherwise, it will return the Rational itself.

The absolute value of this Rational. If the sign of this is negative, the result will be the negation of this. Otherwise, it will return the Rational itself.

Attributes

lazy val asComplex: Complex
Implicitly added by convertToNumber

Method to return this Number as a Complex.

Method to return this Number as a Complex.

Attributes

Returns

Complex(this) as appropriate.

lazy val asNumber: Option[Number]

Method to determine if this Field is actually a real Number (i.e. not complex). NOTE: to force this as a Number, use convertToNumber in the companion Object.

Method to determine if this Field is actually a real Number (i.e. not complex). NOTE: to force this as a Number, use convertToNumber in the companion Object.

Attributes

Returns

a Some(x) if this is a Number; otherwise return None.

lazy val findRepeatingSequence: Try[String]

Finds and returns the repeating sequence in the decimal representation of a fraction. The method uses the numerator, denominator, and the prime factorization of the denominator to compute the repeating sequence.

Finds and returns the repeating sequence in the decimal representation of a fraction. The method uses the numerator, denominator, and the prime factorization of the denominator to compute the repeating sequence.

Attributes

Returns

a Try containing the repeating sequence as a String if successful, or a Failure if an error occurs

lazy val forceToBigDecimal: BigDecimal

Converts the Rational number to a BigDecimal representation. If the Rational number represents infinity, an exception is thrown.

Converts the Rational number to a BigDecimal representation. If the Rational number represents infinity, an exception is thrown.

Attributes

Returns

A BigDecimal representing the Rational number.

Note

Throws RationalException if the Rational number is infinity.

lazy val getInverse: Number
Implicitly added by convertToNumber

Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.

Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.

CONSIDER allowing logarithmic numbers to be inverted simply by changing the sign of the value.

Attributes

lazy val halve: Rational
lazy val invert: Field
Implicitly added by convertToNumber

Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.

Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.

CONSIDER allowing logarithmic numbers to be inverted simply by changing the sign of the value.

Attributes

lazy val invert: Rational

Inverts the numerator and the denominator of a Rational number.

Inverts the numerator and the denominator of a Rational number.

Attributes

Returns

A new Rational instance with the numerator and denominator swapped.

lazy val isDecimal: Boolean

Method to determine if this Rational can be represented exactly as a decimal string.

Method to determine if this Rational can be represented exactly as a decimal string.

NOTE: re: (fixed) Issue #85 It's inappropriate to look for prime factors of very large numbers just to determine if we can represent this Rational as a decimal.

Originally, the code here was as follows: denominatorPrimeFactors.map(_.toBigInt).sorted.distinct.filterNot(x => x == bigTwo).forall(x => x == bigFive)

Attributes

Returns

true if the prime factors only include 2 and/or 5.

lazy val isExact: Boolean

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in the context of No factor, else false.

lazy val isExactDouble: Boolean

Determines if this Rational can be exactly represented as a Double.

Determines if this Rational can be exactly represented as a Double.

Attributes

Returns

true if the Rational can be precisely converted to a Double, otherwise false.

lazy val isInfinite: Boolean

Method to determine if the given Rational represents an infinity (positive or negative).

Method to determine if the given Rational represents an infinity (positive or negative).

Attributes

Returns

true if the denominator is zero; false otherwise.

lazy val isNaN: Boolean

Determines if the Rational object represents "not a number" (NaN).

Determines if the Rational object represents "not a number" (NaN).

Attributes

Returns

true if the Rational is both zero and infinite, indicating an undefined result; false otherwise.

lazy val isNegative: Boolean

Determines if the value is negative.

Determines if the value is negative.

Attributes

Returns

true if the value is negative, false otherwise.

lazy val isUnity: Boolean

Checks if the number is equal to one and is a whole number.

Checks if the number is equal to one and is a whole number.

Attributes

Returns

true if the number is exactly one and is a whole number, false otherwise

lazy val isWhole: Boolean

Determines if the number is a whole number.

Determines if the number is a whole number.

Attributes

Returns

true if the number is equal to the mathematical representation of one; false otherwise.

lazy val isZero: Boolean

Determines if the number is zero and is a whole number.

Determines if the number is zero and is a whole number.

Attributes

Returns

true if the number is zero and is a whole number, otherwise false

lazy val maybeDouble: Option[Double]

Returns an optional Double representation of this Rational. The method checks if the Rational can be exactly represented as a Double. If so, it converts the value to Double and returns it wrapped in Some. Otherwise, it returns None.

Returns an optional Double representation of this Rational. The method checks if the Rational can be exactly represented as a Double. If so, it converts the value to Double and returns it wrapped in Some. Otherwise, it returns None.

Attributes

Returns

an Option[Double], Some(Double) if the Rational can be exactly represented as a Double, otherwise None.

lazy val maybeFactor: Option[Factor]

Method to determine what Factor, if there is such, this NumberLike object is based on.

Method to determine what Factor, if there is such, this NumberLike object is based on.

Attributes

Returns

an optional Factor.

lazy val maybeInt: Option[Int]

Returns an optional integer representation of this Rational. If the Rational is not a whole number or is too large for Int, None is returned.

Returns an optional integer representation of this Rational. If the Rational is not a whole number or is too large for Int, None is returned.

Attributes

Returns

an Option[Int].

lazy val maybeLong: Option[Long]

Method to optionally convert this Rational into an Option[Long].

Method to optionally convert this Rational into an Option[Long].

Attributes

Returns

an Option[Long].

lazy val negate: Rational

Computes the negation of this Rational number.

Computes the negation of this Rational number.

Attributes

Returns

A new Rational instance representing the additive inverse of this Rational.

lazy val render: String

Renders the current object into its string representation. The method conditionally determines the output based on the result of an internal conditional computation. TODO improve this doc! For example, how can we ensure that the output will be decimal, not a ratio?

Renders the current object into its string representation. The method conditionally determines the output based on the result of an internal conditional computation. TODO improve this doc! For example, how can we ensure that the output will be decimal, not a ratio?

Attributes

Returns

A string representation of the object. If a certain condition evaluates to true, a specific value is returned; otherwise, the object's toString is used.

lazy val renderExact: String

Method to render a Rational in a manner other than as a rational number (for that, use toString).

Method to render a Rational in a manner other than as a rational number (for that, use toString).

Attributes

Returns

an exact String representation of this Rational.

lazy val signum: Int

The value of n.signum. NOTE that d is non-negative for all values in the domain of Rational except for negative zero.

The value of n.signum. NOTE that d is non-negative for all values in the domain of Rational except for negative zero.

Attributes

lazy val sqrt: Try[Rational]

The square root of this Rational.

The square root of this Rational.

This is achieved by raising this to the power of 1/2.

Attributes

Returns

Success containing the square root if it can be calculated, otherwise Failure containing an explanation of why the calculation failed.

lazy val square: Number
Implicitly added by convertToNumber

Calculates the square of a number by multiplying the number by itself. CONSIDER different implementations according to the factor.

Calculates the square of a number by multiplying the number by itself. CONSIDER different implementations according to the factor.

Attributes

Returns

the result of squaring this number

lazy val tan: Number
Implicitly added by convertToNumber

Method to determine the tangent of this Number. The result will be a Number with PureNumber factor. NOTE that not all cases have been tested.

Method to determine the tangent of this Number. The result will be a Number with PureNumber factor. NOTE that not all cases have been tested.

Attributes

Returns

the tangent

lazy val toBigDecimal: Option[BigDecimal]

Converts this Rational to an Option[BigDecimal] if it can be exactly represented as a decimal. If the Rational can be precisely represented as a BigDecimal, it is returned wrapped in Some. Otherwise, None is returned.

Converts this Rational to an Option[BigDecimal] if it can be exactly represented as a decimal. If the Rational can be precisely represented as a BigDecimal, it is returned wrapped in Some. Otherwise, None is returned.

Attributes

Returns

an Option[BigDecimal], where Some(BigDecimal) represents the exact conversion, or None if the Rational cannot be exactly represented.

lazy val toBigInt: BigInt

Method to convert this Rational into a BigInt. It is better to use Rational.toBigInt.

Method to convert this Rational into a BigInt. It is better to use Rational.toBigInt.

NOTE this will throw an exception if this Rational is not whole.

Attributes

Returns

a BigInt.

lazy val toDouble: Double

Converts this Rational instance into a Double representation.

Converts this Rational instance into a Double representation.

Attributes

Returns

the Double value of this Rational.

lazy val toFloat: Float

Converts this Rational instance to its Float representation.

Converts this Rational instance to its Float representation.

Attributes

Returns

a Float value representing this Rational.

lazy val toInt: Int

Method to convert this Rational into an Int. It is better to use maybeInt.

Method to convert this Rational into an Int. It is better to use maybeInt.

NOTE this will throw an exception if this Rational is not whole or its numerator is too large for an Int.

Attributes

Returns

an Int.

lazy val toLong: Long

Converts the current instance of Rational to its Long representation. If the conversion is not possible, it attempts to recover from the failure. NOTE this will throw an exception if this Rational is not whole or its numerator is too large for a Long.

Converts the current instance of Rational to its Long representation. If the conversion is not possible, it attempts to recover from the failure. NOTE this will throw an exception if this Rational is not whole or its numerator is too large for a Long.

Attributes

Returns

the long representation of the Rational value.

lazy val toNominalDouble: Option[Double]
Implicitly added by convertToNumber

Method to get the nominalValue of this Number as an optional Double.

Method to get the nominalValue of this Number as an optional Double.

Attributes

Returns

an Some(Double) which is the closest possible nominalValue to the nominal nominalValue, otherwise None if this is invalid.

lazy val toPureNumber: Number
Implicitly added by convertToNumber

Converts the current number instance into a pure number representation. The conversion is based on the factor and fuzz values associated with the number. NOTE that even if this Number is exact, the result may not be.

Converts the current number instance into a pure number representation. The conversion is based on the factor and fuzz values associated with the number. NOTE that even if this Number is exact, the result may not be.

Attributes

Returns

A new instance of Number in pure number representation, performing the necessary conversion and scaling if required.

lazy val toRationalString: String

Represents the fractional string format of the object as "numerator/denominator". Converts the values of n (numerator) and d (denominator) to a string. The result is a lazily evaluated string construction.

Represents the fractional string format of the object as "numerator/denominator". Converts the values of n (numerator) and d (denominator) to a string. The result is a lazily evaluated string construction.

Attributes

lazy override val toString: String

Converts the Rational object to its string representation. Rational numbers are represented as "numerator/denominator" or "numerator" if the denominator is 1.

Converts the Rational object to its string representation. Rational numbers are represented as "numerator/denominator" or "numerator" if the denominator is 1.

Attributes

Returns

A string representation of the Rational object.