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.

Implemented types

Constructors

MixedFraction({required int whole, required int numerator, required int denominator})
Creates an instance of a mixed fraction.
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
Denominator of the fraction.
final
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 the mixed fraction is positive or negative.
no setter
numerator int
Numerator of the fraction.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
whole int
Whole part of the mixed fraction.
final

Methods

compareTo(MixedFraction other) int
Compares this object to another object.
override
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
Changes the sign of this mixed fraction and returns the results in a new MixedFraction instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce() MixedFraction
Reduces this mixed fraction to the lowest terms and returns the results in a new MixedFraction instance.
toDouble() double
Floating point representation of the mixed fraction.
toEgyptianFraction() List<Fraction>
Represents the current mixed fraction as an egyptian fraction.
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
Product between two mixed fractions.
operator +(MixedFraction other) MixedFraction
Sum between two mixed fractions.
operator -(MixedFraction other) MixedFraction
Difference between two mixed fractions.
operator /(MixedFraction other) MixedFraction
Division between two mixed fractions.
operator <(MixedFraction other) bool
Checks whether this mixed fraction is smaller than the other.
operator <=(MixedFraction other) bool
Checks whether this mixed fraction is smaller or equal than the other.
operator ==(Object other) bool
The equality operator.
override
operator >(MixedFraction other) bool
Checks whether this mixed fraction is greater than the other.
operator >=(MixedFraction other) bool
Checks whether this mixed fraction is greater or equal than the other.
operator [](int index) int
Access the whole part, the numerator or the denominator of the fraction via index. In particular: