Rational class final

A rational representation with numerator and denominator.

Implemented types
Available extensions
Annotations
  • @immutable

Constructors

Rational(int _numerator, [int _denominator = 1])
Creates a new Rational from _numerator and _denominator.
const
Rational.fromDouble(double number, {int tolerance = 100})
Creates a new Rational from number and tolerance.
factory
Rational.fromMixed(int wholePart, [int numerator = 0, int _denominator = 1])
Creates a new Rational from wholePart, numerator, and _denominator.
const
Rational.parse(String source)
Parses source as a Rational.
factory

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
simple Rational
The simplified version of this Rational.
no setter

Methods

compareTo(Rational other) int
Compares this object to another object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDouble() double
This Rational as a double.
toInt() int
Truncates this Rational to an integer and returns the result as an int.
toString() String
A string representation of this object.
override

Operators

operator *(Rational other) Rational
Multiplies this Rational with other.
operator +(Rational other) Rational
Adds this Rational to other.
operator -(Rational other) Rational
Subtracts other from this Rational.
operator /(Rational other) Rational
Divides this Rational with other.
operator ==(Object other) bool
The equality operator.
override
operator unary-() Rational
Negates this Rational.

Constants

zero → const Rational
A Rational of value zero.