]> git.proxmox.com Git - rustc.git/blob - vendor/compiler_builtins/libm/src/math/round.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / vendor / compiler_builtins / libm / src / math / round.rs
1 use core::f64;
2
3 const TOINT: f64 = 1.0 / f64::EPSILON;
4
5 #[inline]
6 pub fn round(mut x: f64) -> f64 {
7 let (f, i) = (x, x.to_bits());
8 let e: u64 = i >> 52 & 0x7ff;
9 let mut y: f64;
10
11 if e >= 0x3ff + 52 {
12 return x;
13 }
14 if i >> 63 != 0 {
15 x = -x;
16 }
17 if e < 0x3ff - 1 {
18 // raise inexact if x!=0
19 force_eval!(x + TOINT);
20 return 0.0 * f;
21 }
22 y = x + TOINT - TOINT - x;
23 if y > 0.5 {
24 y = y + x - 1.0;
25 } else if y <= -0.5 {
26 y = y + x + 1.0;
27 } else {
28 y = y + x;
29 }
30
31 if i >> 63 != 0 {
32 -y
33 } else {
34 y
35 }
36 }