Skip to content

Commit 2bcf540

Browse files
committed
Run the new version of rustfmt
1 parent 6cba99b commit 2bcf540

File tree

13 files changed

+746
-480
lines changed

13 files changed

+746
-480
lines changed

src/libcore/num/bignum.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
//! inputs, but we don't do so to avoid the code bloat. Each bignum is still
2020
//! tracked for the actual usages, so it normally doesn't matter.
2121
22-
// This module is only for dec2flt and flt2dec, and only public because of libcoretest.
22+
// This module is only for dec2flt and flt2dec, and only public because of
23+
// libcoretest.
2324
// It is not intended to ever be stabilized.
2425
#![doc(hidden)]
2526
#![unstable(feature = "core_private_bignum",
@@ -36,19 +37,22 @@ use intrinsics;
3637
pub trait FullOps {
3738
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self + other + carry`,
3839
/// where `W` is the number of bits in `Self`.
39-
fn full_add(self, other: Self, carry: bool) -> (bool /*carry*/, Self);
40+
fn full_add(self, other: Self, carry: bool) -> (bool /* carry */, Self);
4041

4142
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self * other + carry`,
4243
/// where `W` is the number of bits in `Self`.
43-
fn full_mul(self, other: Self, carry: Self) -> (Self /*carry*/, Self);
44+
fn full_mul(self, other: Self, carry: Self) -> (Self /* carry */, Self);
4445

4546
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self * other + other2 + carry`,
4647
/// where `W` is the number of bits in `Self`.
47-
fn full_mul_add(self, other: Self, other2: Self, carry: Self) -> (Self /*carry*/, Self);
48+
fn full_mul_add(self, other: Self, other2: Self, carry: Self) -> (Self /* carry */, Self);
4849

4950
/// Returns `(quo, rem)` such that `borrow * 2^W + self = quo * other + rem`
5051
/// and `0 <= rem < other`, where `W` is the number of bits in `Self`.
51-
fn full_div_rem(self, other: Self, borrow: Self) -> (Self /*quotient*/, Self /*remainder*/);
52+
fn full_div_rem(self,
53+
other: Self,
54+
borrow: Self)
55+
-> (Self /* quotient */, Self /* remainder */);
5256
}
5357

5458
macro_rules! impl_full_ops {

src/libcore/num/dec2flt/algorithm.rs

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use num::dec2flt::num::{self, Big};
2121
/// Number of significand bits in Fp
2222
const P: u32 = 64;
2323

24-
// We simply store the best approximation for *all* exponents, so the variable "h" and the
25-
// associated conditions can be omitted. This trades performance for a couple kilobytes of space.
24+
// We simply store the best approximation for *all* exponents, so the variable
25+
// "h" and the
26+
// associated conditions can be omitted. This trades performance for a couple
27+
// kilobytes of space.
2628

2729
fn power_of_ten(e: i16) -> Fp {
2830
assert!(e >= table::MIN_E);
@@ -47,8 +49,10 @@ fn power_of_ten(e: i16) -> Fp {
4749
/// FIXME: It would nevertheless be nice if we had a good way to detect and deal with x87.
4850
pub fn fast_path<T: RawFloat>(integral: &[u8], fractional: &[u8], e: i64) -> Option<T> {
4951
let num_digits = integral.len() + fractional.len();
50-
// log_10(f64::max_sig) ~ 15.95. We compare the exact value to max_sig near the end,
51-
// this is just a quick, cheap rejection (and also frees the rest of the code from
52+
// log_10(f64::max_sig) ~ 15.95. We compare the exact value to max_sig near the
53+
// end,
54+
// this is just a quick, cheap rejection (and also frees the rest of the code
55+
// from
5256
// worrying about underflow).
5357
if num_digits > 16 {
5458
return None;
@@ -130,16 +134,20 @@ fn algorithm_r<T: RawFloat>(f: &Big, e: i16, z0: T) -> T {
130134
let mut x = f.clone();
131135
let mut y = Big::from_u64(m);
132136

133-
// Find positive integers `x`, `y` such that `x / y` is exactly `(f * 10^e) / (m * 2^k)`.
134-
// This not only avoids dealing with the signs of `e` and `k`, we also eliminate the
137+
// Find positive integers `x`, `y` such that `x / y` is exactly `(f * 10^e) /
138+
// (m * 2^k)`.
139+
// This not only avoids dealing with the signs of `e` and `k`, we also
140+
// eliminate the
135141
// power of two common to `10^e` and `2^k` to make the numbers smaller.
136142
make_ratio(&mut x, &mut y, e, k);
137143

138144
let m_digits = [(m & 0xFF_FF_FF_FF) as u32, (m >> 32) as u32];
139145
// This is written a bit awkwardly because our bignums don't support
140146
// negative numbers, so we use the absolute value + sign information.
141-
// The multiplication with m_digits can't overflow. If `x` or `y` are large enough that
142-
// we need to worry about overflow, then they are also large enough that`make_ratio` has
147+
// The multiplication with m_digits can't overflow. If `x` or `y` are large
148+
// enough that
149+
// we need to worry about overflow, then they are also large enough
150+
// that`make_ratio` has
143151
// reduced the fraction by a factor of 2^64 or more.
144152
let (d2, d_negative) = if x >= y {
145153
// Don't need x any more, save a clone().
@@ -187,14 +195,17 @@ fn make_ratio(x: &mut Big, y: &mut Big, e: i16, k: i16) {
187195
let (e_abs, k_abs) = (e.abs() as usize, k.abs() as usize);
188196
if e >= 0 {
189197
if k >= 0 {
190-
// x = f * 10^e, y = m * 2^k, except that we reduce the fraction by some power of two.
198+
// x = f * 10^e, y = m * 2^k, except that we reduce the fraction by some power
199+
// of two.
191200
let common = min(e_abs, k_abs);
192201
x.mul_pow5(e_abs).mul_pow2(e_abs - common);
193202
y.mul_pow2(k_abs - common);
194203
} else {
195204
// x = f * 10^e * 2^abs(k), y = m
196-
// This can't overflow because it requires positive `e` and negative `k`, which can
197-
// only happen for values extremely close to 1, which means that `e` and `k` will be
205+
// This can't overflow because it requires positive `e` and negative `k`, which
206+
// can
207+
// only happen for values extremely close to 1, which means that `e` and `k`
208+
// will be
198209
// comparatively tiny.
199210
x.mul_pow5(e_abs).mul_pow2(e_abs + k_abs);
200211
}
@@ -239,7 +250,8 @@ pub fn algorithm_m<T: RawFloat>(f: &Big, e: i16) -> T {
239250
v = Big::from_small(1);
240251
v.mul_pow5(e_abs).mul_pow2(e_abs);
241252
} else {
242-
// FIXME possible optimization: generalize big_to_fp so that we can do the equivalent of
253+
// FIXME possible optimization: generalize big_to_fp so that we can do the
254+
// equivalent of
243255
// fp_to_float(big_to_fp(u)) here, only without the double rounding.
244256
u = f.clone();
245257
u.mul_pow5(e_abs).mul_pow2(e_abs);
@@ -253,10 +265,13 @@ pub fn algorithm_m<T: RawFloat>(f: &Big, e: i16) -> T {
253265
loop {
254266
u.div_rem(&v, &mut x, &mut rem);
255267
if k == T::min_exp_int() {
256-
// We have to stop at the minimum exponent, if we wait until `k < T::min_exp_int()`,
257-
// then we'd be off by a factor of two. Unfortunately this means we have to special-
268+
// We have to stop at the minimum exponent, if we wait until `k <
269+
// T::min_exp_int()`,
270+
// then we'd be off by a factor of two. Unfortunately this means we have to
271+
// special-
258272
// case normal numbers with the minimum exponent.
259-
// FIXME find a more elegant formulation, but run the `tiny-pow10` test to make sure
273+
// FIXME find a more elegant formulation, but run the `tiny-pow10` test to make
274+
// sure
260275
// that it's actually correct!
261276
if x >= min_sig && x <= max_sig {
262277
break;
@@ -283,13 +298,18 @@ pub fn algorithm_m<T: RawFloat>(f: &Big, e: i16) -> T {
283298

284299
/// Skip over most AlgorithmM iterations by checking the bit length.
285300
fn quick_start<T: RawFloat>(u: &mut Big, v: &mut Big, k: &mut i16) {
286-
// The bit length is an estimate of the base two logarithm, and log(u / v) = log(u) - log(v).
287-
// The estimate is off by at most 1, but always an under-estimate, so the error on log(u)
288-
// and log(v) are of the same sign and cancel out (if both are large). Therefore the error
301+
// The bit length is an estimate of the base two logarithm, and log(u / v) =
302+
// log(u) - log(v).
303+
// The estimate is off by at most 1, but always an under-estimate, so the error
304+
// on log(u)
305+
// and log(v) are of the same sign and cancel out (if both are large).
306+
// Therefore the error
289307
// for log(u / v) is at most one as well.
290-
// The target ratio is one where u/v is in an in-range significand. Thus our termination
308+
// The target ratio is one where u/v is in an in-range significand. Thus our
309+
// termination
291310
// condition is log2(u / v) being the significand bits, plus/minus one.
292-
// FIXME Looking at the second bit could improve the estimate and avoid some more divisions.
311+
// FIXME Looking at the second bit could improve the estimate and avoid some
312+
// more divisions.
293313
let target_ratio = f64::sig_bits() as i16;
294314
let log2_u = u.bit_length() as i16;
295315
let log2_v = v.bit_length() as i16;
@@ -326,8 +346,10 @@ fn underflow<T: RawFloat>(x: Big, v: Big, rem: Big) -> T {
326346
let z = rawfp::encode_subnormal(q);
327347
return round_by_remainder(v, rem, q, z);
328348
}
329-
// Ratio isn't an in-range significand with the minimum exponent, so we need to round off
330-
// excess bits and adjust the exponent accordingly. The real value now looks like this:
349+
// Ratio isn't an in-range significand with the minimum exponent, so we need to
350+
// round off
351+
// excess bits and adjust the exponent accordingly. The real value now looks
352+
// like this:
331353
//
332354
// x lsb
333355
// /--------------\/
@@ -336,8 +358,10 @@ fn underflow<T: RawFloat>(x: Big, v: Big, rem: Big) -> T {
336358
// q trunc. (represented by rem)
337359
//
338360
// Therefore, when the rounded-off bits are != 0.5 ULP, they decide the rounding
339-
// on their own. When they are equal and the remainder is non-zero, the value still
340-
// needs to be rounded up. Only when the rounded off bits are 1/2 and the remainer
361+
// on their own. When they are equal and the remainder is non-zero, the value
362+
// still
363+
// needs to be rounded up. Only when the rounded off bits are 1/2 and the
364+
// remainer
341365
// is zero, we have a half-to-even situation.
342366
let bits = x.bit_length();
343367
let lsb = bits - T::sig_bits() as usize;

0 commit comments

Comments
 (0)