UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

79 lines (78 loc) 3.11 kB
/** Represents a mixed fraction. */ export type MixedFraction = { whole: number; remainder: Fraction; }; /** * Represents the sign of a fraction. * * 0, -0, +0 have a sign of '/'. */ export type FractionSign = '+' | '-' | '/'; /** * Represents a mathematical fraction with a numerator and a denominator. * * The `Fraction` class provides methods for basic arithmetic operations such as addition, subtraction, multiplication, * and division, as well as utility methods for comparing, simplifying, and converting fractions. */ export declare class Fraction { readonly numerator: number; readonly denominator: number; constructor(numerator: number, denominator?: number); /** Creates a 0 fraction. */ static zero(): Fraction; /** Creates the maximum fraction. */ static max(): Fraction; /** * Creates a fraction from a decimal number. * * NOTE: Integers work too. */ static fromDecimal(decimal: number): Fraction; /** Creates a fraction from a mixed fraction. */ static fromMixed(mixed: MixedFraction): Fraction; /** Creates a fraction from something that appears to be a fraction. */ static fromFractionLike(fractionLike: { numerator: number; denominator: number; }): Fraction; /** Returns the sum of the fractions. */ static sum(...fractions: Fraction[]): Fraction; /** Returns the decimal of the fraction. */ toDecimal(): number; /** Returns the fraction in mixed form. */ toMixed(): MixedFraction; /** Returns the sign of the fraction. */ sign(): FractionSign; /** Returns whether the other fraction is equal to this fraction. */ isEquivalent(value: Fraction): boolean; /** Returns whether the other fraction has the exact same numerator and denominator. */ isEqual(value: Fraction): boolean; /** Returns whether this fraction is less than the other. */ isLessThan(value: Fraction): boolean; /** Returns whether this fraction is less than or _equivalent_ to the other. */ isLessThanOrEqualTo(value: Fraction): boolean; /** Returns whether this fraction is greater than the other. */ isGreaterThan(value: Fraction): boolean; /** Returns whether this fraction is greater than or _equivalent_ to the other. */ isGreaterThanOrEqualTo(value: Fraction): boolean; /** Reduces the numerator and denominator to its lowest common factor. */ simplify(): Fraction; /** Returns the sum as a new fraction. */ add(value: Fraction): Fraction; /** Returns the difference as a new fraction. */ subtract(value: Fraction): Fraction; /** Returns the product as a new fraction. */ multiply(value: Fraction): Fraction; /** Returns the quotient as a new fraction. */ divide(value: Fraction): Fraction; /** Returns the reciprocal a new fraction. */ reciprocate(): Fraction; /** Returns a fraction-like POJO representing the fraction. */ toFractionLike(): { numerator: number; denominator: number; }; /** Returns the greatest common denominator. */ private gcd; }