Table of Contents

Struct Fraction

Namespace
Sigil.Sound
Assembly
Sigil.Sound.Notes.dll

An exact fraction of a cycle. Pattern time is rational so that Fast(3) followed by Slow(3) lands exactly where it started and a loop does not drift after hours, as floating-point beats would.

public readonly struct Fraction : IEquatable<Fraction>, IComparable<Fraction>

Implements

Inherited Members

Constructors

Fraction(long, long)

Creates numerator / denominator in lowest terms.

public Fraction(long numerator, long denominator = 1)

Parameters

numerator long
denominator long

Exceptions

DivideByZeroException

The denominator is zero.

Properties

Denominator

The denominator, in lowest terms; always positive.

public long Denominator { get; }

Property Value

long

Numerator

The numerator, in lowest terms.

public long Numerator { get; }

Property Value

long

One

One.

public static Fraction One { get; }

Property Value

Fraction

Zero

Zero.

public static Fraction Zero { get; }

Property Value

Fraction

Methods

CompareTo(Fraction)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(Fraction other)

Parameters

other Fraction

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

Equals(Fraction)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Fraction other)

Parameters

other Fraction

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object?

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Floor()

The largest whole number not above this fraction.

public long Floor()

Returns

long

FromDouble(double)

The nearest simple fraction to value (denominator up to 100000), by continued fractions.

public static Fraction FromDouble(double value)

Parameters

value double

Returns

Fraction

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Max(Fraction, Fraction)

The larger of two fractions.

public static Fraction Max(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Min(Fraction, Fraction)

The smaller of two fractions.

public static Fraction Min(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Reciprocal()

One divided by this fraction.

public Fraction Reciprocal()

Returns

Fraction

Exceptions

DivideByZeroException

The fraction is zero.

ToDouble()

The fraction as a floating-point number.

public double ToDouble()

Returns

double

ToString()

The fraction in lowest terms: 3 for a whole number, 3/4 otherwise.

public override string ToString()

Returns

string

Operators

operator +(Fraction, Fraction)

The exact sum.

public static Fraction operator +(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Exceptions

OverflowException

The result does not fit.

operator /(Fraction, Fraction)

The exact quotient.

public static Fraction operator /(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Exceptions

DivideByZeroException

The divisor is zero.

OverflowException

The result does not fit.

operator ==(Fraction, Fraction)

True when both are the same value, in any form (2/4 equals 1/2).

public static bool operator ==(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

explicit operator Fraction(double)

The nearest simple fraction; see Sigil.Sound.Fraction.FromDouble(System.Double).

public static explicit operator Fraction(double value)

Parameters

value double

Returns

Fraction

explicit operator double(Fraction)

The fraction as a floating-point number.

public static explicit operator double(Fraction value)

Parameters

value Fraction

Returns

double

operator >(Fraction, Fraction)

True when a is greater than b.

public static bool operator >(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

operator >=(Fraction, Fraction)

True when a is greater than or equal to b.

public static bool operator >=(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

implicit operator Fraction(int)

A whole number as a fraction.

public static implicit operator Fraction(int value)

Parameters

value int

Returns

Fraction

implicit operator Fraction(long)

A whole number as a fraction.

public static implicit operator Fraction(long value)

Parameters

value long

Returns

Fraction

operator !=(Fraction, Fraction)

True when the values differ.

public static bool operator !=(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

operator <(Fraction, Fraction)

True when a is less than b.

public static bool operator <(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

operator <=(Fraction, Fraction)

True when a is less than or equal to b.

public static bool operator <=(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

bool

operator *(Fraction, Fraction)

The exact product.

public static Fraction operator *(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Exceptions

OverflowException

The result does not fit.

operator -(Fraction, Fraction)

The exact difference.

public static Fraction operator -(Fraction a, Fraction b)

Parameters

a Fraction
b Fraction

Returns

Fraction

Exceptions

OverflowException

The result does not fit.

operator -(Fraction)

The negated fraction.

public static Fraction operator -(Fraction a)

Parameters

a Fraction

Returns

Fraction