Represents a rational number with basic arithmetic operations and field properties. This class provides methods and implicit instances for managing rational numbers and their integration with mathematical abstractions such as the Field typeclass.
Attributes
- Companion
- class
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
RationalNumber.type
Members list
Type members
Classlikes
Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.
Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.
This instance defines a no-op conversion, where a RationalNumber is returned as-is when converted to another RationalNumber. It enables compatibility with the Convertible typeclass interface, but does not alter or transform the provided RationalNumber.
Value parameters
- u
-
the
RationalNumberinstance to be returned - witness
-
an optional
RationalNumberinstance provided as a template (unused in this implementation)
Attributes
- Returns
-
the input
RationalNumberreturned directly without modification - Supertypes
- Self type
Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.
Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.
This conversion attempts to recover a RationalNumber representation from a given Real object. If the Real instance cannot be converted into a RationalNumber, an AlgebraException is thrown describing the failure.
Attributes
- Returns
-
a
RationalNumberinstance that is equivalent to the providedReal, if the conversion is successful - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the conversion fails.
- Supertypes
- Self type
Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.
Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.
This implementation defines the convert method, which delegates the conversion of a WholeNumber to its corresponding RationalNumber representation by invoking the toRationalNumber method on the WholeNumber instance.
Attributes
- Supertypes
- Self type
Provides an implicit implementation of the Field type class for the RationalNumber type.
Provides an implicit implementation of the Field type class for the RationalNumber type.
This object defines the standard operations required for RationalNumber to function as a field, including addition, multiplication, division, and their respective identity and inverse operations. By extending the Field type class, it ensures compliance with field axioms.
Attributes
- Supertypes
-
trait Field[RationalNumber]trait CommutativeSemifield[RationalNumber]trait MultiplicativeCommutativeGroup[RationalNumber]trait DivisionRing[RationalNumber]trait Semifield[RationalNumber]trait MultiplicativeGroup[RationalNumber]trait EuclideanRing[RationalNumber]trait GCDRing[RationalNumber]trait CommutativeRing[RationalNumber]trait CommutativeRng[RationalNumber]trait CommutativeRig[RationalNumber]trait MultiplicativeCommutativeMonoid[RationalNumber]trait CommutativeSemiring[RationalNumber]trait MultiplicativeCommutativeSemigroup[RationalNumber]trait Ring[RationalNumber]trait Rng[RationalNumber]trait AdditiveCommutativeGroup[RationalNumber]trait AdditiveGroup[RationalNumber]trait Rig[RationalNumber]trait MultiplicativeMonoid[RationalNumber]trait Semiring[RationalNumber]trait MultiplicativeSemigroup[RationalNumber]trait AdditiveCommutativeMonoid[RationalNumber]trait AdditiveCommutativeSemigroup[RationalNumber]trait AdditiveMonoid[RationalNumber]trait AdditiveSemigroup[RationalNumber]trait Serializableclass Objecttrait Matchableclass AnyShow all
- Self type
Value members
Concrete methods
Converts a given Rational to a RationalNumber.
Converts a given Rational to a RationalNumber.
Value parameters
- r
-
the
Rationalvalue to be converted
Attributes
- Returns
-
a new
RationalNumberinstance representing the givenRational
Creates a RationalNumber instance from two provided Long values, representing the numerator and denominator of a rational number.
Creates a RationalNumber instance from two provided Long values, representing the numerator and denominator of a rational number.
Value parameters
- x
-
the numerator of the rational number
- y
-
the denominator of the rational number
Attributes
- Returns
-
a
RationalNumberinstance constructed from the given numerator and denominator
Constructs a RationalNumber instance from the given numerator and denominator.
Constructs a RationalNumber instance from the given numerator and denominator.
Value parameters
- x
-
The numerator as a
BigInt. - y
-
The denominator as a
BigInt.
Attributes
- Returns
-
A
RationalNumberrepresenting the fractionx / y.
Creates a rational number representation from a given integer value.
Creates a rational number representation from a given integer value.
Value parameters
- x
-
the integer value to be converted into a rational number
Attributes
- Returns
-
a
RationalNumberrepresenting the input integer
Parses a string representation of a rational number and converts it into an Option[RationalNumber].
Parses a string representation of a rational number and converts it into an Option[RationalNumber].
Value parameters
- w
-
the string representation of the rational number to be parsed
Attributes
- Returns
-
an
Option[RationalNumber]containing the parsed rational number if successful, orNoneif parsing fails
Converts a given Rational value into a RationalNumber representing its percentage equivalent.
Converts a given Rational value into a RationalNumber representing its percentage equivalent.
Value parameters
- r
-
the
Rationalvalue expressed as a percentage, e.g., 50 for 50%.
Attributes
- Returns
-
a
RationalNumberinstance representing the percentage value of the givenRational
Concrete fields
Represents a predefined constant value of one-half as a RationalNumber. This is a convenience representation of the fraction 1/2 in the system of rational numbers.
Represents a predefined constant value of one-half as a RationalNumber. This is a convenience representation of the fraction 1/2 in the system of rational numbers.
Attributes
Represents a rational number with an infinite value.
Represents a rational number with an infinite value.
This value is constructed from the infinity representation of the Rational type.
Attributes
Represents the rational number -1 as a predefined constant. This is an instance of the RationalNumber class initialized with the negative one value from the Rational type.
Represents the rational number -1 as a predefined constant. This is an instance of the RationalNumber class initialized with the negative one value from the Rational type.
Attributes
Represents the rational number one as an instance of RationalNumber.
Represents the rational number one as an instance of RationalNumber.
Attributes
Represents the rational number zero. This is a predefined constant in the RationalNumber class.
Represents the rational number zero. This is a predefined constant in the RationalNumber class.
Attributes
Givens
Givens
Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.
Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.
This instance defines a no-op conversion, where a RationalNumber is returned as-is when converted to another RationalNumber. It enables compatibility with the Convertible typeclass interface, but does not alter or transform the provided RationalNumber.
Value parameters
- u
-
the
RationalNumberinstance to be returned - witness
-
an optional
RationalNumberinstance provided as a template (unused in this implementation)
Attributes
- Returns
-
the input
RationalNumberreturned directly without modification
Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.
Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.
This conversion attempts to recover a RationalNumber representation from a given Real object. If the Real instance cannot be converted into a RationalNumber, an AlgebraException is thrown describing the failure.
Attributes
- Returns
-
a
RationalNumberinstance that is equivalent to the providedReal, if the conversion is successful - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the conversion fails.
Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.
Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.
This implementation defines the convert method, which delegates the conversion of a WholeNumber to its corresponding RationalNumber representation by invoking the toRationalNumber method on the WholeNumber instance.
Attributes
A given instance of DyadicOperator for RationalNumber that provides an implementation of the op method, enabling the execution of a dyadic operation on two rational numbers. The operation is defined by a user-supplied function f, which specifies how the operands should be combined and produces a result wrapped in a Try.
A given instance of DyadicOperator for RationalNumber that provides an implementation of the op method, enabling the execution of a dyadic operation on two rational numbers. The operation is defined by a user-supplied function f, which specifies how the operands should be combined and produces a result wrapped in a Try.
Attributes
- Returns
-
A
Try[Z]representing the result of the operationfapplied to the operands, or an exception if the operation fails.
Provides an instance of Eq[RationalNumber], enabling equality comparison between two RationalNumber instances.
Provides an instance of Eq[RationalNumber], enabling equality comparison between two RationalNumber instances.
Attributes
- Returns
-
an
Eq[RationalNumber]instance that defines equality by delegating to theeqvmethod ofRationalNumber, or returningfalseif undefined
Provides an instance of the FuzzyEq type class for RationalNumber.
Provides an instance of the FuzzyEq type class for RationalNumber.
This instance defines the fuzzy equality for RationalNumber using the == operator to compare two RationalNumber instances based on their exact equality.
Attributes
- Returns
-
a
FuzzyEq[RationalNumber]instance defining the fuzzy equality forRationalNumber
Implicits
Implicits
Implicitly converts a Rational instance into a RationalNumber.
Implicitly converts a Rational instance into a RationalNumber.
Value parameters
- x
-
the
Rationalvalue to be converted
Attributes
- Returns
-
a
RationalNumberinstance representing the givenRational
LatexRenderer for Rational numbers.
LatexRenderer for Rational numbers.
Renders as:
- Integer if denominator is 1
- Fraction otherwise using \frac{numerator}{denominator}
- Handles negative values appropriately
Attributes
LatexRenderer for RationalNumber.
LatexRenderer for RationalNumber.
Delegates to the Rational renderer.
Attributes
Provides an implicit Show instance for the RationalNumber class. This instance defines how a RationalNumber is transformed into a String representation by using its render method.
Provides an implicit Show instance for the RationalNumber class. This instance defines how a RationalNumber is transformed into a String representation by using its render method.