From 7a32a99352cc6001c24c8bff0885c0d0cb937678 Mon Sep 17 00:00:00 2001 From: "Mark S. Baranowski" Date: Tue, 31 Oct 2023 15:59:56 -0600 Subject: [PATCH] This updates the exponent calculations done in the nextafter functions related to detecting underflow/overflow. The functions now match the behavior of the MUSL implementations these were based on. Fixes rust-lang/libm#286 --- library/compiler-builtins/libm/src/math/nextafter.rs | 2 +- library/compiler-builtins/libm/src/math/nextafterf.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/compiler-builtins/libm/src/math/nextafter.rs b/library/compiler-builtins/libm/src/math/nextafter.rs index 13094a17c34b..05762619109a 100644 --- a/library/compiler-builtins/libm/src/math/nextafter.rs +++ b/library/compiler-builtins/libm/src/math/nextafter.rs @@ -23,7 +23,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 { ux_i += 1; } - let e = ux_i.wrapping_shr(52 & 0x7ff); + let e = ux_i >> 52 & 0x7ff; // raise overflow if ux.f is infinite and x is finite if e == 0x7ff { force_eval!(x + x); diff --git a/library/compiler-builtins/libm/src/math/nextafterf.rs b/library/compiler-builtins/libm/src/math/nextafterf.rs index df9b1082978a..8ba3833562fb 100644 --- a/library/compiler-builtins/libm/src/math/nextafterf.rs +++ b/library/compiler-builtins/libm/src/math/nextafterf.rs @@ -23,7 +23,7 @@ pub fn nextafterf(x: f32, y: f32) -> f32 { ux_i += 1; } - let e = ux_i.wrapping_shr(0x7f80_0000_u32); + let e = ux_i & 0x7f80_0000_u32; // raise overflow if ux_f is infinite and x is finite if e == 0x7f80_0000_u32 { force_eval!(x + x);