This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.
Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.
Applies to: ~>0.1
TFraction is an advanced “record with methods” encapsulates a vulgar fraction and defines various mathematical operations on it.
The record is immutable, i.e. its properties are read-only and are never modified by any operations on the record. Any methods that manipulate a fraction always return a new record instance containing the result of the manipulation.
A variable of type TFraction can be instantiated by passing the numerator and denominator to the record’s constructor. The fraction is normalised by the constructor, so that the denominator is always positive and the numerator takes the sign.
Furthermore a TFraction variable can be instantiated by assigning a variable of a valid type to it. Supported types are:
The following read-only properties are exposed.
|Numerator||The fraction’s numerator.|
|Denominator||The fraction’s denominator.|
|WholeNumberPart||The whole number part of the fraction when considered as a mixed fraction.|
|FractionalPart||The fractional part of the fraction when considered as a mixed fraction.|
The operators are overloaded by the record
|Implicit||Enables a TFraction record to be cast / assigned from integer and floating point types and to floating point types (not integers).|
|Equal||Enables two TFraction records to be compared for equality using the
|NotEqual||Enables two TFraction records to be compared for inequality using the
|LessThan||Enables two TFraction records to be compared using the less-than (
|LessThanOrEqual||Enables two TFraction records to be compared using the less-than-or-equal (
|GreaterThan||Enables two TFraction records to be compared using the greater-than (
|GreaterThanOrEqual||Enables two TFraction records to be compared using the greater-than-or-equal (
|Negative||Enables the unary minus operator to be used to negate a TFraction record.|
|Positive||Enables the unary plus operator to be applied to a TFraction record.|
|Add||Enables the addition operator (
|Subtract||Enables the subtraction operator (
|Multiply||Enables the multiplication operator (
|Divide||Enables the division operator (
|IntDivide||Enables the integer division operator (
|Modulus||Enables the modulus operator (
TFraction defines several methods. Some are static class methods that operate on fractions passed as parameters while others are instance methods that operate on the current record. There is also a single constructor.
|Create||Constructs a TFraction instance from a given numerator and denominator.|
|CompareTo||Compares the fraction to another and returns a value indicating which fraction is greatest or if they are equal.|
|Convert||Converts the fraction into an equivalent one in which the numerator and denominator are a given integer multiple of their original values.|
|HasCommonFactor||Checks if a given integer is a common factor of the fraction.|
|IsProper||Checks if the fraction is a proper fraction.|
|IsWholeNumber||Checks if the fraction represents a whole number.|
|Reciprocal||Returns the reciprocal of the fraction.|
|RoundToMultiple||Rounds the fraction to the nearest whole number multiple of another fraction.|
|Sign||Returns a value representing the sign of the fraction.|
|Simplify||Two overloaded methods that reduce the fraction either to its common terms or by a given common factor.|
|TruncateToMultiple||Truncates the fraction to a whole number multiple of another fraction.|
|Abs||Returns the absolute value of a given fraction.|
|Compare||Compares two fractions and returns a value indicating which of the two is greater or if they equal.|
|LCD||Computes the least common denominator of two fractions.|
|Max||Overloaded methods that find the largest of two or more fractions.|
|Min||Overloaded methods that find the smallest of two or more fractions.|
|Power||Computes an integer power of a fraction.|