Fraction
ReferencesRepresents a fraction.
Constructors
Fraction
#Create a new fraction from numerator and denominator.
Parameters:
| numerator (BigInteger) | Fraction numerator. |
| denominator (BigInteger) | Fraction denominator. |
Properties
Magnitude
#Gets the magnitude or integral part of this fraction. If the fraction is negative, the integral part will be more positive than the fraction value.
Methods
Equals
#Indicates whether this instance and a specified object are equal.
Parameters:
| obj (object) | The object to compare with the current instance. |
Overrides: ValueType.Equals
GetHashCode
#Returns the hash code for this instance.
Returns: A 32-bit signed integer that is the hash code for this instance.
Overrides: ValueType.GetHashCode
Mean
#Compute the mean (or average) of two fractions.
Mediant
#Compute the mediant of two fractions.
Rationalise
#Find a fraction which well describes this double.
Rationalise
#Find a fraction which well describes this double.
RationalMediants
#Re-implementation of Eric Lippert's dedoublifier algorithm at: https://ericlippert.com/2015/12/10/the-dedoublifier-part-four/
Parameters:
| target (double) | Double value to approximate, must be in the range [0, 1). |
Returns: Sequence of rationals that (over time) approximate x.
Reduce
#Reduce this fraction by reducing the numerator and denominator by the greatest common denominator.
Returns: Reduced fraction.
ToString
#Gets the string representation of this fraction.
Returns: String.
Overrides: ValueType.ToString
ToString
#Gets the string representation of this fraction.
Operators
| Operation | Result | Description | ||
|---|---|---|---|---|
| Fraction | + | Fraction | Fraction | Add two fractions. The result is not necessarily in reduced form, as that may be a very slow operation. |
| Fraction | / | Fraction | Fraction | Divide two fractions. The result is not necessarily in reduced form, as that may be a very slow operation. |
| Fraction | == | Fraction | bool | Compare two fractions. Equality is defined numerically, not structurally. Undefined fractions are always unequal. |
| Fraction | > | Fraction | bool | Compare two fractions. |
| Fraction | >= | Fraction | bool | Compare two fractions. |
| Fraction | != | Fraction | bool | Compare two fractions. Inequality is defined numerically, not structurally. Undefined fractions are always unequal. |
| Fraction | < | Fraction | bool | Compare two fractions. |
| Fraction | <= | Fraction | bool | Compare two fractions. |
| Fraction | * | Fraction | Fraction | Multiply two fractions. The result is not necessarily in reduced form, as that may be a very slow operation. |
| Fraction | - | Fraction | Fraction | Subtract two fractions. The result is not necessarily in reduced form, as that may be a very slow operation. |