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
Exceptions
- DivideByZeroException
-
The denominator is zero.
Properties
Denominator
The denominator, in lowest terms; always positive.
public long Denominator { get; }Property Value
Numerator
The numerator, in lowest terms.
public long Numerator { get; }Property Value
One
One.
public static Fraction One { get; }Property Value
Zero
Zero.
public static Fraction Zero { get; }Property Value
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
otherFraction-
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 otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin 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
otherFraction-
An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)Parameters
objobject?-
The object to compare with the current instance.
Returns
- bool
-
true if
objand 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
FromDouble(double)
The nearest simple fraction to value (denominator up to 100000), by continued fractions.
public static Fraction FromDouble(double value)Parameters
valuedouble
Returns
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
Returns
Min(Fraction, Fraction)
The smaller of two fractions.
public static Fraction Min(Fraction a, Fraction b)Parameters
Returns
Reciprocal()
One divided by this fraction.
public Fraction Reciprocal()Returns
Exceptions
- DivideByZeroException
-
The fraction is zero.
ToDouble()
The fraction as a floating-point number.
public double ToDouble()Returns
ToString()
The fraction in lowest terms: 3 for a whole number, 3/4 otherwise.
public override string ToString()Returns
Operators
operator +(Fraction, Fraction)
The exact sum.
public static Fraction operator +(Fraction a, Fraction b)Parameters
Returns
Exceptions
- OverflowException
-
The result does not fit.
operator /(Fraction, Fraction)
The exact quotient.
public static Fraction operator /(Fraction a, Fraction b)Parameters
Returns
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
Returns
explicit operator Fraction(double)
The nearest simple fraction; see Sigil.Sound.Fraction.FromDouble(System.Double).
public static explicit operator Fraction(double value)Parameters
valuedouble
Returns
explicit operator double(Fraction)
The fraction as a floating-point number.
public static explicit operator double(Fraction value)Parameters
valueFraction
Returns
operator >(Fraction, Fraction)
True when a is greater than b.
public static bool operator >(Fraction a, Fraction b)Parameters
Returns
operator >=(Fraction, Fraction)
True when a is greater than or equal to b.
public static bool operator >=(Fraction a, Fraction b)Parameters
Returns
implicit operator Fraction(int)
A whole number as a fraction.
public static implicit operator Fraction(int value)Parameters
valueint
Returns
implicit operator Fraction(long)
A whole number as a fraction.
public static implicit operator Fraction(long value)Parameters
valuelong
Returns
operator !=(Fraction, Fraction)
True when the values differ.
public static bool operator !=(Fraction a, Fraction b)Parameters
Returns
operator <(Fraction, Fraction)
True when a is less than b.
public static bool operator <(Fraction a, Fraction b)Parameters
Returns
operator <=(Fraction, Fraction)
True when a is less than or equal to b.
public static bool operator <=(Fraction a, Fraction b)Parameters
Returns
operator *(Fraction, Fraction)
The exact product.
public static Fraction operator *(Fraction a, Fraction b)Parameters
Returns
Exceptions
- OverflowException
-
The result does not fit.
operator -(Fraction, Fraction)
The exact difference.
public static Fraction operator -(Fraction a, Fraction b)Parameters
Returns
Exceptions
- OverflowException
-
The result does not fit.
operator -(Fraction)
The negated fraction.
public static Fraction operator -(Fraction a)Parameters
aFraction