Released v0.2.0 of the Fractions unit

What I hope is the last v0.x release of my Fractions unit has just been released. If all is well v1.0 should finally be out in May 25, just 12 years after it first appeared.

This unit provides an advanced record, TFraction, that encapsulates an immutable fraction and a whole bunch of methods for manipulating them. There are also a lot of operator overloads that make it easy to perform arithmetic and comparisons. You can cast from integers and to and from floating point values.

TFraction is well documented online if you want to check out what operations it supports.

Finally there are comprehensive DUnit tests for every method and operator.

⮞ Get it here.

Here's the properties, methods & operators (with various directives deleted):

property Numerator: Int64;
property Denominator: Int64;
property WholeNumberPart: Int64;
property FractionalPart: TFraction;
function IsProper: Boolean;
function IsWholeNumber: Boolean;
function Sign: TValueSign;
function CompareTo(const F: TFraction): TValueRelationship;
function Convert(const Multiplier: Int64): TFraction;
function HasCommonFactor(const Factor: Int64): Boolean;
function Simplify: TFraction;
function Simplify(const CommonFactor: Int64): TFraction;
function Reciprocal: TFraction;
function TruncateToMultiple(const F: TFraction): TFraction;
function RoundToMultiple(const F: TFraction): TFraction;
class function LCD(const A, B: TFraction): Int64;
class function Compare(const A, B: TFraction): TValueRelationship; 
class function Max(const A, B: TFraction): TFraction;
class function Max(const FA: array of TFraction): TFraction;
class function Min(const A, B: TFraction): TFraction;
class function Min(const FA: array of TFraction): TFraction;
class function Power(const F: TFraction; Exponent: ShortInt): TFraction; 
function Power(const Exponent: ShortInt): TFraction;
class function Abs(const F: TFraction): TFraction;
function Abs: TFraction;
function Hash: Integer;
class operator Implicit(const I: Integer): TFraction;
class operator Implicit(const F: TFraction): Extended;
class operator Implicit(const E: Extended): TFraction;
class operator Equal(const A, B: TFraction): Boolean;
class operator NotEqual(const A, B: TFraction): Boolean;
class operator LessThan(const A, B: TFraction): Boolean;
class operator LessThanOrEqual(const A, B: TFraction): Boolean;
class operator GreaterThan(const A, B: TFraction): Boolean;
class operator GreaterThanOrEqual(const A, B: TFraction): Boolean;
class operator Negative(const F: TFraction): TFraction;
class operator Positive(const F: TFraction): TFraction;
class operator Trunc(const F: TFraction): Int64;
class operator Round(const F: TFraction): Int64;
class operator Add(const A, B: TFraction): TFraction;
class operator Subtract(const A, B: TFraction): TFraction;
class operator Multiply(const A, B: TFraction): TFraction;
class operator Divide(const A, B: TFraction): TFraction;
class operator IntDivide(const A, B: TFraction): Int64;
class operator Modulus(const A, B: TFraction): TFraction;

and, conditionally compiled for Delphi 10.4 and later:

class operator Initialize(out Dest: TFraction);



Comments

Popular posts from this blog

Initialising dynamic arrays

Deleting elements from a dynamic array