Rational class abstract base

Dart representation of a rational number.

A rational number is a number that can be expressed as the quotient x/y of two integers, a numerator x and a non-zero denominator y. Any rational number is also a real number.

Rational and all of its sub-types are immutable. This type can only be subclassed.

See also:

  • Fraction, to work with fractions in the form a/b
  • MixedFraction, to work with mixed fractions in the form a b/c
Implemented types
Implementers

Constructors

Rational()
Creates a Rational object.
const

Properties

denominator int
The divisor b of the a/b division, which also is the denominator of the associated fraction.
no setter
hashCode int
The hash code for this object.
no setterinherited
isNegative bool
True or false whether this rational number is positive or negative.
no setter
isWhole bool
True or false whether this rational number is whole or not.
no setter
numerator int
The dividend a of the a/b division, which also is the numerator of the associated fraction.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

compareTo(Rational other) int
Compares this object to another object.
override
negate() Rational
The sign is changed and the result is returned in new Rational object.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce() Rational
Reduces this rational number to the lowest terms and returns the result in a new Rational object.
toDouble() double
A floating point representation of this rational number.
toEgyptianFraction() List<Fraction>
Represents this rational number as an egyptian fraction.
toString() String
A string representation of this object.
inherited

Operators

operator <(Rational other) bool
Checks whether this rational number is smaller than the other.
operator <=(Rational other) bool
Checks whether this rational number is smaller or equal than the other.
operator ==(Object other) bool
The equality operator.
inherited
operator >(Rational other) bool
Checks whether this rational number is greater than the other.
operator >=(Rational other) bool
Checks whether this rational number is greater or equal than the other.

Static Methods

tryParse(String value) Rational?
This function tries to convert a String into a Fraction or MixedFraction object. If the conversion fails, null is returned. For example: