1/// Rounds the number toward 0 to the closest integral value (f16).
2///
3/// This effectively removes the decimal part of the number, leaving the integral part.
4#[cfg(f16_enabled)]
5#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6pub fn truncf16(x: f16) -> f16 {
7super::generic::trunc(x)
8}
910/// Rounds the number toward 0 to the closest integral value (f32).
11///
12/// This effectively removes the decimal part of the number, leaving the integral part.
13#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
14pub fn truncf(x: f32) -> f32 {
15select_implementation! {
16 name: truncf,
17 use_arch: all(target_arch = "wasm32", intrinsics_enabled),
18 args: x,
19 }
2021super::generic::trunc(x)
22}
2324/// Rounds the number toward 0 to the closest integral value (f64).
25///
26/// This effectively removes the decimal part of the number, leaving the integral part.
27#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
28pub fn trunc(x: f64) -> f64 {
29select_implementation! {
30 name: trunc,
31 use_arch: all(target_arch = "wasm32", intrinsics_enabled),
32 args: x,
33 }
3435super::generic::trunc(x)
36}
3738/// Rounds the number toward 0 to the closest integral value (f128).
39///
40/// This effectively removes the decimal part of the number, leaving the integral part.
41#[cfg(f128_enabled)]
42#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
43pub fn truncf128(x: f128) -> f128 {
44super::generic::trunc(x)
45}
4647#[cfg(test)]
48mod tests {
49#[test]
50fn sanity_check() {
51assert_eq!(super::truncf(1.1), 1.0);
52 }
53}