compiler_builtins/math/libm_math/
roundeven.rs

1use super::support::{Float, Round};
2
3/// Round `x` to the nearest integer, breaking ties toward even. This is IEEE 754
4/// `roundToIntegralTiesToEven`.
5#[cfg(f16_enabled)]
6#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
7pub fn roundevenf16(x: f16) -> f16 {
8    roundeven_impl(x)
9}
10
11/// Round `x` to the nearest integer, breaking ties toward even. This is IEEE 754
12/// `roundToIntegralTiesToEven`.
13#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
14pub fn roundevenf(x: f32) -> f32 {
15    roundeven_impl(x)
16}
17
18/// Round `x` to the nearest integer, breaking ties toward even. This is IEEE 754
19/// `roundToIntegralTiesToEven`.
20#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
21pub fn roundeven(x: f64) -> f64 {
22    roundeven_impl(x)
23}
24
25/// Round `x` to the nearest integer, breaking ties toward even. This is IEEE 754
26/// `roundToIntegralTiesToEven`.
27#[cfg(f128_enabled)]
28#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
29pub fn roundevenf128(x: f128) -> f128 {
30    roundeven_impl(x)
31}
32
33#[inline]
34pub fn roundeven_impl<F: Float>(x: F) -> F {
35    super::generic::rint_round(x, Round::Nearest).val
36}