Skip to main content

float_split

Function float_split 

Source
pub fn float_split(x: f64) -> (f64, f64)
Expand description

(modf) Splits a floating-point number into an integer and a fractional part

Returns (integer, fractional) where:

integer + fractional = x

§Notes

  • This function is also known as modf in C/C++ and Go
  • Both integer and fractional values will have the same sign as x

§Special cases

  • float_split(±Inf) = ±Inf, NaN
  • float_split(NaN) = NaN, NaN

§Examples

use russell_lab::math;

let (integer, fractional) = math::float_split(3.141593);
assert_eq!(
    format!("integer = {:?}, fractional = {:.6}", integer, fractional),
    "integer = 3.0, fractional = 0.141593"
);