Skip to main content

approximate_gcd

Function approximate_gcd 

Source
pub fn approximate_gcd(
    values: &[FloatType],
    grain: FloatType,
) -> Result<FloatType>
Expand description

The greatest length that goes a whole number of times, to within grain, into every one of values: music21’s approximateGCD, which tries the smallest value, then each value divided by one to sixteen.

use music21::common::numbertools::approximate_gcd;

assert_eq!(approximate_gcd(&[2.5, 10.0, 0.25], 1e-4)?, 0.25);
assert_eq!(approximate_gcd(&[1.5, 5.0, 2.0, 7.0], 1e-4)?, 0.5);

§Errors

No values, or no length that goes into them all. The smallest value being nought gives no finite answer.