Run cargo fmt with new settings

Apply the changes from the `.rustfmt.toml` file added in the previous
commit.
This commit is contained in:
Trevor Gross 2024-10-26 20:22:24 -05:00
parent 710ca6e38e
commit ab0c8e84fb
57 changed files with 131 additions and 393 deletions

View file

@ -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::<Vec<_>>();
let files = fs::read_dir(math_src).unwrap().map(|f| f.unwrap().path()).collect::<Vec<_>>();
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<R: Rng>(function: &Function, rng: &mut R) -> Test {
let mut inputs = function
.args
.iter()
.map(|ty| ty.gen_i64(rng))
.collect::<Vec<_>>();
let mut inputs = function.args.iter().map(|ty| ty.gen_i64(rng)).collect::<Vec<_>>();
// 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<R: Rng>(&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::<f32>().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::<f64>().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),

View file

@ -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) }
}
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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 [

View file

@ -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 */

View file

@ -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 */

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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);

View file

@ -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);

View file

@ -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 */

View file

@ -1,6 +1,4 @@
use super::exp;
use super::expm1;
use super::k_expo2;
use super::{exp, expm1, k_expo2};
/// Hyperbolic cosine (f64)
///

View file

@ -1,6 +1,4 @@
use super::expf;
use super::expm1f;
use super::k_expo2f;
use super::{expf, expm1f, k_expo2f};
/// Hyperbolic cosine (f64)
///

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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) }
}

View file

@ -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 {

View file

@ -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) }
}

View file

@ -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 }
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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,);
}
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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
}

View file

@ -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
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -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) }
}

View file

@ -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.;

View file

@ -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.;

View file

@ -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;

View file

@ -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)

View file

@ -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

View file

@ -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]

View file

@ -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];

View file

@ -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

View file

@ -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)]

View file

@ -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) }
}

View file

@ -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 }
}
}

View file

@ -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 }
}
}

View file

@ -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))

View file

@ -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))

View file

@ -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 */

View file

@ -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 {

View file

@ -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);

View file

@ -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() {

View file

@ -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);

View file

@ -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);

View file

@ -45,9 +45,5 @@ pub fn tanh(mut x: f64) -> f64 {
t = x;
}
if sign {
-t
} else {
t
}
if sign { -t } else { t }
}

View file

@ -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 }
}