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.
|The fraction’s numerator.
|The fraction’s denominator.
|The whole number part of the fraction when considered as a mixed fraction.
|The fractional part of the fraction when considered as a mixed fraction.
The operators are overloaded by the record
|Enables a TFraction record to be cast / assigned from integer and floating point types and to floating point types (not integers).
|Enables two TFraction records to be compared for equality using the
|Enables two TFraction records to be compared for inequality using the
|Enables two TFraction records to be compared using the less-than (
|Enables two TFraction records to be compared using the less-than-or-equal (
|Enables two TFraction records to be compared using the greater-than (
|Enables two TFraction records to be compared using the greater-than-or-equal (
|Enables the unary minus operator to be used to negate a TFraction record.
|Enables the unary plus operator to be applied to a TFraction record.
|Enables the addition operator (
+) to be used to add two TFraction records.
|Enables the subtraction operator (
-) to be used to subtract two TFraction records.
|Enables the multiplication operator (
*) to be used to multiple two TFraction records.
|Enables the division operator (
/) to be used to divide to TFraction records.
|Enables the integer division operator (
div) to be used to divide two integers giving an integer result.
|Enables the modulus operator (
mod) to be used to get the fractional remainder after dividing one TFraction record by another.
Round operator to round a TFraction record to the nearest whole number value.
Trunc operator to truncate a TFraction record to the nearest whole number in the direction of zero.
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.
|Constructs a TFraction instance from a given numerator and denominator.
|Compares the fraction to another and returns a value indicating which fraction is greatest or if they are equal.
|Converts the fraction into an equivalent one in which the numerator and denominator are a given integer multiple of their original values.
|Checks if a given integer is a common factor of the fraction.
|Checks if the fraction is a proper fraction.
|Checks if the fraction represents a whole number.
|Returns the reciprocal of the fraction.
|Rounds the fraction to the nearest whole number multiple of another fraction.
|Returns a value representing the sign of the fraction.
|Two overloaded methods that reduce the fraction either to its common terms or by a given common factor.
|Truncates the fraction to a whole number multiple of another fraction.
|Returns the absolute value of a given fraction.
|Compares two fractions and returns a value indicating which of the two is greater or if they equal.
|Computes the least common denominator of two fractions.
|Overloaded methods that find the largest of two or more fractions.
|Overloaded methods that find the smallest of two or more fractions.
|Computes an integer power of a fraction.