MixedFraction class
Dart representation of a 'mixed fraction', which is made up by the whole
part and a proper fraction. A proper fraction is a fraction in which the
relation numerator <= denominator
is true.
There's the possibility to create an instance of MixedFraction either by using one of the constructors or the extension methods on num and String.
MixedFraction(
whole: 5,
numerator: 2,
denominator: 3,
);
MixedFraction.fromDouble(1.5);
MixedFraction.fromString("1 1/2");
There also are extension methods to quickly build Fraction objects from primitive types:
1.5.toMixedFraction();
"1 1/2".toMixedFraction();
If the string doesn't represent a valid fraction, a MixedFractionException is thrown.
Constructors
- MixedFraction({required int whole, required int numerator, required int denominator})
-
Creates an instance of a mixed fraction.
factory
- MixedFraction.fromDouble(double value, {double precision = 1.0e-12})
-
Tries to give a fractional representation of a double according with the
given precision. This implementation takes inspiration from the continued
fraction algorithm.
factory
- MixedFraction.fromFraction(Fraction fraction)
-
Creates an instance of a mixed fraction.
factory
- MixedFraction.fromString(String value)
-
Creates an instance of a mixed fraction. The input string must be in the
form 'a b/c' with exactly one space between the whole part and the
fraction.
factory
Properties
- denominator → int
-
The divisor
b
of thea/b
division, which also is the denominator of the associated fraction.no setteroverride - fractionalPart → Fraction
-
Returns the fractional part of the mixed fraction as Fraction object.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNegative → bool
-
True or false whether this rational number is positive or negative.
no setteroverride
- isWhole → bool
-
True or false whether this rational number is whole or not.
no setteroverride
- numerator → int
-
The dividend
a
of thea/b
division, which also is the numerator of the associated fraction.no setteroverride - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- whole → int
-
Whole part of the mixed fraction.
final
Methods
-
compareTo(
Rational other) → int -
Compares this object to another object.
inherited
-
copyWith(
{int? whole, int? numerator, int? denominator}) → MixedFraction - Creates a deep copy of this object with the given fields replaced with the new values.
-
negate(
) → MixedFraction -
The sign is changed and the result is returned in new instance.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reduce(
) → MixedFraction -
Reduces this rational number to the lowest terms and returns the result in
a new instance.
override
-
toDouble(
) → double -
A floating point representation of this rational number.
override
-
toEgyptianFraction(
) → List< Fraction> -
Represents this rational number as an egyptian fraction.
override
-
toFraction(
) → Fraction - Converts this mixed fraction into a fraction.
-
toString(
) → String -
A string representation of this object.
override
-
toStringAsGlyph(
) → String - If possible, this method converts this MixedFraction instance into an unicode glyph string. For example:
Operators
-
operator *(
MixedFraction other) → MixedFraction - The product of two mixed fractions.
-
operator +(
MixedFraction other) → MixedFraction - The sum between two mixed fractions.
-
operator -(
MixedFraction other) → MixedFraction - The difference between two mixed fractions.
-
operator /(
MixedFraction other) → MixedFraction - The division of two mixed fractions.
-
operator <(
Rational other) → bool -
Checks whether this rational number is smaller than the other.
inherited
-
operator <=(
Rational other) → bool -
Checks whether this rational number is smaller or equal than the other.
inherited
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
Rational other) → bool -
Checks whether this rational number is greater than the other.
inherited
-
operator >=(
Rational other) → bool -
Checks whether this rational number is greater or equal than the other.
inherited
-
operator [](
int index) → int - Access the whole part, the numerator or the denominator of the fraction via index. In particular: