run rustfmt on libcore/num folder

This commit is contained in:
Srinivas Reddy Thatiparthy 2016-10-12 23:57:46 +05:30
parent acb50e3481
commit 5457c35ece
No known key found for this signature in database
GPG Key ID: 091C58F4BFC36571
6 changed files with 112 additions and 54 deletions

View File

@ -34,19 +34,22 @@
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 {
@ -100,11 +103,7 @@ fn full_div_rem(self, other: $ty, borrow: $ty) -> ($ty, $ty) {
/// 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) => (

View File

@ -49,12 +49,30 @@ pub fn mul(&self, other: &Fp) -> 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 }
}
@ -66,6 +84,9 @@ pub fn normalize_to(&self, e: i16) -> 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,
}
}
}

View File

@ -61,13 +61,13 @@
/// 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")]
@ -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]
@ -192,11 +206,11 @@ fn classify(self) -> Fp {
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,
}
}
@ -252,7 +266,9 @@ fn is_sign_negative(self) -> bool {
/// 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 {
@ -261,7 +277,9 @@ fn powi(self, n: i32) -> 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]

View File

@ -61,13 +61,13 @@
/// 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")]
@ -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]
@ -192,11 +206,11 @@ fn classify(self) -> Fp {
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,
}
}
@ -252,7 +266,9 @@ fn is_sign_negative(self) -> bool {
/// 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 {
@ -261,7 +277,9 @@ fn powi(self, n: i32) -> 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]

View File

@ -43,7 +43,8 @@
/// ```
#[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> {
@ -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")]
@ -2662,8 +2663,7 @@ fn checked_add(&self, other: u32) -> Option<Self> {
}
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;
@ -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() {
@ -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 {

View File

@ -310,13 +310,13 @@ mod platform {
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;