Skip to main content

nearest_multiple

Function nearest_multiple 

Source
pub fn nearest_multiple(
    value: FloatType,
    unit: FloatType,
) -> Result<NearestMultiple>
Expand description

The multiple of unit nearest a value that is not negative, how far off it is and which way: music21’s nearestMultiple. Half way rounds down.

use music21::common::numbertools::nearest_multiple;

let found = nearest_multiple(0.4, 0.25)?;
assert_eq!(found.multiple, 0.5);
assert_eq!(found.signed_error, -0.1);

§Errors

A negative value, or one that falls between no two multiples.