From ab0c8e84fb3b76136aa38b800a17c0f97fa469a7 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 26 Oct 2024 20:22:24 -0500 Subject: [PATCH] Run `cargo fmt` with new settings Apply the changes from the `.rustfmt.toml` file added in the previous commit. --- .../libm/crates/libm-test/build.rs | 43 ++++------------ library/compiler-builtins/libm/src/lib.rs | 15 ++---- .../compiler-builtins/libm/src/math/asin.rs | 6 +-- .../compiler-builtins/libm/src/math/asinf.rs | 6 +-- .../compiler-builtins/libm/src/math/asinh.rs | 6 +-- .../compiler-builtins/libm/src/math/asinhf.rs | 6 +-- .../compiler-builtins/libm/src/math/atan.rs | 12 ++--- .../compiler-builtins/libm/src/math/atan2.rs | 3 +- .../compiler-builtins/libm/src/math/atan2f.rs | 3 +- .../compiler-builtins/libm/src/math/atanf.rs | 15 ++---- .../compiler-builtins/libm/src/math/atanh.rs | 6 +-- .../compiler-builtins/libm/src/math/atanhf.rs | 6 +-- .../compiler-builtins/libm/src/math/ceil.rs | 15 ++---- .../compiler-builtins/libm/src/math/ceilf.rs | 3 +- .../compiler-builtins/libm/src/math/cosf.rs | 4 +- .../compiler-builtins/libm/src/math/cosh.rs | 4 +- .../compiler-builtins/libm/src/math/coshf.rs | 4 +- .../compiler-builtins/libm/src/math/erf.rs | 12 +---- .../compiler-builtins/libm/src/math/erff.rs | 12 +---- .../compiler-builtins/libm/src/math/exp.rs | 6 +-- .../compiler-builtins/libm/src/math/exp10f.rs | 5 +- .../compiler-builtins/libm/src/math/expf.rs | 6 +-- .../compiler-builtins/libm/src/math/expm1f.rs | 6 +-- .../compiler-builtins/libm/src/math/fabs.rs | 3 +- .../compiler-builtins/libm/src/math/fabsf.rs | 3 +- .../compiler-builtins/libm/src/math/floor.rs | 15 ++---- .../compiler-builtins/libm/src/math/floorf.rs | 3 +- .../compiler-builtins/libm/src/math/fma.rs | 10 +--- .../compiler-builtins/libm/src/math/fmaf.rs | 8 +-- .../compiler-builtins/libm/src/math/fmodf.rs | 3 +- .../compiler-builtins/libm/src/math/ilogb.rs | 6 +-- .../compiler-builtins/libm/src/math/ilogbf.rs | 6 +-- library/compiler-builtins/libm/src/math/jn.rs | 12 +---- .../compiler-builtins/libm/src/math/jnf.rs | 12 +---- .../compiler-builtins/libm/src/math/k_sin.rs | 6 +-- .../compiler-builtins/libm/src/math/log1p.rs | 6 +-- .../compiler-builtins/libm/src/math/log1pf.rs | 6 +-- .../compiler-builtins/libm/src/math/mod.rs | 32 +++++------- .../compiler-builtins/libm/src/math/pow.rs | 50 +++++-------------- .../compiler-builtins/libm/src/math/powf.rs | 12 +---- .../libm/src/math/rem_pio2.rs | 20 ++------ .../libm/src/math/rem_pio2_large.rs | 3 +- .../libm/src/math/rem_pio2f.rs | 4 +- .../compiler-builtins/libm/src/math/remquo.rs | 6 +-- .../libm/src/math/remquof.rs | 6 +-- .../compiler-builtins/libm/src/math/rint.rs | 10 +--- .../compiler-builtins/libm/src/math/rintf.rs | 10 +--- .../compiler-builtins/libm/src/math/round.rs | 4 +- .../compiler-builtins/libm/src/math/roundf.rs | 4 +- .../compiler-builtins/libm/src/math/sinf.rs | 16 ++---- .../compiler-builtins/libm/src/math/sinhf.rs | 3 +- .../compiler-builtins/libm/src/math/sqrt.rs | 3 +- .../compiler-builtins/libm/src/math/sqrtf.rs | 10 ++-- .../compiler-builtins/libm/src/math/tan.rs | 6 +-- .../compiler-builtins/libm/src/math/tanf.rs | 10 ++-- .../compiler-builtins/libm/src/math/tanh.rs | 6 +-- .../compiler-builtins/libm/src/math/tanhf.rs | 6 +-- 57 files changed, 131 insertions(+), 393 deletions(-) diff --git a/library/compiler-builtins/libm/crates/libm-test/build.rs b/library/compiler-builtins/libm/crates/libm-test/build.rs index 3a49e3c57315..9653bd830135 100644 --- a/library/compiler-builtins/libm/crates/libm-test/build.rs +++ b/library/compiler-builtins/libm/crates/libm-test/build.rs @@ -5,12 +5,12 @@ fn main() { #[cfg(feature = "test-musl-serialized")] mod musl_reference_tests { - use rand::seq::SliceRandom; - use rand::Rng; - use std::env; - use std::fs; use std::path::PathBuf; use std::process::Command; + use std::{env, fs}; + + use rand::Rng; + use rand::seq::SliceRandom; // Number of tests to generate for each function const NTESTS: usize = 500; @@ -60,10 +60,7 @@ mod musl_reference_tests { return; } - let files = fs::read_dir(math_src) - .unwrap() - .map(|f| f.unwrap().path()) - .collect::>(); + let files = fs::read_dir(math_src).unwrap().map(|f| f.unwrap().path()).collect::>(); let mut math = Vec::new(); for file in files { @@ -112,12 +109,7 @@ mod musl_reference_tests { let tail = eat(tail, " -> "); let ret = parse_retty(tail.replace("{", "").trim()); - return Function { - name: name.to_string(), - args, - ret, - tests: Vec::new(), - }; + return Function { name: name.to_string(), args, ret, tests: Vec::new() }; fn parse_ty(s: &str) -> Ty { match s { @@ -156,11 +148,7 @@ mod musl_reference_tests { } fn generate_test(function: &Function, rng: &mut R) -> Test { - let mut inputs = function - .args - .iter() - .map(|ty| ty.gen_i64(rng)) - .collect::>(); + let mut inputs = function.args.iter().map(|ty| ty.gen_i64(rng)).collect::>(); // First argument to this function appears to be a number of // iterations, so passing in massive random numbers causes it to @@ -180,15 +168,12 @@ mod musl_reference_tests { impl Ty { fn gen_i64(&self, r: &mut R) -> i64 { - use std::f32; - use std::f64; + use std::{f32, f64}; return match self { Ty::F32 => { if r.gen_range(0..20) < 1 { - let i = *[f32::NAN, f32::INFINITY, f32::NEG_INFINITY] - .choose(r) - .unwrap(); + let i = *[f32::NAN, f32::INFINITY, f32::NEG_INFINITY].choose(r).unwrap(); i.to_bits().into() } else { r.gen::().to_bits().into() @@ -196,9 +181,7 @@ mod musl_reference_tests { } Ty::F64 => { if r.gen_range(0..20) < 1 { - let i = *[f64::NAN, f64::INFINITY, f64::NEG_INFINITY] - .choose(r) - .unwrap(); + let i = *[f64::NAN, f64::INFINITY, f64::NEG_INFINITY].choose(r).unwrap(); i.to_bits() as i64 } else { r.gen::().to_bits() as i64 @@ -424,11 +407,7 @@ mod musl_reference_tests { src.push_str(");"); for (i, ret) in function.ret.iter().enumerate() { - let get = if function.ret.len() == 1 { - String::new() - } else { - format!(".{}", i) - }; + let get = if function.ret.len() == 1 { String::new() } else { format!(".{}", i) }; src.push_str(&(match ret { Ty::F32 => format!("if libm::_eqf(output{}, f32::from_bits(expected[{}] as u32)).is_ok() {{ continue }}", get, i), Ty::F64 => format!("if libm::_eq(output{}, f64::from_bits(expected[{}] as u64)).is_ok() {{ continue }}", get, i), diff --git a/library/compiler-builtins/libm/src/lib.rs b/library/compiler-builtins/libm/src/lib.rs index 04f4ac0f2e18..6d95fa1737b3 100644 --- a/library/compiler-builtins/libm/src/lib.rs +++ b/library/compiler-builtins/libm/src/lib.rs @@ -17,9 +17,10 @@ mod math; use core::{f32, f64}; -pub use self::math::*; pub use libm_helper::*; +pub use self::math::*; + /// Approximate equality with 1 ULP of tolerance #[doc(hidden)] #[inline] @@ -29,11 +30,7 @@ pub fn _eqf(a: f32, b: f32) -> Result<(), u32> { } else { let err = (a.to_bits() as i32).wrapping_sub(b.to_bits() as i32).abs(); - if err <= 1 { - Ok(()) - } else { - Err(err as u32) - } + if err <= 1 { Ok(()) } else { Err(err as u32) } } } @@ -45,10 +42,6 @@ pub fn _eq(a: f64, b: f64) -> Result<(), u64> { } else { let err = (a.to_bits() as i64).wrapping_sub(b.to_bits() as i64).abs(); - if err <= 1 { - Ok(()) - } else { - Err(err as u64) - } + if err <= 1 { Ok(()) } else { Err(err as u64) } } } diff --git a/library/compiler-builtins/libm/src/math/asin.rs b/library/compiler-builtins/libm/src/math/asin.rs index 3e4b7c56ebae..12fe08fc7452 100644 --- a/library/compiler-builtins/libm/src/math/asin.rs +++ b/library/compiler-builtins/libm/src/math/asin.rs @@ -111,9 +111,5 @@ pub fn asin(mut x: f64) -> f64 { c = (z - f * f) / (s + f); x = 0.5 * PIO2_HI - (2.0 * s * r - (PIO2_LO - 2.0 * c) - (0.5 * PIO2_HI - 2.0 * f)); } - if hx >> 31 != 0 { - -x - } else { - x - } + if hx >> 31 != 0 { -x } else { x } } diff --git a/library/compiler-builtins/libm/src/math/asinf.rs b/library/compiler-builtins/libm/src/math/asinf.rs index 6ec61b629782..2c785abe2baf 100644 --- a/library/compiler-builtins/libm/src/math/asinf.rs +++ b/library/compiler-builtins/libm/src/math/asinf.rs @@ -64,9 +64,5 @@ pub fn asinf(mut x: f32) -> f32 { let z = (1. - fabsf(x)) * 0.5; let s = sqrt(z as f64); x = (PIO2 - 2. * (s + s * (r(z) as f64))) as f32; - if (hx >> 31) != 0 { - -x - } else { - x - } + if (hx >> 31) != 0 { -x } else { x } } diff --git a/library/compiler-builtins/libm/src/math/asinh.rs b/library/compiler-builtins/libm/src/math/asinh.rs index 0abd80c2fd72..75d3c3ad462a 100644 --- a/library/compiler-builtins/libm/src/math/asinh.rs +++ b/library/compiler-builtins/libm/src/math/asinh.rs @@ -32,9 +32,5 @@ pub fn asinh(mut x: f64) -> f64 { force_eval!(x + x1p120); } - if sign { - -x - } else { - x - } + if sign { -x } else { x } } diff --git a/library/compiler-builtins/libm/src/math/asinhf.rs b/library/compiler-builtins/libm/src/math/asinhf.rs index 09c77823e105..27ed9dd372da 100644 --- a/library/compiler-builtins/libm/src/math/asinhf.rs +++ b/library/compiler-builtins/libm/src/math/asinhf.rs @@ -31,9 +31,5 @@ pub fn asinhf(mut x: f32) -> f32 { force_eval!(x + x1p120); } - if sign { - -x - } else { - x - } + if sign { -x } else { x } } diff --git a/library/compiler-builtins/libm/src/math/atan.rs b/library/compiler-builtins/libm/src/math/atan.rs index 4259dc71aaba..4ca5cc91a1e4 100644 --- a/library/compiler-builtins/libm/src/math/atan.rs +++ b/library/compiler-builtins/libm/src/math/atan.rs @@ -29,9 +29,10 @@ * to produce the hexadecimal values shown. */ -use super::fabs; use core::f64; +use super::fabs; + const ATANHI: [f64; 4] = [ 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ @@ -128,18 +129,15 @@ pub fn atan(x: f64) -> f64 { let z = i!(ATANHI, id as usize) - (x * (s1 + s2) - i!(ATANLO, id as usize) - x); - if sign != 0 { - -z - } else { - z - } + if sign != 0 { -z } else { z } } #[cfg(test)] mod tests { - use super::atan; use core::f64; + use super::atan; + #[test] fn sanity_check() { for (input, answer) in [ diff --git a/library/compiler-builtins/libm/src/math/atan2.rs b/library/compiler-builtins/libm/src/math/atan2.rs index fb2ea4edaf56..b9bf0da935bc 100644 --- a/library/compiler-builtins/libm/src/math/atan2.rs +++ b/library/compiler-builtins/libm/src/math/atan2.rs @@ -37,8 +37,7 @@ * to produce the hexadecimal values shown. */ -use super::atan; -use super::fabs; +use super::{atan, fabs}; const PI: f64 = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */ const PI_LO: f64 = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ diff --git a/library/compiler-builtins/libm/src/math/atan2f.rs b/library/compiler-builtins/libm/src/math/atan2f.rs index eae3b002daee..fa33f54f6f76 100644 --- a/library/compiler-builtins/libm/src/math/atan2f.rs +++ b/library/compiler-builtins/libm/src/math/atan2f.rs @@ -13,8 +13,7 @@ * ==================================================== */ -use super::atanf; -use super::fabsf; +use super::{atanf, fabsf}; const PI: f32 = 3.1415927410e+00; /* 0x40490fdb */ const PI_LO: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */ diff --git a/library/compiler-builtins/libm/src/math/atanf.rs b/library/compiler-builtins/libm/src/math/atanf.rs index d042b3bc0fd9..eb3d401cd967 100644 --- a/library/compiler-builtins/libm/src/math/atanf.rs +++ b/library/compiler-builtins/libm/src/math/atanf.rs @@ -29,13 +29,8 @@ const ATAN_LO: [f32; 4] = [ 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ ]; -const A_T: [f32; 5] = [ - 3.3333328366e-01, - -1.9999158382e-01, - 1.4253635705e-01, - -1.0648017377e-01, - 6.1687607318e-02, -]; +const A_T: [f32; 5] = + [3.3333328366e-01, -1.9999158382e-01, 1.4253635705e-01, -1.0648017377e-01, 6.1687607318e-02]; /// Arctangent (f32) /// @@ -104,9 +99,5 @@ pub fn atanf(mut x: f32) -> f32 { } let id = id as usize; let z = i!(ATAN_HI, id) - ((x * (s1 + s2) - i!(ATAN_LO, id)) - x); - if sign { - -z - } else { - z - } + if sign { -z } else { z } } diff --git a/library/compiler-builtins/libm/src/math/atanh.rs b/library/compiler-builtins/libm/src/math/atanh.rs index b984c4ac6282..9dc826f5605b 100644 --- a/library/compiler-builtins/libm/src/math/atanh.rs +++ b/library/compiler-builtins/libm/src/math/atanh.rs @@ -29,9 +29,5 @@ pub fn atanh(x: f64) -> f64 { y = 0.5 * log1p(2.0 * (y / (1.0 - y))); } - if sign { - -y - } else { - y - } + if sign { -y } else { y } } diff --git a/library/compiler-builtins/libm/src/math/atanhf.rs b/library/compiler-builtins/libm/src/math/atanhf.rs index a1aa314a50f3..3545411bbd5b 100644 --- a/library/compiler-builtins/libm/src/math/atanhf.rs +++ b/library/compiler-builtins/libm/src/math/atanhf.rs @@ -29,9 +29,5 @@ pub fn atanhf(mut x: f32) -> f32 { x = 0.5 * log1pf(2.0 * (x / (1.0 - x))); } - if sign { - -x - } else { - x - } + if sign { -x } else { x } } diff --git a/library/compiler-builtins/libm/src/math/ceil.rs b/library/compiler-builtins/libm/src/math/ceil.rs index cde5a19d0c80..1593fdaffcee 100644 --- a/library/compiler-builtins/libm/src/math/ceil.rs +++ b/library/compiler-builtins/libm/src/math/ceil.rs @@ -42,28 +42,21 @@ pub fn ceil(x: f64) -> f64 { return x; } // y = int(x) - x, where int(x) is an integer neighbor of x - y = if (u >> 63) != 0 { - x - TOINT + TOINT - x - } else { - x + TOINT - TOINT - x - }; + y = if (u >> 63) != 0 { x - TOINT + TOINT - x } else { x + TOINT - TOINT - x }; // special case because of non-nearest rounding modes if e < 0x3ff { force_eval!(y); return if (u >> 63) != 0 { -0. } else { 1. }; } - if y < 0. { - x + y + 1. - } else { - x + y - } + if y < 0. { x + y + 1. } else { x + y } } #[cfg(test)] mod tests { - use super::*; use core::f64::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(ceil(1.1), 2.0); diff --git a/library/compiler-builtins/libm/src/math/ceilf.rs b/library/compiler-builtins/libm/src/math/ceilf.rs index 7bcc647ca76a..bf9ba12279cf 100644 --- a/library/compiler-builtins/libm/src/math/ceilf.rs +++ b/library/compiler-builtins/libm/src/math/ceilf.rs @@ -44,9 +44,10 @@ pub fn ceilf(x: f32) -> f32 { #[cfg(not(target_arch = "powerpc64"))] #[cfg(test)] mod tests { - use super::*; use core::f32::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(ceilf(1.1), 2.0); diff --git a/library/compiler-builtins/libm/src/math/cosf.rs b/library/compiler-builtins/libm/src/math/cosf.rs index 424fa42eda61..0a01335f7707 100644 --- a/library/compiler-builtins/libm/src/math/cosf.rs +++ b/library/compiler-builtins/libm/src/math/cosf.rs @@ -14,10 +14,10 @@ * ==================================================== */ -use super::{k_cosf, k_sinf, rem_pio2f}; - use core::f64::consts::FRAC_PI_2; +use super::{k_cosf, k_sinf, rem_pio2f}; + /* Small multiples of pi/2 rounded to double precision. */ const C1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */ const C2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */ diff --git a/library/compiler-builtins/libm/src/math/cosh.rs b/library/compiler-builtins/libm/src/math/cosh.rs index 2fb568ab314c..d2e43fd6cb69 100644 --- a/library/compiler-builtins/libm/src/math/cosh.rs +++ b/library/compiler-builtins/libm/src/math/cosh.rs @@ -1,6 +1,4 @@ -use super::exp; -use super::expm1; -use super::k_expo2; +use super::{exp, expm1, k_expo2}; /// Hyperbolic cosine (f64) /// diff --git a/library/compiler-builtins/libm/src/math/coshf.rs b/library/compiler-builtins/libm/src/math/coshf.rs index e7b684587887..567a24410e79 100644 --- a/library/compiler-builtins/libm/src/math/coshf.rs +++ b/library/compiler-builtins/libm/src/math/coshf.rs @@ -1,6 +1,4 @@ -use super::expf; -use super::expm1f; -use super::k_expo2f; +use super::{expf, expm1f, k_expo2f}; /// Hyperbolic cosine (f64) /// diff --git a/library/compiler-builtins/libm/src/math/erf.rs b/library/compiler-builtins/libm/src/math/erf.rs index 55569affc975..1b634abec6bc 100644 --- a/library/compiler-builtins/libm/src/math/erf.rs +++ b/library/compiler-builtins/libm/src/math/erf.rs @@ -256,11 +256,7 @@ pub fn erf(x: f64) -> f64 { y = 1.0 - x1p_1022; } - if sign != 0 { - -y - } else { - y - } + if sign != 0 { -y } else { y } } /// Complementary error function (f64) @@ -310,9 +306,5 @@ pub fn erfc(x: f64) -> f64 { } let x1p_1022 = f64::from_bits(0x0010000000000000); - if sign != 0 { - 2.0 - x1p_1022 - } else { - x1p_1022 * x1p_1022 - } + if sign != 0 { 2.0 - x1p_1022 } else { x1p_1022 * x1p_1022 } } diff --git a/library/compiler-builtins/libm/src/math/erff.rs b/library/compiler-builtins/libm/src/math/erff.rs index 7b25474f6025..2e41183bfc0f 100644 --- a/library/compiler-builtins/libm/src/math/erff.rs +++ b/library/compiler-builtins/libm/src/math/erff.rs @@ -167,11 +167,7 @@ pub fn erff(x: f32) -> f32 { y = 1.0 - x1p_120; } - if sign != 0 { - -y - } else { - y - } + if sign != 0 { -y } else { y } } /// Complementary error function (f32) @@ -222,9 +218,5 @@ pub fn erfcf(x: f32) -> f32 { } let x1p_120 = f32::from_bits(0x03800000); - if sign != 0 { - 2.0 - x1p_120 - } else { - x1p_120 * x1p_120 - } + if sign != 0 { 2.0 - x1p_120 } else { x1p_120 * x1p_120 } } diff --git a/library/compiler-builtins/libm/src/math/exp.rs b/library/compiler-builtins/libm/src/math/exp.rs index d4994277f895..782042b62cd3 100644 --- a/library/compiler-builtins/libm/src/math/exp.rs +++ b/library/compiler-builtins/libm/src/math/exp.rs @@ -146,9 +146,5 @@ pub fn exp(mut x: f64) -> f64 { xx = x * x; c = x - xx * (P1 + xx * (P2 + xx * (P3 + xx * (P4 + xx * P5)))); y = 1. + (x * c / (2. - c) - lo + hi); - if k == 0 { - y - } else { - scalbn(y, k) - } + if k == 0 { y } else { scalbn(y, k) } } diff --git a/library/compiler-builtins/libm/src/math/exp10f.rs b/library/compiler-builtins/libm/src/math/exp10f.rs index 1279bc6c566b..786305481dcf 100644 --- a/library/compiler-builtins/libm/src/math/exp10f.rs +++ b/library/compiler-builtins/libm/src/math/exp10f.rs @@ -2,9 +2,8 @@ use super::{exp2, exp2f, modff}; const LN10_F32: f32 = 3.32192809488736234787031942948939; const LN10_F64: f64 = 3.32192809488736234787031942948939; -const P10: &[f32] = &[ - 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, -]; +const P10: &[f32] = + &[1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7]; #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn exp10f(x: f32) -> f32 { diff --git a/library/compiler-builtins/libm/src/math/expf.rs b/library/compiler-builtins/libm/src/math/expf.rs index a53aa90a646a..8dc067ab0846 100644 --- a/library/compiler-builtins/libm/src/math/expf.rs +++ b/library/compiler-builtins/libm/src/math/expf.rs @@ -93,9 +93,5 @@ pub fn expf(mut x: f32) -> f32 { let xx = x * x; let c = x - xx * (P1 + xx * P2); let y = 1. + (x * c / (2. - c) - lo + hi); - if k == 0 { - y - } else { - scalbnf(y, k) - } + if k == 0 { y } else { scalbnf(y, k) } } diff --git a/library/compiler-builtins/libm/src/math/expm1f.rs b/library/compiler-builtins/libm/src/math/expm1f.rs index 3fc2a247b5be..a862fe2558c4 100644 --- a/library/compiler-builtins/libm/src/math/expm1f.rs +++ b/library/compiler-builtins/libm/src/math/expm1f.rs @@ -126,9 +126,5 @@ pub fn expm1f(mut x: f32) -> f32 { return y - 1.; } let uf = f32::from_bits(((0x7f - k) << 23) as u32); /* 2^-k */ - if k < 23 { - (x - e + (1. - uf)) * twopk - } else { - (x - (e + uf) + 1.) * twopk - } + if k < 23 { (x - e + (1. - uf)) * twopk } else { (x - (e + uf) + 1.) * twopk } } diff --git a/library/compiler-builtins/libm/src/math/fabs.rs b/library/compiler-builtins/libm/src/math/fabs.rs index b2255ad32cf3..3b0628aa63a7 100644 --- a/library/compiler-builtins/libm/src/math/fabs.rs +++ b/library/compiler-builtins/libm/src/math/fabs.rs @@ -18,9 +18,10 @@ pub fn fabs(x: f64) -> f64 { #[cfg(test)] mod tests { - use super::*; use core::f64::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(fabs(-1.0), 1.0); diff --git a/library/compiler-builtins/libm/src/math/fabsf.rs b/library/compiler-builtins/libm/src/math/fabsf.rs index 23f3646dc4a5..f81c8ca44236 100644 --- a/library/compiler-builtins/libm/src/math/fabsf.rs +++ b/library/compiler-builtins/libm/src/math/fabsf.rs @@ -18,9 +18,10 @@ pub fn fabsf(x: f32) -> f32 { #[cfg(not(target_arch = "powerpc64"))] #[cfg(test)] mod tests { - use super::*; use core::f32::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(fabsf(-1.0), 1.0); diff --git a/library/compiler-builtins/libm/src/math/floor.rs b/library/compiler-builtins/libm/src/math/floor.rs index b7d1a04d2cd3..e8fb21e5884b 100644 --- a/library/compiler-builtins/libm/src/math/floor.rs +++ b/library/compiler-builtins/libm/src/math/floor.rs @@ -41,28 +41,21 @@ pub fn floor(x: f64) -> f64 { return x; } /* y = int(x) - x, where int(x) is an integer neighbor of x */ - let y = if (ui >> 63) != 0 { - x - TOINT + TOINT - x - } else { - x + TOINT - TOINT - x - }; + let y = if (ui >> 63) != 0 { x - TOINT + TOINT - x } else { x + TOINT - TOINT - x }; /* special case because of non-nearest rounding modes */ if e < 0x3ff { force_eval!(y); return if (ui >> 63) != 0 { -1. } else { 0. }; } - if y > 0. { - x + y - 1. - } else { - x + y - } + if y > 0. { x + y - 1. } else { x + y } } #[cfg(test)] mod tests { - use super::*; use core::f64::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(floor(1.1), 1.0); diff --git a/library/compiler-builtins/libm/src/math/floorf.rs b/library/compiler-builtins/libm/src/math/floorf.rs index dfdab91a0f69..f66cab74fdcf 100644 --- a/library/compiler-builtins/libm/src/math/floorf.rs +++ b/library/compiler-builtins/libm/src/math/floorf.rs @@ -44,9 +44,10 @@ pub fn floorf(x: f32) -> f32 { #[cfg(not(target_arch = "powerpc64"))] #[cfg(test)] mod tests { - use super::*; use core::f32::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(floorf(0.5), 0.0); diff --git a/library/compiler-builtins/libm/src/math/fma.rs b/library/compiler-builtins/libm/src/math/fma.rs index 940ee2db927b..bb2028fa77f2 100644 --- a/library/compiler-builtins/libm/src/math/fma.rs +++ b/library/compiler-builtins/libm/src/math/fma.rs @@ -216,17 +216,11 @@ mod tests { #[test] fn fma_sbb() { - assert_eq!( - fma(-(1.0 - f64::EPSILON), f64::MIN, f64::MIN), - -3991680619069439e277 - ); + assert_eq!(fma(-(1.0 - f64::EPSILON), f64::MIN, f64::MIN), -3991680619069439e277); } #[test] fn fma_underflow() { - assert_eq!( - fma(1.1102230246251565e-16, -9.812526705433188e-305, 1.0894e-320), - 0.0, - ); + assert_eq!(fma(1.1102230246251565e-16, -9.812526705433188e-305, 1.0894e-320), 0.0,); } } diff --git a/library/compiler-builtins/libm/src/math/fmaf.rs b/library/compiler-builtins/libm/src/math/fmaf.rs index 2848f2aee0c3..10bdaeab33de 100644 --- a/library/compiler-builtins/libm/src/math/fmaf.rs +++ b/library/compiler-builtins/libm/src/math/fmaf.rs @@ -29,7 +29,7 @@ use core::f32; use core::ptr::read_volatile; use super::fenv::{ - feclearexcept, fegetround, feraiseexcept, fetestexcept, FE_INEXACT, FE_TONEAREST, FE_UNDERFLOW, + FE_INEXACT, FE_TONEAREST, FE_UNDERFLOW, feclearexcept, fegetround, feraiseexcept, fetestexcept, }; /* @@ -91,11 +91,7 @@ pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 { * we need to adjust the low-order bit in the direction of the error. */ let neg = ui >> 63 != 0; - let err = if neg == (z as f64 > xy) { - xy - result + z as f64 - } else { - z as f64 - result + xy - }; + let err = if neg == (z as f64 > xy) { xy - result + z as f64 } else { z as f64 - result + xy }; if neg == (err < 0.0) { ui += 1; } else { diff --git a/library/compiler-builtins/libm/src/math/fmodf.rs b/library/compiler-builtins/libm/src/math/fmodf.rs index c53dc186aeba..1d80013842e7 100644 --- a/library/compiler-builtins/libm/src/math/fmodf.rs +++ b/library/compiler-builtins/libm/src/math/fmodf.rs @@ -1,5 +1,4 @@ -use core::f32; -use core::u32; +use core::{f32, u32}; #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fmodf(x: f32, y: f32) -> f32 { diff --git a/library/compiler-builtins/libm/src/math/ilogb.rs b/library/compiler-builtins/libm/src/math/ilogb.rs index 7d74dcfb666d..9d58d06081b7 100644 --- a/library/compiler-builtins/libm/src/math/ilogb.rs +++ b/library/compiler-builtins/libm/src/math/ilogb.rs @@ -21,11 +21,7 @@ pub fn ilogb(x: f64) -> i32 { e } else if e == 0x7ff { force_eval!(0.0 / 0.0); - if (i << 12) != 0 { - FP_ILOGBNAN - } else { - i32::max_value() - } + if (i << 12) != 0 { FP_ILOGBNAN } else { i32::max_value() } } else { e - 0x3ff } diff --git a/library/compiler-builtins/libm/src/math/ilogbf.rs b/library/compiler-builtins/libm/src/math/ilogbf.rs index 0fa58748c2f5..85deb43c83b7 100644 --- a/library/compiler-builtins/libm/src/math/ilogbf.rs +++ b/library/compiler-builtins/libm/src/math/ilogbf.rs @@ -21,11 +21,7 @@ pub fn ilogbf(x: f32) -> i32 { e } else if e == 0xff { force_eval!(0.0 / 0.0); - if (i << 9) != 0 { - FP_ILOGBNAN - } else { - i32::max_value() - } + if (i << 9) != 0 { FP_ILOGBNAN } else { i32::max_value() } } else { e - 0x7f } diff --git a/library/compiler-builtins/libm/src/math/jn.rs b/library/compiler-builtins/libm/src/math/jn.rs index 1be167f8461a..22ced20c15a4 100644 --- a/library/compiler-builtins/libm/src/math/jn.rs +++ b/library/compiler-builtins/libm/src/math/jn.rs @@ -244,11 +244,7 @@ pub fn jn(n: i32, mut x: f64) -> f64 { } } - if sign { - -b - } else { - b - } + if sign { -b } else { b } } pub fn yn(n: i32, x: f64) -> f64 { @@ -335,9 +331,5 @@ pub fn yn(n: i32, x: f64) -> f64 { } } - if sign { - -b - } else { - b - } + if sign { -b } else { b } } diff --git a/library/compiler-builtins/libm/src/math/jnf.rs b/library/compiler-builtins/libm/src/math/jnf.rs index 360f62e201d4..9cd0bb37de9d 100644 --- a/library/compiler-builtins/libm/src/math/jnf.rs +++ b/library/compiler-builtins/libm/src/math/jnf.rs @@ -188,11 +188,7 @@ pub fn jnf(n: i32, mut x: f32) -> f32 { } } - if sign { - -b - } else { - b - } + if sign { -b } else { b } } pub fn ynf(n: i32, x: f32) -> f32 { @@ -251,9 +247,5 @@ pub fn ynf(n: i32, x: f32) -> f32 { a = temp; } - if sign { - -b - } else { - b - } + if sign { -b } else { b } } diff --git a/library/compiler-builtins/libm/src/math/k_sin.rs b/library/compiler-builtins/libm/src/math/k_sin.rs index 9dd96c944744..42441455ff32 100644 --- a/library/compiler-builtins/libm/src/math/k_sin.rs +++ b/library/compiler-builtins/libm/src/math/k_sin.rs @@ -49,9 +49,5 @@ pub(crate) fn k_sin(x: f64, y: f64, iy: i32) -> f64 { let w = z * z; let r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6); let v = z * x; - if iy == 0 { - x + v * (S1 + z * r) - } else { - x - ((z * (0.5 * y - v * r) - y) - v * S1) - } + if iy == 0 { x + v * (S1 + z * r) } else { x - ((z * (0.5 * y - v * r) - y) - v * S1) } } diff --git a/library/compiler-builtins/libm/src/math/log1p.rs b/library/compiler-builtins/libm/src/math/log1p.rs index 4fd1c73eb81e..552de549bfc6 100644 --- a/library/compiler-builtins/libm/src/math/log1p.rs +++ b/library/compiler-builtins/libm/src/math/log1p.rs @@ -117,11 +117,7 @@ pub fn log1p(x: f64) -> f64 { k = (hu >> 20) as i32 - 0x3ff; /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ if k < 54 { - c = if k >= 2 { - 1. - (f64::from_bits(ui) - x) - } else { - x - (f64::from_bits(ui) - 1.) - }; + c = if k >= 2 { 1. - (f64::from_bits(ui) - x) } else { x - (f64::from_bits(ui) - 1.) }; c /= f64::from_bits(ui); } else { c = 0.; diff --git a/library/compiler-builtins/libm/src/math/log1pf.rs b/library/compiler-builtins/libm/src/math/log1pf.rs index 500e8eeaa85e..8068128db4f8 100644 --- a/library/compiler-builtins/libm/src/math/log1pf.rs +++ b/library/compiler-builtins/libm/src/math/log1pf.rs @@ -72,11 +72,7 @@ pub fn log1pf(x: f32) -> f32 { k = (iu >> 23) as i32 - 0x7f; /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ if k < 25 { - c = if k >= 2 { - 1. - (f32::from_bits(ui) - x) - } else { - x - (f32::from_bits(ui) - 1.) - }; + c = if k >= 2 { 1. - (f32::from_bits(ui) - x) } else { x - (f32::from_bits(ui) - 1.) }; c /= f32::from_bits(ui); } else { c = 0.; diff --git a/library/compiler-builtins/libm/src/math/mod.rs b/library/compiler-builtins/libm/src/math/mod.rs index a56532dddc14..85c9fc5bf156 100644 --- a/library/compiler-builtins/libm/src/math/mod.rs +++ b/library/compiler-builtins/libm/src/math/mod.rs @@ -218,15 +218,13 @@ pub use self::cos::cos; pub use self::cosf::cosf; pub use self::cosh::cosh; pub use self::coshf::coshf; -pub use self::erf::erf; -pub use self::erf::erfc; -pub use self::erff::erfcf; -pub use self::erff::erff; +pub use self::erf::{erf, erfc}; +pub use self::erff::{erfcf, erff}; pub use self::exp::exp; -pub use self::exp10::exp10; -pub use self::exp10f::exp10f; pub use self::exp2::exp2; pub use self::exp2f::exp2f; +pub use self::exp10::exp10; +pub use self::exp10f::exp10f; pub use self::expf::expf; pub use self::expm1::expm1; pub use self::expm1f::expm1f; @@ -250,18 +248,12 @@ pub use self::hypot::hypot; pub use self::hypotf::hypotf; pub use self::ilogb::ilogb; pub use self::ilogbf::ilogbf; -pub use self::j0::j0; -pub use self::j0::y0; -pub use self::j0f::j0f; -pub use self::j0f::y0f; -pub use self::j1::j1; -pub use self::j1::y1; -pub use self::j1f::j1f; -pub use self::j1f::y1f; -pub use self::jn::jn; -pub use self::jn::yn; -pub use self::jnf::jnf; -pub use self::jnf::ynf; +pub use self::j0::{j0, y0}; +pub use self::j0f::{j0f, y0f}; +pub use self::j1::{j1, y1}; +pub use self::j1f::{j1f, y1f}; +pub use self::jn::{jn, yn}; +pub use self::jnf::{jnf, ynf}; pub use self::ldexp::ldexp; pub use self::ldexpf::ldexpf; pub use self::lgamma::lgamma; @@ -269,12 +261,12 @@ pub use self::lgamma_r::lgamma_r; pub use self::lgammaf::lgammaf; pub use self::lgammaf_r::lgammaf_r; pub use self::log::log; -pub use self::log10::log10; -pub use self::log10f::log10f; pub use self::log1p::log1p; pub use self::log1pf::log1pf; pub use self::log2::log2; pub use self::log2f::log2f; +pub use self::log10::log10; +pub use self::log10f::log10f; pub use self::logf::logf; pub use self::modf::modf; pub use self::modff::modff; diff --git a/library/compiler-builtins/libm/src/math/pow.rs b/library/compiler-builtins/libm/src/math/pow.rs index 09d12c1851b4..9b617cadbfed 100644 --- a/library/compiler-builtins/libm/src/math/pow.rs +++ b/library/compiler-builtins/libm/src/math/pow.rs @@ -159,18 +159,10 @@ pub fn pow(x: f64, y: f64) -> f64 { 1.0 } else if ix >= 0x3ff00000 { /* (|x|>1)**+-inf = inf,0 */ - if hy >= 0 { - y - } else { - 0.0 - } + if hy >= 0 { y } else { 0.0 } } else { /* (|x|<1)**+-inf = 0,inf */ - if hy >= 0 { - 0.0 - } else { - -y - } + if hy >= 0 { 0.0 } else { -y } }; } @@ -246,18 +238,10 @@ pub fn pow(x: f64, y: f64) -> f64 { /* over/underflow if x is not close to one */ if ix < 0x3fefffff { - return if hy < 0 { - s * HUGE * HUGE - } else { - s * TINY * TINY - }; + return if hy < 0 { s * HUGE * HUGE } else { s * TINY * TINY }; } if ix > 0x3ff00000 { - return if hy > 0 { - s * HUGE * HUGE - } else { - s * TINY * TINY - }; + return if hy > 0 { s * HUGE * HUGE } else { s * TINY * TINY }; } /* now |1-x| is TINY <= 2**-20, suffice to compute @@ -455,11 +439,7 @@ mod tests { fn pow_test(base: f64, exponent: f64, expected: f64) { let res = pow(base, exponent); assert!( - if expected.is_nan() { - res.is_nan() - } else { - pow(base, exponent) == expected - }, + if expected.is_nan() { res.is_nan() } else { pow(base, exponent) == expected }, "{} ** {} was {} instead of {}", base, exponent, @@ -469,13 +449,11 @@ mod tests { } fn test_sets_as_base(sets: &[&[f64]], exponent: f64, expected: f64) { - sets.iter() - .for_each(|s| s.iter().for_each(|val| pow_test(*val, exponent, expected))); + sets.iter().for_each(|s| s.iter().for_each(|val| pow_test(*val, exponent, expected))); } fn test_sets_as_exponent(base: f64, sets: &[&[f64]], expected: f64) { - sets.iter() - .for_each(|s| s.iter().for_each(|val| pow_test(base, *val, expected))); + sets.iter().for_each(|s| s.iter().for_each(|val| pow_test(base, *val, expected))); } fn test_sets(sets: &[&[f64]], computed: &dyn Fn(f64) -> f64, expected: &dyn Fn(f64) -> f64) { @@ -489,11 +467,7 @@ mod tests { #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))] let res = force_eval!(res); assert!( - if exp.is_nan() { - res.is_nan() - } else { - exp == res - }, + if exp.is_nan() { res.is_nan() } else { exp == res }, "test for {} was {} instead of {}", val, res, @@ -608,15 +582,15 @@ mod tests { // Factoring -1 out: // (negative anything ^ integer should be (-1 ^ integer) * (positive anything ^ integer)) - (&[POS_ZERO, NEG_ZERO, POS_ONE, NEG_ONE, POS_EVENS, NEG_EVENS]) - .iter() - .for_each(|int_set| { + (&[POS_ZERO, NEG_ZERO, POS_ONE, NEG_ONE, POS_EVENS, NEG_EVENS]).iter().for_each( + |int_set| { int_set.iter().for_each(|int| { test_sets(ALL, &|v: f64| pow(-v, *int), &|v: f64| { pow(-1.0, *int) * pow(v, *int) }); }) - }); + }, + ); // Negative base (imaginary results): // (-anything except 0 and Infinity ^ non-integer should be NAN) diff --git a/library/compiler-builtins/libm/src/math/powf.rs b/library/compiler-builtins/libm/src/math/powf.rs index 68d2083bbdd7..d47ab4b3d1d9 100644 --- a/library/compiler-builtins/libm/src/math/powf.rs +++ b/library/compiler-builtins/libm/src/math/powf.rs @@ -181,19 +181,11 @@ pub fn powf(x: f32, y: f32) -> f32 { /* if |y| > 2**27 */ /* over/underflow if x is not close to one */ if ix < 0x3f7ffff8 { - return if hy < 0 { - sn * HUGE * HUGE - } else { - sn * TINY * TINY - }; + return if hy < 0 { sn * HUGE * HUGE } else { sn * TINY * TINY }; } if ix > 0x3f800007 { - return if hy > 0 { - sn * HUGE * HUGE - } else { - sn * TINY * TINY - }; + return if hy > 0 { sn * HUGE * HUGE } else { sn * TINY * TINY }; } /* now |1-x| is TINY <= 2**-20, suffice to compute diff --git a/library/compiler-builtins/libm/src/math/rem_pio2.rs b/library/compiler-builtins/libm/src/math/rem_pio2.rs index 644616f2df84..6be23a43cede 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2.rs @@ -197,28 +197,16 @@ mod tests { fn test_near_pi() { let arg = 3.141592025756836; let arg = force_eval!(arg); - assert_eq!( - rem_pio2(arg), - (2, -6.278329573009626e-7, -2.1125998133974653e-23) - ); + assert_eq!(rem_pio2(arg), (2, -6.278329573009626e-7, -2.1125998133974653e-23)); let arg = 3.141592033207416; let arg = force_eval!(arg); - assert_eq!( - rem_pio2(arg), - (2, -6.20382377148128e-7, -2.1125998133974653e-23) - ); + assert_eq!(rem_pio2(arg), (2, -6.20382377148128e-7, -2.1125998133974653e-23)); let arg = 3.141592144966125; let arg = force_eval!(arg); - assert_eq!( - rem_pio2(arg), - (2, -5.086236681942706e-7, -2.1125998133974653e-23) - ); + assert_eq!(rem_pio2(arg), (2, -5.086236681942706e-7, -2.1125998133974653e-23)); let arg = 3.141592979431152; let arg = force_eval!(arg); - assert_eq!( - rem_pio2(arg), - (2, 3.2584135866119817e-7, -2.1125998133974653e-23) - ); + assert_eq!(rem_pio2(arg), (2, 3.2584135866119817e-7, -2.1125998133974653e-23)); } #[test] diff --git a/library/compiler-builtins/libm/src/math/rem_pio2_large.rs b/library/compiler-builtins/libm/src/math/rem_pio2_large.rs index db97a39d4902..1dfbba3b1b22 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2_large.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2_large.rs @@ -11,8 +11,7 @@ * ==================================================== */ -use super::floor; -use super::scalbn; +use super::{floor, scalbn}; // initial value for jk const INIT_JK: [usize; 4] = [3, 4, 4, 6]; diff --git a/library/compiler-builtins/libm/src/math/rem_pio2f.rs b/library/compiler-builtins/libm/src/math/rem_pio2f.rs index 775f5d750fb1..3c658fe3dbce 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2f.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2f.rs @@ -14,10 +14,10 @@ * ==================================================== */ -use super::rem_pio2_large; - use core::f64; +use super::rem_pio2_large; + const TOINT: f64 = 1.5 / f64::EPSILON; /// 53 bits of 2/pi diff --git a/library/compiler-builtins/libm/src/math/remquo.rs b/library/compiler-builtins/libm/src/math/remquo.rs index 0afd1f7f5f2a..4c11e848746b 100644 --- a/library/compiler-builtins/libm/src/math/remquo.rs +++ b/library/compiler-builtins/libm/src/math/remquo.rs @@ -91,11 +91,7 @@ pub fn remquo(mut x: f64, mut y: f64) -> (f64, i32) { } q &= 0x7fffffff; let quo = if sx ^ sy { -(q as i32) } else { q as i32 }; - if sx { - (-x, quo) - } else { - (x, quo) - } + if sx { (-x, quo) } else { (x, quo) } } #[cfg(test)] diff --git a/library/compiler-builtins/libm/src/math/remquof.rs b/library/compiler-builtins/libm/src/math/remquof.rs index d71bd38e3ddc..b0e85ca66116 100644 --- a/library/compiler-builtins/libm/src/math/remquof.rs +++ b/library/compiler-builtins/libm/src/math/remquof.rs @@ -89,9 +89,5 @@ pub fn remquof(mut x: f32, mut y: f32) -> (f32, i32) { } q &= 0x7fffffff; let quo = if sx ^ sy { -(q as i32) } else { q as i32 }; - if sx { - (-x, quo) - } else { - (x, quo) - } + if sx { (-x, quo) } else { (x, quo) } } diff --git a/library/compiler-builtins/libm/src/math/rint.rs b/library/compiler-builtins/libm/src/math/rint.rs index 8edbe3440223..618b26e5466b 100644 --- a/library/compiler-builtins/libm/src/math/rint.rs +++ b/library/compiler-builtins/libm/src/math/rint.rs @@ -23,15 +23,7 @@ pub fn rint(x: f64) -> f64 { xminusoneovere + one_over_e }; - if ans == 0.0 { - if is_positive { - 0.0 - } else { - -0.0 - } - } else { - ans - } + if ans == 0.0 { if is_positive { 0.0 } else { -0.0 } } else { ans } } } diff --git a/library/compiler-builtins/libm/src/math/rintf.rs b/library/compiler-builtins/libm/src/math/rintf.rs index 7a7da618ad8f..0726d83ba673 100644 --- a/library/compiler-builtins/libm/src/math/rintf.rs +++ b/library/compiler-builtins/libm/src/math/rintf.rs @@ -23,15 +23,7 @@ pub fn rintf(x: f32) -> f32 { xminusoneovere + one_over_e }; - if ans == 0.0 { - if is_positive { - 0.0 - } else { - -0.0 - } - } else { - ans - } + if ans == 0.0 { if is_positive { 0.0 } else { -0.0 } } else { ans } } } diff --git a/library/compiler-builtins/libm/src/math/round.rs b/library/compiler-builtins/libm/src/math/round.rs index 46fabc90ff53..b81ebaa1dbec 100644 --- a/library/compiler-builtins/libm/src/math/round.rs +++ b/library/compiler-builtins/libm/src/math/round.rs @@ -1,7 +1,7 @@ -use super::copysign; -use super::trunc; use core::f64; +use super::{copysign, trunc}; + #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn round(x: f64) -> f64 { trunc(x + copysign(0.5 - 0.25 * f64::EPSILON, x)) diff --git a/library/compiler-builtins/libm/src/math/roundf.rs b/library/compiler-builtins/libm/src/math/roundf.rs index becdb5620a90..fb974bbfe73f 100644 --- a/library/compiler-builtins/libm/src/math/roundf.rs +++ b/library/compiler-builtins/libm/src/math/roundf.rs @@ -1,7 +1,7 @@ -use super::copysignf; -use super::truncf; use core::f32; +use super::{copysignf, truncf}; + #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn roundf(x: f32) -> f32 { truncf(x + copysignf(0.5 - 0.25 * f32::EPSILON, x)) diff --git a/library/compiler-builtins/libm/src/math/sinf.rs b/library/compiler-builtins/libm/src/math/sinf.rs index 6e20be2aeee3..ca181462723e 100644 --- a/library/compiler-builtins/libm/src/math/sinf.rs +++ b/library/compiler-builtins/libm/src/math/sinf.rs @@ -14,10 +14,10 @@ * ==================================================== */ -use super::{k_cosf, k_sinf, rem_pio2f}; - use core::f64::consts::FRAC_PI_2; +use super::{k_cosf, k_sinf, rem_pio2f}; + /* Small multiples of pi/2 rounded to double precision. */ const S1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */ const S2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */ @@ -39,11 +39,7 @@ pub fn sinf(x: f32) -> f32 { if ix < 0x39800000 { /* |x| < 2**-12 */ /* raise inexact if x!=0 and underflow if subnormal */ - force_eval!(if ix < 0x00800000 { - x / x1p120 - } else { - x + x1p120 - }); + force_eval!(if ix < 0x00800000 { x / x1p120 } else { x + x1p120 }); return x; } return k_sinf(x64); @@ -58,11 +54,7 @@ pub fn sinf(x: f32) -> f32 { return k_cosf(x64 - S1_PIO2); } } - return k_sinf(if sign { - -(x64 + S2_PIO2) - } else { - -(x64 - S2_PIO2) - }); + return k_sinf(if sign { -(x64 + S2_PIO2) } else { -(x64 - S2_PIO2) }); } if ix <= 0x40e231d5 { /* |x| ~<= 9*pi/4 */ diff --git a/library/compiler-builtins/libm/src/math/sinhf.rs b/library/compiler-builtins/libm/src/math/sinhf.rs index 24f863c4465e..6788642f0c90 100644 --- a/library/compiler-builtins/libm/src/math/sinhf.rs +++ b/library/compiler-builtins/libm/src/math/sinhf.rs @@ -1,5 +1,4 @@ -use super::expm1f; -use super::k_expo2f; +use super::{expm1f, k_expo2f}; #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sinhf(x: f32) -> f32 { diff --git a/library/compiler-builtins/libm/src/math/sqrt.rs b/library/compiler-builtins/libm/src/math/sqrt.rs index 66cb7659c2db..5862b119b641 100644 --- a/library/compiler-builtins/libm/src/math/sqrt.rs +++ b/library/compiler-builtins/libm/src/math/sqrt.rs @@ -242,9 +242,10 @@ pub fn sqrt(x: f64) -> f64 { #[cfg(test)] mod tests { - use super::*; use core::f64::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(sqrt(100.0), 10.0); diff --git a/library/compiler-builtins/libm/src/math/sqrtf.rs b/library/compiler-builtins/libm/src/math/sqrtf.rs index 16cbb2f97701..f7324c941378 100644 --- a/library/compiler-builtins/libm/src/math/sqrtf.rs +++ b/library/compiler-builtins/libm/src/math/sqrtf.rs @@ -132,9 +132,10 @@ pub fn sqrtf(x: f32) -> f32 { #[cfg(not(target_arch = "powerpc64"))] #[cfg(test)] mod tests { - use super::*; use core::f32::*; + use super::*; + #[test] fn sanity_check() { assert_eq!(sqrtf(100.0), 10.0); @@ -154,12 +155,7 @@ mod tests { #[test] fn conformance_tests() { - let values = [ - 3.14159265359f32, - 10000.0f32, - f32::from_bits(0x0000000f), - INFINITY, - ]; + let values = [3.14159265359f32, 10000.0f32, f32::from_bits(0x0000000f), INFINITY]; let results = [1071833029u32, 1120403456u32, 456082799u32, 2139095040u32]; for i in 0..values.len() { diff --git a/library/compiler-builtins/libm/src/math/tan.rs b/library/compiler-builtins/libm/src/math/tan.rs index 5a72f68014ab..5aa44aeef72f 100644 --- a/library/compiler-builtins/libm/src/math/tan.rs +++ b/library/compiler-builtins/libm/src/math/tan.rs @@ -49,11 +49,7 @@ pub fn tan(x: f64) -> f64 { if ix < 0x3e400000 { /* |x| < 2**-27 */ /* raise inexact if x!=0 and underflow if subnormal */ - force_eval!(if ix < 0x00100000 { - x / x1p120 as f64 - } else { - x + x1p120 as f64 - }); + force_eval!(if ix < 0x00100000 { x / x1p120 as f64 } else { x + x1p120 as f64 }); return x; } return k_tan(x, 0.0, 0); diff --git a/library/compiler-builtins/libm/src/math/tanf.rs b/library/compiler-builtins/libm/src/math/tanf.rs index 10de59c3917d..f6b2399d0941 100644 --- a/library/compiler-builtins/libm/src/math/tanf.rs +++ b/library/compiler-builtins/libm/src/math/tanf.rs @@ -14,10 +14,10 @@ * ==================================================== */ -use super::{k_tanf, rem_pio2f}; - use core::f64::consts::FRAC_PI_2; +use super::{k_tanf, rem_pio2f}; + /* Small multiples of pi/2 rounded to double precision. */ const T1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */ const T2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */ @@ -39,11 +39,7 @@ pub fn tanf(x: f32) -> f32 { if ix < 0x39800000 { /* |x| < 2**-12 */ /* raise inexact if x!=0 and underflow if subnormal */ - force_eval!(if ix < 0x00800000 { - x / x1p120 - } else { - x + x1p120 - }); + force_eval!(if ix < 0x00800000 { x / x1p120 } else { x + x1p120 }); return x; } return k_tanf(x64, false); diff --git a/library/compiler-builtins/libm/src/math/tanh.rs b/library/compiler-builtins/libm/src/math/tanh.rs index 980c68554fd8..cfea2c167039 100644 --- a/library/compiler-builtins/libm/src/math/tanh.rs +++ b/library/compiler-builtins/libm/src/math/tanh.rs @@ -45,9 +45,5 @@ pub fn tanh(mut x: f64) -> f64 { t = x; } - if sign { - -t - } else { - t - } + if sign { -t } else { t } } diff --git a/library/compiler-builtins/libm/src/math/tanhf.rs b/library/compiler-builtins/libm/src/math/tanhf.rs index fc94e3ddd589..ab13e1abf4c8 100644 --- a/library/compiler-builtins/libm/src/math/tanhf.rs +++ b/library/compiler-builtins/libm/src/math/tanhf.rs @@ -31,9 +31,5 @@ pub fn tanhf(mut x: f32) -> f32 { force_eval!(x * x); x }; - if sign { - -tt - } else { - tt - } + if sign { -tt } else { tt } }