3 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4 pub fn truncf(x
: f32) -> f32 {
5 // On wasm32 we know that LLVM's intrinsic will compile to an optimized
6 // `f32.trunc` native instruction, so we can leverage this for both code size
8 llvm_intrinsically_optimized
! {
9 #[cfg(target_arch = "wasm32")] {
10 return unsafe { ::core::intrinsics::truncf32(x) }
13 let x1p120
= f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120
15 let mut i
: u32 = x
.to_bits();
16 let mut e
: i32 = (i
>> 23 & 0xff) as i32 - 0x7f + 9;
25 m
= -1i32 as u32 >> e
;
29 force_eval
!(x
+ x1p120
);
38 assert_eq
!(super::truncf(1.1), 1.0);