Function fract

Source
pub fn fract(x: f32) -> f32
🔬This is a nightly-only experimental API. (core_float_math)
Expand description

Experimental version of fract in core. See f32::fract for details.

§Examples

#![feature(core_float_math)]

use core::f32;

let x = 3.6_f32;
let y = -3.6_f32;
let abs_difference_x = (f32::fract(x) - 0.6).abs();
let abs_difference_y = (f32::fract(y) - (-0.6)).abs();

assert!(abs_difference_x <= f32::EPSILON);
assert!(abs_difference_y <= f32::EPSILON);

This standalone function is for testing only. It will be stabilized as an inherent method.