How can I convert a f64 to f32 and get the closest approximation and the next greater or smaller value?
问题 Possible pseudocode for the operation could be: fn f32_greater(x: f64) -> f32 { let mut y = x as f32; //I get closest while f64::from(y) < x { y = nextafter(y, f32::INFINITY); } y } fn f32_smaller(x: f64) -> f32 { let mut y = x as f32; //I get closest while f64::from(y) > x { y = nextafter(y, f32::NEG_INFINITY); } y } I can not find an equivalent to C11's nextafter function in the libc crate or in the methods on f64 For context, I have an R-tree index using f32 . I want to search the region