Skip to main content

float_ratio

Function float_ratio 

Source
pub fn float_ratio(value: FloatType) -> Option<(BigInt, BigInt)>
Expand description

The exact fraction a float stands for, in lowest terms, as Python’s float.as_integer_ratio gives it.

use music21::common::numbertools::float_ratio;
use num::BigInt;

assert_eq!(float_ratio(0.75), Some((BigInt::from(3), BigInt::from(4))));
assert_eq!(float_ratio(f64::NAN), None);