Skip to main content

round_to_half_integer

Function round_to_half_integer 

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

A number rounded to the nearest half, a quarter rounding up, as music21’s roundToHalfInteger does: a whole number where it lands on one, and a float on a half.

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

assert_eq!(round_to_half_integer(1.35)?, IntOrFloat::Float(1.5));
assert_eq!(round_to_half_integer(1.75)?, IntOrFloat::Int(2.into()));
assert_eq!(round_to_half_integer(-0.25)?, IntOrFloat::Int(0.into()));

§Errors

A value that is not finite.