Skip to main content

truncate

Function truncate 

Source
pub fn truncate(v: f32) -> i32
Expand description

(int)v as the compiler writes it, with cvttss2si: it rounds towards zero, and a NaN or a value outside the i32 range gives i32::MIN. Rust’s v as i32 gives 0 for a NaN and the nearest limit for a value out of range, so ported code that converts a float the game could leave NaN uses this.

use unbanished_core::crt::truncate;

assert_eq!(truncate(-2.7), -2);
assert_eq!(truncate(f32::NAN), i32::MIN);
assert_eq!(truncate(3e9), i32::MIN);