From 62e2506745ccb6555f67e95dcdddb02fc9cd76a8 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Thu, 9 May 2019 18:40:19 +0300 Subject: [PATCH] fix jn, ilogb --- build.rs | 4 +--- src/math/ilogb.rs | 14 +++++++------- src/math/ilogbf.rs | 14 +++++++------- src/math/jn.rs | 4 ++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index bf28fe2..9af6dec 100644 --- a/build.rs +++ b/build.rs @@ -26,9 +26,7 @@ mod musl_reference_tests { // These files are all internal functions or otherwise miscellaneous, not // defining a function we want to test. - const IGNORED_FILES: &[&str] = &[ - "fenv.rs", - ]; + const IGNORED_FILES: &[&str] = &["fenv.rs"]; struct Function { name: String, diff --git a/src/math/ilogb.rs b/src/math/ilogb.rs index 8a1289c..0a380b7 100644 --- a/src/math/ilogb.rs +++ b/src/math/ilogb.rs @@ -1,4 +1,4 @@ -const FP_ILOGBNAN: i32 = -1 - ((!0) >> 1); +const FP_ILOGBNAN: i32 = -1 - 0x7fffffff; const FP_ILOGB0: i32 = FP_ILOGBNAN; pub fn ilogb(x: f64) -> i32 { @@ -17,15 +17,15 @@ pub fn ilogb(x: f64) -> i32 { e -= 1; i <<= 1; } - return e; - } - if e == 0x7ff { + e + } else if e == 0x7ff { force_eval!(0.0 / 0.0); if (i << 12) != 0 { - return FP_ILOGBNAN; + FP_ILOGBNAN } else { - return i32::max_value(); + i32::max_value() } + } else { + e - 0x3ff } - return e - 0x3ff; } diff --git a/src/math/ilogbf.rs b/src/math/ilogbf.rs index 1bf4670..b384fa4 100644 --- a/src/math/ilogbf.rs +++ b/src/math/ilogbf.rs @@ -1,4 +1,4 @@ -const FP_ILOGBNAN: i32 = -1 - ((!0) >> 1); +const FP_ILOGBNAN: i32 = -1 - 0x7fffffff; const FP_ILOGB0: i32 = FP_ILOGBNAN; pub fn ilogbf(x: f32) -> i32 { @@ -17,15 +17,15 @@ pub fn ilogbf(x: f32) -> i32 { e -= 1; i <<= 1; } - return e; - } - if e == 0xff { + e + } else if e == 0xff { force_eval!(0.0 / 0.0); if (i << 9) != 0 { - return FP_ILOGBNAN; + FP_ILOGBNAN } else { - return i32::max_value(); + i32::max_value() } + } else { + e - 0x7f } - return e - 0x7f; } diff --git a/src/math/jn.rs b/src/math/jn.rs index 70c9802..1be167f 100644 --- a/src/math/jn.rs +++ b/src/math/jn.rs @@ -54,7 +54,7 @@ pub fn jn(n: i32, mut x: f64) -> f64 { ix &= 0x7fffffff; // -lx == !lx + 1 - if (ix | (lx | (!lx + 1)) >> 31) > 0x7ff00000 { + if (ix | (lx | ((!lx).wrapping_add(1))) >> 31) > 0x7ff00000 { /* nan */ return x; } @@ -268,7 +268,7 @@ pub fn yn(n: i32, x: f64) -> f64 { ix &= 0x7fffffff; // -lx == !lx + 1 - if (ix | (lx | (!lx + 1)) >> 31) > 0x7ff00000 { + if (ix | (lx | ((!lx).wrapping_add(1))) >> 31) > 0x7ff00000 { /* nan */ return x; }