I'm surprised that no one has mentioned a need for inverting a fraction to get its reciprocal. I use it often to convert a frequency (x / 1 second) to the duration of one cycle of that frequency (1 / x).
{$ModeSwitch AdvancedRecords}
{$ModeSwitch TypeHelpers}
interface
type
f32 = Single; i32 = LongInt; i64 = Int64; int = i32;
f64 = Double; u32 = LongWord; u64 = QWord; uint = u32;
TFractionHelper = type helper for TFraction
{ procedure InterlockedInvert; inline;}
procedure Invert; inline;
end;
implementation
{procedure TFractionHelper.InterlockedInvert;
begin
InterlockedExchange64(FNumerator, FDenominator); // fails because a type helper can only access public variables
end;}
procedure TFractionHelper.Invert; // not thread-safe
var
i : i64;
begin
tmp := Numerator;
Numerator := Denominator;
Denominator := i;
end;