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 {
/// 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) => (
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 }
}
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,
+ }
}
}
/// 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")]
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]
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,
}
}
/// 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 {
/// 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]
/// 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")]
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]
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,
}
}
/// 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 {
/// 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]
/// ```
#[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> {
/// Positive or negative infinity.
#[stable(feature = "rust1", since = "1.0.0")]
- Infinite ,
+ Infinite,
/// Positive or negative zero.
#[stable(feature = "rust1", since = "1.0.0")]
}
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;
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() {
/// [`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 {
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;