compiler_builtins/math/libm_math/
rint.rs

1use super::support::Round;
2
3/// Round `x` to the nearest integer, breaking ties toward even.
4#[cfg(f16_enabled)]
5#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6pub fn rintf16(x: f16) -> f16 {
7    select_implementation! {
8        name: rintf16,
9        use_arch: all(target_arch = "aarch64", target_feature = "fp16"),
10        args: x,
11    }
12
13    super::generic::rint_round(x, Round::Nearest).val
14}
15
16/// Round `x` to the nearest integer, breaking ties toward even.
17#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
18pub fn rintf(x: f32) -> f32 {
19    select_implementation! {
20        name: rintf,
21        use_arch: any(
22            all(target_arch = "aarch64", target_feature = "neon"),
23            all(target_arch = "wasm32", intrinsics_enabled),
24        ),
25        args: x,
26    }
27
28    super::generic::rint_round(x, Round::Nearest).val
29}
30
31/// Round `x` to the nearest integer, breaking ties toward even.
32#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
33pub fn rint(x: f64) -> f64 {
34    select_implementation! {
35        name: rint,
36        use_arch: any(
37            all(target_arch = "aarch64", target_feature = "neon"),
38            all(target_arch = "wasm32", intrinsics_enabled),
39        ),
40        args: x,
41    }
42
43    super::generic::rint_round(x, Round::Nearest).val
44}
45
46/// Round `x` to the nearest integer, breaking ties toward even.
47#[cfg(f128_enabled)]
48#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
49pub fn rintf128(x: f128) -> f128 {
50    super::generic::rint_round(x, Round::Nearest).val
51}