Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Fraction

A class representing mathematical fractions, which have a numerator and a denominator.

Hierarchy

  • Fraction

Index

Constructors

constructor

  • new Fraction(numerator?: number, denominator?: number, wholeValue?: number, simplify?: boolean): Fraction
  • Parameters

    • Default value numerator: number = 0
    • Default value denominator: number = 1
    • Default value wholeValue: number = 0

      the integer number, needed for values greater than 1

    • Default value simplify: boolean = true

      If simplify is true, then the fraction is simplified to make both the numerator and denominator coprime, and less than maximumAllowedNumber.

    Returns Fraction

Properties

Private denominator

denominator: number = 1

Private numerator

numerator: number = 0

Private realValue

realValue: number

Private wholeValue

wholeValue: number = 0

Static FloatInaccuracyTolerance

FloatInaccuracyTolerance: number = 0.0001

Static Private maximumAllowedNumber

maximumAllowedNumber: number = 46340

Accessors

Denominator

  • get Denominator(): number
  • set Denominator(value: number): void

Numerator

  • get Numerator(): number
  • set Numerator(value: number): void

RealValue

  • get RealValue(): number

WholeValue

  • get WholeValue(): number
  • set WholeValue(value: number): void

Methods

Add

  • Adds a Fraction to this Fraction. Attention: This changes the already existing Fraction, which might be referenced elsewhere! Use Fraction.plus() for creating a new Fraction object being the sum of two Fractions.

    Parameters

    • fraction: Fraction

      the Fraction to add.

    Returns void

CompareTo

Equals

GetExpandedNumerator

  • GetExpandedNumerator(): number
  • Returns the unified numerator where the whole value will be expanded with the denominator and added to the existing numerator.

    Returns number

IsNegative

  • IsNegative(): boolean

Quantize

  • Quantize(maxAllowedDenominator: number): Fraction
  • Brute Force quanization by searching incremental with the numerator until the denominator is smaller/equal than the desired one.

    Parameters

    • maxAllowedDenominator: number

    Returns Fraction

Sub

  • Subtracts a Fraction from this Fraction. Attention: This changes the already existing Fraction, which might be referenced elsewhere! Use Fraction.minus() for creating a new Fraction object being the difference of two Fractions.

    Parameters

    • fraction: Fraction

      the Fraction to subtract.

    Returns void

clone

distanceFromBeat

  • distanceFromBeat(timeSignature: Fraction): number

expand

  • expand(expansionValue: number): void

gt

gte

isOnBeat

  • isOnBeat(timeSignature: Fraction): boolean

lt

lte

Private setRealValue

  • setRealValue(): void

Private simplify

  • simplify(): void

toString

  • toString(): string

Static Equal

Static createFromFraction

Static Private greatestCommonDenominator

  • greatestCommonDenominator(a: number, b: number): number

Static max

Static minus

Static multiply

Static plus

Generated using TypeDoc