Function rationalize::float2ratio

source ·
pub fn float2ratio<const N: usize>(n: f64, min: f64) -> Ratio<isize>
Expand description

Convert a float to a rational number


  • n: The float to convert
  • min: Numbers less than this value are treated as zero

returns: Ratio


use num::rational::Ratio;
use rationalize::float2ratio;
let cfe = float2ratio::<4>(std::f64::consts::PI, 1e-10);
assert_eq!(cfe, Ratio::new(355, 113));