Skip to main content

op_frac

Function op_frac 

Source
pub fn op_frac(value: FloatType) -> Result<OffsetQL>
Expand description

music21’s opFrac for a float: the float itself where its exact fraction has a denominator up to DENOM_LIMIT, and otherwise the nearest fraction within the limit, written as a float again where its denominator is a power of two.

It is what keeps three triplet eighths summing to exactly one beat.

use music21::common::numbertools::{op_frac, OffsetQL};

assert_eq!(op_frac(0.25)?, OffsetQL::Float(0.25));
assert_eq!(
    op_frac(1.0 / 3.0)?,
    OffsetQL::Fraction { numerator: 1, denominator: 3 }
);
assert_eq!(op_frac(0.99999999842)?, OffsetQL::Float(1.0));

§Errors

A value that is not finite, which has no fraction.