Skip to main content

rational_to_f64_nearest

Function rational_to_f64_nearest 

Source
pub fn rational_to_f64_nearest(r: &Rational) -> f64
Expand description

The f64 nearest to r (ties to even), rounded once from the exact value: the binary exponent comes from the bit lengths, the quotient is scaled to 53 significant bits (or onto the 2^-1074 grid below the normal range), and the remainder decides the rounding. Past the largest finite float it is the signed infinity. Unlike Rational::to_f64, which divides two rounded doubles, this never rounds twice.