Skip to main content

num_to_int_or_float

Function num_to_int_or_float 

Source
pub fn num_to_int_or_float(value: FloatType) -> Result<IntOrFloat>
Expand description

A value close enough to a whole number, within a millionth, as that whole number, and anything else as it is: music21’s numToIntOrFloat.

use music21::common::numbertools::{num_to_int_or_float, IntOrFloat};

assert_eq!(num_to_int_or_float(0.999999999)?, IntOrFloat::Int(1.into()));
assert_eq!(num_to_int_or_float(1.5)?, IntOrFloat::Float(1.5));

§Errors

A value that is not finite, which rounds to no whole number.