summaryrefslogtreecommitdiffstats
path: root/vendor/libm/src/math/round.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/libm/src/math/round.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/libm/src/math/round.rs')
-rw-r--r--vendor/libm/src/math/round.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/libm/src/math/round.rs b/vendor/libm/src/math/round.rs
new file mode 100644
index 000000000..9a9723cfb
--- /dev/null
+++ b/vendor/libm/src/math/round.rs
@@ -0,0 +1,37 @@
+use core::f64;
+
+const TOINT: f64 = 1.0 / f64::EPSILON;
+
+#[inline]
+#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
+pub fn round(mut x: f64) -> f64 {
+ let (f, i) = (x, x.to_bits());
+ let e: u64 = i >> 52 & 0x7ff;
+ let mut y: f64;
+
+ if e >= 0x3ff + 52 {
+ return x;
+ }
+ if i >> 63 != 0 {
+ x = -x;
+ }
+ if e < 0x3ff - 1 {
+ // raise inexact if x!=0
+ force_eval!(x + TOINT);
+ return 0.0 * f;
+ }
+ y = x + TOINT - TOINT - x;
+ if y > 0.5 {
+ y = y + x - 1.0;
+ } else if y <= -0.5 {
+ y = y + x + 1.0;
+ } else {
+ y = y + x;
+ }
+
+ if i >> 63 != 0 {
+ -y
+ } else {
+ y
+ }
+}