Skip to content

Commit 565b581

Browse files
bors[bot]japaric
andcommitted
78: force PR code to be formatted r=japaric a=japaric Co-authored-by: Jorge Aparicio <[email protected]>
2 parents cd78955 + f966201 commit 565b581

13 files changed

+155
-149
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ matrix:
1515
- env: TARGET=powerpc64-unknown-linux-gnu
1616
- env: TARGET=powerpc64le-unknown-linux-gnu
1717
- env: TARGET=x86_64-unknown-linux-gnu
18+
- env: TARGET=cargo-fmt
19+
rust: beta
1820

1921
before_install: set -e
2022

ci/install.sh

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
set -euxo pipefail
22

33
main() {
4+
if [ $TARGET = cargo-fmt ]; then
5+
rustup component add rustfmt-preview
6+
return
7+
fi
8+
49
if ! hash cross >/dev/null 2>&1; then
510
cargo install cross
611
fi

ci/script.sh

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
set -euxo pipefail
22

33
main() {
4+
if [ $TARGET = cargo-fmt ]; then
5+
cargo fmt -- --check
6+
return
7+
fi
8+
49
# quick check
510
cargo check
611

src/math/expf.rs

+40-33
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,67 @@
11
use super::scalbnf;
22

3-
const HALF : [f32; 2] = [0.5,-0.5];
4-
const LN2_HI : f32 = 6.9314575195e-01; /* 0x3f317200 */
5-
const LN2_LO : f32 = 1.4286067653e-06; /* 0x35bfbe8e */
6-
const INV_LN2 : f32 = 1.4426950216e+00; /* 0x3fb8aa3b */
3+
const HALF: [f32; 2] = [0.5, -0.5];
4+
const LN2_HI: f32 = 6.9314575195e-01; /* 0x3f317200 */
5+
const LN2_LO: f32 = 1.4286067653e-06; /* 0x35bfbe8e */
6+
const INV_LN2: f32 = 1.4426950216e+00; /* 0x3fb8aa3b */
77
/*
88
* Domain [-0.34568, 0.34568], range ~[-4.278e-9, 4.447e-9]:
99
* |x*(exp(x)+1)/(exp(x)-1) - p(x)| < 2**-27.74
1010
*/
11-
const P1 : f32 = 1.6666625440e-1; /* 0xaaaa8f.0p-26 */
12-
const P2 : f32 = -2.7667332906e-3; /* -0xb55215.0p-32 */
11+
const P1: f32 = 1.6666625440e-1; /* 0xaaaa8f.0p-26 */
12+
const P2: f32 = -2.7667332906e-3; /* -0xb55215.0p-32 */
1313

1414
#[inline]
1515
pub fn expf(mut x: f32) -> f32 {
16-
let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127
17-
let x1p_126 = f32::from_bits(0x800000); // 0x1p-126f === 2 ^ -126 /*original 0x1p-149f ??????????? */
18-
16+
let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127
17+
let x1p_126 = f32::from_bits(0x800000); // 0x1p-126f === 2 ^ -126 /*original 0x1p-149f ??????????? */
18+
1919
let mut hx = x.to_bits();
20-
let sign = (hx >> 31) as i32; /* sign bit of x */
21-
let signb : bool = sign != 0;
22-
hx &= 0x7fffffff; /* high word of |x| */
23-
20+
let sign = (hx >> 31) as i32; /* sign bit of x */
21+
let signb: bool = sign != 0;
22+
hx &= 0x7fffffff; /* high word of |x| */
23+
2424
/* special cases */
25-
if hx >= 0x42aeac50 { /* if |x| >= -87.33655f or NaN */
26-
if hx > 0x7f800000 {/* NaN */
25+
if hx >= 0x42aeac50 {
26+
/* if |x| >= -87.33655f or NaN */
27+
if hx > 0x7f800000 {
28+
/* NaN */
2729
return x;
2830
}
29-
if (hx >= 0x42b17218) && (!signb) { /* x >= 88.722839f */
31+
if (hx >= 0x42b17218) && (!signb) {
32+
/* x >= 88.722839f */
3033
/* overflow */
3134
x *= x1p127;
3235
return x;
3336
}
3437
if signb {
3538
/* underflow */
36-
force_eval!(-x1p_126/x);
37-
if hx >= 0x42cff1b5 { /* x <= -103.972084f */
38-
return 0.
39+
force_eval!(-x1p_126 / x);
40+
if hx >= 0x42cff1b5 {
41+
/* x <= -103.972084f */
42+
return 0.;
3943
}
4044
}
4145
}
42-
46+
4347
/* argument reduction */
44-
let k : i32;
45-
let hi : f32;
46-
let lo : f32;
47-
if hx > 0x3eb17218 { /* if |x| > 0.5 ln2 */
48-
if hx > 0x3f851592 { /* if |x| > 1.5 ln2 */
49-
k = (INV_LN2*x + HALF[sign as usize]) as i32;
48+
let k: i32;
49+
let hi: f32;
50+
let lo: f32;
51+
if hx > 0x3eb17218 {
52+
/* if |x| > 0.5 ln2 */
53+
if hx > 0x3f851592 {
54+
/* if |x| > 1.5 ln2 */
55+
k = (INV_LN2 * x + HALF[sign as usize]) as i32;
5056
} else {
5157
k = 1 - sign - sign;
5258
}
5359
let kf = k as f32;
54-
hi = x - kf*LN2_HI; /* k*ln2hi is exact here */
55-
lo = kf*LN2_LO;
60+
hi = x - kf * LN2_HI; /* k*ln2hi is exact here */
61+
lo = kf * LN2_LO;
5662
x = hi - lo;
57-
} else if hx > 0x39000000 { /* |x| > 2**-14 */
63+
} else if hx > 0x39000000 {
64+
/* |x| > 2**-14 */
5865
k = 0;
5966
hi = x;
6067
lo = 0.;
@@ -63,11 +70,11 @@ pub fn expf(mut x: f32) -> f32 {
6370
force_eval!(x1p127 + x);
6471
return 1. + x;
6572
}
66-
73+
6774
/* x is now in primary range */
68-
let xx = x*x;
69-
let c = x - xx*(P1+xx*P2);
70-
let y = 1. + (x*c/(2.-c) - lo + hi);
75+
let xx = x * x;
76+
let c = x - xx * (P1 + xx * P2);
77+
let y = 1. + (x * c / (2. - c) - lo + hi);
7178
if k == 0 {
7279
y
7380
} else {

src/math/floor.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
use core::f64;
22

3-
const TOINT : f64 = 1. / f64::EPSILON;
3+
const TOINT: f64 = 1. / f64::EPSILON;
44

55
#[inline]
6-
pub fn floor(x : f64) -> f64 {
6+
pub fn floor(x: f64) -> f64 {
77
let ui = x.to_bits();
8-
let e = ((ui >> 52) & 0x7ff) as i32;
8+
let e = ((ui >> 52) & 0x7ff) as i32;
99

10-
if (e >= 0x3ff+52) || (x == 0.) {
11-
return x;
10+
if (e >= 0x3ff + 52) || (x == 0.) {
11+
return x;
1212
}
13-
/* y = int(x) - x, where int(x) is an integer neighbor of x */
14-
let y = if (ui >> 63) != 0 {
15-
x - TOINT + TOINT - x
16-
} else {
17-
x + TOINT - TOINT - x
13+
/* y = int(x) - x, where int(x) is an integer neighbor of x */
14+
let y = if (ui >> 63) != 0 {
15+
x - TOINT + TOINT - x
16+
} else {
17+
x + TOINT - TOINT - x
1818
};
19-
/* special case because of non-nearest rounding modes */
20-
if e <= 0x3ff-1 {
21-
force_eval!(y);
22-
return if (ui >> 63) != 0 { -1. } else { 0. };
23-
}
24-
if y > 0. {
19+
/* special case because of non-nearest rounding modes */
20+
if e <= 0x3ff - 1 {
21+
force_eval!(y);
22+
return if (ui >> 63) != 0 { -1. } else { 0. };
23+
}
24+
if y > 0. {
2525
x + y - 1.
2626
} else {
2727
x + y

src/math/hypot.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn sq(x: f64) -> (f64, f64) {
1212
xc = x * SPLIT;
1313
xh = x - xc + xc;
1414
xl = x - xh;
15-
let hi = x*x;
16-
let lo = xh*xh - hi + 2.*xh*xl + xl*xl;
15+
let hi = x * x;
16+
let lo = xh * xh - hi + 2. * xh * xl + xl * xl;
1717
(hi, lo)
1818
}
1919

@@ -39,8 +39,8 @@ pub fn hypot(mut x: f64, mut y: f64) -> f64 {
3939
}
4040

4141
/* special cases */
42-
ex = (uxi>>52) as i64;
43-
ey = (uyi>>52) as i64;
42+
ex = (uxi >> 52) as i64;
43+
ey = (uyi >> 52) as i64;
4444
x = f64::from_bits(uxi);
4545
y = f64::from_bits(uyi);
4646
/* note: hypot(inf,nan) == inf */
@@ -59,16 +59,16 @@ pub fn hypot(mut x: f64, mut y: f64) -> f64 {
5959
/* precise sqrt argument in nearest rounding mode without overflow */
6060
/* xh*xh must not overflow and xl*xl must not underflow in sq */
6161
z = 1.;
62-
if ex > 0x3ff+510 {
62+
if ex > 0x3ff + 510 {
6363
z = x1p700;
6464
x *= x1p_700;
6565
y *= x1p_700;
66-
} else if ey < 0x3ff-450 {
66+
} else if ey < 0x3ff - 450 {
6767
z = x1p_700;
6868
x *= x1p700;
6969
y *= x1p700;
7070
}
7171
let (hx, lx) = sq(x);
7272
let (hy, ly) = sq(y);
73-
return z*sqrt(ly+lx+hy+hx);
73+
return z * sqrt(ly + lx + hy + hx);
7474
}

src/math/hypotf.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ pub fn hypotf(mut x: f32, mut y: f32) -> f32 {
2222

2323
x = f32::from_bits(uxi);
2424
y = f32::from_bits(uyi);
25-
if uyi == 0xff<<23 {
25+
if uyi == 0xff << 23 {
2626
return y;
2727
}
28-
if uxi >= 0xff<<23 || uyi == 0 || uxi - uyi >= 25<<23 {
28+
if uxi >= 0xff << 23 || uyi == 0 || uxi - uyi >= 25 << 23 {
2929
return x + y;
3030
}
3131

3232
z = 1.;
33-
if uxi >= (0x7f+60)<<23 {
33+
if uxi >= (0x7f + 60) << 23 {
3434
z = x1p90;
3535
x *= x1p_90;
3636
y *= x1p_90;
37-
} else if uyi < (0x7f-60)<<23 {
37+
} else if uyi < (0x7f - 60) << 23 {
3838
z = x1p_90;
3939
x *= x1p90;
4040
y *= x1p90;
4141
}
42-
z*sqrtf((x as f64 * x as f64 + y as f64 * y as f64) as f32)
42+
z * sqrtf((x as f64 * x as f64 + y as f64 * y as f64) as f32)
4343
}

src/math/logf.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
const LN2_HI : f32 = 6.9313812256e-01; /* 0x3f317180 */
2-
const LN2_LO : f32 = 9.0580006145e-06; /* 0x3717f7d1 */
1+
const LN2_HI: f32 = 6.9313812256e-01; /* 0x3f317180 */
2+
const LN2_LO: f32 = 9.0580006145e-06; /* 0x3717f7d1 */
33
/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
4-
const LG1 : f32 = 0.66666662693; /* 0xaaaaaa.0p-24*/
5-
const LG2 : f32 = 0.40000972152; /* 0xccce13.0p-25 */
6-
const LG3 : f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
7-
const LG4 : f32 = 0.24279078841; /* 0xf89e26.0p-26 */
4+
const LG1: f32 = 0.66666662693; /* 0xaaaaaa.0p-24*/
5+
const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
6+
const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
7+
const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
88

99
#[inline]
1010
pub fn logf(mut x: f32) -> f32 {
1111
let x1p25 = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25
12-
12+
1313
let mut ix = x.to_bits();
1414
let mut k = 0i32;
15-
16-
if (ix < 0x00800000) || ((ix>>31) != 0) { /* x < 2**-126 */
17-
if ix<<1 == 0 {
18-
return -1./(x*x); /* log(+-0)=-inf */
15+
16+
if (ix < 0x00800000) || ((ix >> 31) != 0) {
17+
/* x < 2**-126 */
18+
if ix << 1 == 0 {
19+
return -1. / (x * x); /* log(+-0)=-inf */
1920
}
20-
if (ix>>31) != 0 {
21-
return (x-x)/0.; /* log(-#) = NaN */
21+
if (ix >> 31) != 0 {
22+
return (x - x) / 0.; /* log(-#) = NaN */
2223
}
2324
/* subnormal number, scale up x */
2425
k -= 25;
@@ -32,18 +33,18 @@ pub fn logf(mut x: f32) -> f32 {
3233

3334
/* reduce x into [sqrt(2)/2, sqrt(2)] */
3435
ix += 0x3f800000 - 0x3f3504f3;
35-
k += ((ix>>23) as i32) - 0x7f;
36+
k += ((ix >> 23) as i32) - 0x7f;
3637
ix = (ix & 0x007fffff) + 0x3f3504f3;
37-
x = f32::from_bits(ix);
38+
x = f32::from_bits(ix);
3839

3940
let f = x - 1.;
40-
let s = f/(2. + f);
41-
let z = s*s;
42-
let w = z*z;
43-
let t1 = w*(LG2+w*LG4);
44-
let t2 = z*(LG1+w*LG3);
41+
let s = f / (2. + f);
42+
let z = s * s;
43+
let w = z * z;
44+
let t1 = w * (LG2 + w * LG4);
45+
let t2 = z * (LG1 + w * LG3);
4546
let r = t2 + t1;
46-
let hfsq = 0.5*f*f;
47+
let hfsq = 0.5 * f * f;
4748
let dk = k as f32;
48-
s*(hfsq+r) + dk*LN2_LO - hfsq + f + dk*LN2_HI
49+
s * (hfsq + r) + dk * LN2_LO - hfsq + f + dk * LN2_HI
4950
}

src/math/mod.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,31 @@ macro_rules! force_eval {
77
}
88

99
mod ceilf;
10+
mod expf;
1011
mod fabs;
1112
mod fabsf;
13+
mod floor;
1214
mod floorf;
1315
mod fmodf;
16+
mod hypot;
17+
mod hypotf;
18+
mod logf;
1419
mod powf;
1520
mod round;
1621
mod roundf;
1722
mod scalbn;
1823
mod scalbnf;
1924
mod sqrt;
2025
mod sqrtf;
21-
mod logf;
22-
mod expf;
23-
mod floor;
2426
mod trunc;
2527
mod truncf;
26-
mod hypot;
27-
mod hypotf;
2828

2929
//mod service;
3030

3131
pub use self::{
32-
ceilf::ceilf,
33-
fabs::fabs,
34-
fabsf::fabsf,
35-
floorf::floorf,
36-
fmodf::fmodf,
37-
powf::powf,
38-
round::round,
39-
roundf::roundf,
40-
scalbn::scalbn,
41-
scalbnf::scalbnf,
42-
sqrt::sqrt,
43-
sqrtf::sqrtf,
44-
logf::logf,
45-
expf::expf,
46-
floor::floor,
47-
trunc::trunc,
48-
truncf::truncf,
49-
hypot::hypot,
50-
hypotf::hypotf,
32+
ceilf::ceilf, expf::expf, fabs::fabs, fabsf::fabsf, floor::floor, floorf::floorf, fmodf::fmodf,
33+
hypot::hypot, hypotf::hypotf, logf::logf, powf::powf, round::round, roundf::roundf,
34+
scalbn::scalbn, scalbnf::scalbnf, sqrt::sqrt, sqrtf::sqrtf, trunc::trunc, truncf::truncf,
5135
};
5236

5337
fn isnanf(x: f32) -> bool {

src/math/round.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn round(mut x: f64) -> f64 {
2626
} else {
2727
y = y + x;
2828
}
29-
29+
3030
if i >> 63 != 0 {
3131
-y
3232
} else {

0 commit comments

Comments
 (0)