Rational
classin packageklyn.math
public class Rational extends Object
└ Rational

Represents a rational number with a numerator and a denominator.

Properties
Modifier and Type Member Description
public property denominator
denominator as Int
Property for the denominator.
public property numerator
numerator as Int
Property for the numerator.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public Rational
Rational( num as Int = 0, den as Int = 1 ) throws ZeroDivisionException
Constructor for Rational class.
Methods
Modifier and Type Member Description
public override hash
hash() as Long
Returns a value hash compatible with rational equality.
public simplify
simplify() as Void
Reduces the fraction and makes its denominator positive.
public override toString
toString() as String
Returns the string representation of the rational number.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml
Operators
Modifier and Type Member Description
public static operator<(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Tests whether the first fraction is strictly smaller than the second.
public static operator<=(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Tests whether the first fraction is smaller than or equal to the second.
public static operator!=(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Value inequality between two rational numbers.
public static operator*( readonly notnull r1 as Rational, readonly notnull r2 as Rational ) as Rational Overloaded multiplication operator for Rational numbers.
public static operator+(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Rational Overloaded addition operator for Rational numbers.
public static operator-( readonly notnull r1 as Rational, readonly notnull r2 as Rational ) as Rational Overloaded subtraction operator for Rational numbers.
public static operator/( readonly notnull r1 as Rational, readonly notnull r2 as Rational ) as Rational throws ZeroDivisionException Overloaded division operator for Rational numbers.
public static operator==(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Value equality between two rational numbers.
public static operator>(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Tests whether the first fraction is strictly greater than the second.
public static operator>=(readonly notnull r1 as Rational, readonly notnull r2 as Rational) as Boolean Tests whether the first fraction is greater than or equal to the second.