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 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 TruncateToMultiple(const F: TFraction): TFraction;
function RoundToMultiple(const F: TFraction): TFraction;
class function LCD(const A, B: TFraction): Int64;
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 Modulus(const A, B: TFraction): TFraction;
and, conditionally compiled for Delphi 10.4 and later:
Comments
Post a Comment
Comments are very welcome, but please don't comment here if:
1) You have a query about, or a bug report for, one of my programs or libraries. Most of my posts contain a link to the relevant repository where there will be an issue tracker you can use.
2) You have a query about any 3rd party programs I feature, please address them to the developer(s) - there will be a link in the post.
3) You're one of the tiny, tiny minority who are aggressive or abusive - in the bin you go and reported you will be!
Thanks