Skip to content

run rustfmt on libcore/num folder #37123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/libcore/num/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ use intrinsics;
pub trait FullOps: Sized {
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self + other + carry`,
/// where `W` is the number of bits in `Self`.
fn full_add(self, other: Self, carry: bool) -> (bool /*carry*/, Self);
fn full_add(self, other: Self, carry: bool) -> (bool /* carry */, Self);

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

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

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

macro_rules! impl_full_ops {
Expand Down Expand Up @@ -100,11 +103,7 @@ impl_full_ops! {

/// Table of powers of 5 representable in digits. Specifically, the largest {u8, u16, u32} value
/// that's a power of five, plus the corresponding exponent. Used in `mul_pow5`.
const SMALL_POW5: [(u64, usize); 3] = [
(125, 3),
(15625, 6),
(1_220_703_125, 13),
];
const SMALL_POW5: [(u64, usize); 3] = [(125, 3), (15625, 6), (1_220_703_125, 13)];

macro_rules! define_bignum {
($name:ident: type=$ty:ty, n=$n:expr) => (
Expand Down
35 changes: 28 additions & 7 deletions src/libcore/num/diy_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,30 @@ impl Fp {
pub fn normalize(&self) -> Fp {
let mut f = self.f;
let mut e = self.e;
if f >> (64 - 32) == 0 { f <<= 32; e -= 32; }
if f >> (64 - 16) == 0 { f <<= 16; e -= 16; }
if f >> (64 - 8) == 0 { f <<= 8; e -= 8; }
if f >> (64 - 4) == 0 { f <<= 4; e -= 4; }
if f >> (64 - 2) == 0 { f <<= 2; e -= 2; }
if f >> (64 - 1) == 0 { f <<= 1; e -= 1; }
if f >> (64 - 32) == 0 {
f <<= 32;
e -= 32;
}
if f >> (64 - 16) == 0 {
f <<= 16;
e -= 16;
}
if f >> (64 - 8) == 0 {
f <<= 8;
e -= 8;
}
if f >> (64 - 4) == 0 {
f <<= 4;
e -= 4;
}
if f >> (64 - 2) == 0 {
f <<= 2;
e -= 2;
}
if f >> (64 - 1) == 0 {
f <<= 1;
e -= 1;
}
debug_assert!(f >= (1 >> 63));
Fp { f: f, e: e }
}
Expand All @@ -66,6 +84,9 @@ impl Fp {
assert!(edelta >= 0);
let edelta = edelta as usize;
assert_eq!(self.f << edelta >> edelta, self.f);
Fp { f: self.f << edelta, e: e }
Fp {
f: self.f << edelta,
e: e,
}
}
}
48 changes: 33 additions & 15 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub const MAX_10_EXP: i32 = 38;

/// Not a Number (NaN).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f32 = 0.0_f32/0.0_f32;
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
/// Infinity (∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f32 = 1.0_f32/0.0_f32;
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
/// Negative infinity (-∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -144,26 +144,40 @@ pub mod consts {
issue = "32110")]
impl Float for f32 {
#[inline]
fn nan() -> f32 { NAN }
fn nan() -> f32 {
NAN
}

#[inline]
fn infinity() -> f32 { INFINITY }
fn infinity() -> f32 {
INFINITY
}

#[inline]
fn neg_infinity() -> f32 { NEG_INFINITY }
fn neg_infinity() -> f32 {
NEG_INFINITY
}

#[inline]
fn zero() -> f32 { 0.0 }
fn zero() -> f32 {
0.0
}

#[inline]
fn neg_zero() -> f32 { -0.0 }
fn neg_zero() -> f32 {
-0.0
}

#[inline]
fn one() -> f32 { 1.0 }
fn one() -> f32 {
1.0
}

/// Returns `true` if the number is NaN.
#[inline]
fn is_nan(self) -> bool { self != self }
fn is_nan(self) -> bool {
self != self
}

/// Returns `true` if the number is infinite.
#[inline]
Expand Down Expand Up @@ -192,11 +206,11 @@ impl Float for f32 {

let bits: u32 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {
(0, 0) => Fp::Zero,
(_, 0) => Fp::Subnormal,
(0, 0) => Fp::Zero,
(_, 0) => Fp::Subnormal,
(0, EXP_MASK) => Fp::Infinite,
(_, EXP_MASK) => Fp::Nan,
_ => Fp::Normal,
_ => Fp::Normal,
}
}

Expand Down Expand Up @@ -252,7 +266,9 @@ impl Float for f32 {

/// Returns the reciprocal (multiplicative inverse) of the number.
#[inline]
fn recip(self) -> f32 { 1.0 / self }
fn recip(self) -> f32 {
1.0 / self
}

#[inline]
fn powi(self, n: i32) -> f32 {
Expand All @@ -261,7 +277,9 @@ impl Float for f32 {

/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f32 { self * (180.0f32 / consts::PI) }
fn to_degrees(self) -> f32 {
self * (180.0f32 / consts::PI)
}

/// Converts to radians, assuming the number is in degrees.
#[inline]
Expand Down
48 changes: 33 additions & 15 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub const MAX_10_EXP: i32 = 308;

/// Not a Number (NaN).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f64 = 0.0_f64/0.0_f64;
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
/// Infinity (∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f64 = 1.0_f64/0.0_f64;
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
/// Negative infinity (-∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -144,26 +144,40 @@ pub mod consts {
issue = "32110")]
impl Float for f64 {
#[inline]
fn nan() -> f64 { NAN }
fn nan() -> f64 {
NAN
}

#[inline]
fn infinity() -> f64 { INFINITY }
fn infinity() -> f64 {
INFINITY
}

#[inline]
fn neg_infinity() -> f64 { NEG_INFINITY }
fn neg_infinity() -> f64 {
NEG_INFINITY
}

#[inline]
fn zero() -> f64 { 0.0 }
fn zero() -> f64 {
0.0
}

#[inline]
fn neg_zero() -> f64 { -0.0 }
fn neg_zero() -> f64 {
-0.0
}

#[inline]
fn one() -> f64 { 1.0 }
fn one() -> f64 {
1.0
}

/// Returns `true` if the number is NaN.
#[inline]
fn is_nan(self) -> bool { self != self }
fn is_nan(self) -> bool {
self != self
}

/// Returns `true` if the number is infinite.
#[inline]
Expand Down Expand Up @@ -192,11 +206,11 @@ impl Float for f64 {

let bits: u64 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {
(0, 0) => Fp::Zero,
(_, 0) => Fp::Subnormal,
(0, 0) => Fp::Zero,
(_, 0) => Fp::Subnormal,
(0, EXP_MASK) => Fp::Infinite,
(_, EXP_MASK) => Fp::Nan,
_ => Fp::Normal,
_ => Fp::Normal,
}
}

Expand Down Expand Up @@ -252,7 +266,9 @@ impl Float for f64 {

/// Returns the reciprocal (multiplicative inverse) of the number.
#[inline]
fn recip(self) -> f64 { 1.0 / self }
fn recip(self) -> f64 {
1.0 / self
}

#[inline]
fn powi(self, n: i32) -> f64 {
Expand All @@ -261,7 +277,9 @@ impl Float for f64 {

/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f64 { self * (180.0f64 / consts::PI) }
fn to_degrees(self) -> f64 {
self * (180.0f64 / consts::PI)
}

/// Converts to radians, assuming the number is in degrees.
#[inline]
Expand Down
14 changes: 8 additions & 6 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ use str::FromStr;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")]
pub T);

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
Expand Down Expand Up @@ -2402,7 +2403,7 @@ pub enum FpCategory {

/// Positive or negative infinity.
#[stable(feature = "rust1", since = "1.0.0")]
Infinite ,
Infinite,

/// Positive or negative zero.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -2662,8 +2663,7 @@ macro_rules! doit {
}
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }

fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
-> Result<T, ParseIntError> {
fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, ParseIntError> {
use self::IntErrorKind::*;
use self::ParseIntError as PIE;

Expand All @@ -2686,7 +2686,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
let (is_positive, digits) = match src[0] {
b'+' => (true, &src[1..]),
b'-' if is_signed_ty => (false, &src[1..]),
_ => (true, src)
_ => (true, src),
};

if digits.is_empty() {
Expand Down Expand Up @@ -2738,7 +2738,9 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
/// [`i8::from_str_radix()`]: ../../std/primitive.i8.html#method.from_str_radix
#[derive(Debug, Clone, PartialEq, Eq)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseIntError { kind: IntErrorKind }
pub struct ParseIntError {
kind: IntErrorKind,
}

#[derive(Debug, Clone, PartialEq, Eq)]
enum IntErrorKind {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ mod shift_max {
pub const isize: u32 = super::i64;
}

pub const i8: u32 = (1 << 3) - 1;
pub const i8: u32 = (1 << 3) - 1;
pub const i16: u32 = (1 << 4) - 1;
pub const i32: u32 = (1 << 5) - 1;
pub const i64: u32 = (1 << 6) - 1;
pub use self::platform::isize;

pub const u8: u32 = i8;
pub const u8: u32 = i8;
pub const u16: u32 = i16;
pub const u32: u32 = i32;
pub const u64: u32 = i64;
Expand Down