mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 18:15:01 +00:00
rollup merge of #23549: aturon/stab-num
This commit stabilizes the `std::num` module: * The `Int` and `Float` traits are deprecated in favor of (1) the newly-added inherent methods and (2) the generic traits available in rust-lang/num. * The `Zero` and `One` traits are reintroduced in `std::num`, which together with various other traits allow you to recover the most common forms of generic programming. * The `FromStrRadix` trait, and associated free function, is deprecated in favor of inherent implementations. * A wide range of methods and constants for both integers and floating point numbers are now `#[stable]`, having been adjusted for integer guidelines. * `is_positive` and `is_negative` are renamed to `is_sign_positive` and `is_sign_negative`, in order to address #22985 * The `Wrapping` type is moved to `std::num` and stabilized; `WrappingOps` is deprecated in favor of inherent methods on the integer types, and direct implementation of operations on `Wrapping<X>` for each concrete integer type `X`. Closes #22985 Closes #21069 [breaking-change] r? @alexcrichton
This commit is contained in:
commit
5d0beb7d85
@ -189,7 +189,6 @@ mod imp {
|
||||
use core::option::Option;
|
||||
use core::option::Option::None;
|
||||
use core::ptr::{null_mut, null};
|
||||
use core::num::Int;
|
||||
use libc::{c_char, c_int, c_void, size_t};
|
||||
use super::MIN_ALIGN;
|
||||
|
||||
|
@ -91,7 +91,6 @@ use core::hash;
|
||||
use core::iter::RandomAccessIterator;
|
||||
use core::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat, Cloned};
|
||||
use core::iter::{self, FromIterator, IntoIterator};
|
||||
use core::num::Int;
|
||||
use core::ops::Index;
|
||||
use core::slice;
|
||||
use core::{u8, u32, usize};
|
||||
|
@ -16,7 +16,6 @@
|
||||
use core::prelude::*;
|
||||
use core::marker;
|
||||
use core::fmt;
|
||||
use core::num::Int;
|
||||
use core::iter::{FromIterator, IntoIterator};
|
||||
use core::ops::{Sub, BitOr, BitAnd, BitXor};
|
||||
|
||||
|
@ -89,6 +89,7 @@ use core::iter::MultiplicativeIterator;
|
||||
use core::marker::Sized;
|
||||
use core::mem::size_of;
|
||||
use core::mem;
|
||||
#[cfg(stage0)]
|
||||
use core::num::wrapping::WrappingOps;
|
||||
use core::ops::FnMut;
|
||||
use core::option::Option::{self, Some, None};
|
||||
|
@ -18,9 +18,6 @@
|
||||
//! (see below). It is not possible to move out of borrowed strings because they
|
||||
//! are owned elsewhere.
|
||||
//!
|
||||
//! Basic operations are implemented directly by the compiler, but more advanced
|
||||
//! operations are defined as methods on the `str` type.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! Here's some code that uses a `&str`:
|
||||
|
@ -25,6 +25,7 @@ use core::default::Default;
|
||||
use core::fmt;
|
||||
use core::iter::{self, repeat, FromIterator, IntoIterator, RandomAccessIterator};
|
||||
use core::mem;
|
||||
#[cfg(stage0)]
|
||||
use core::num::wrapping::WrappingOps;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::ptr::{self, Unique};
|
||||
|
@ -20,8 +20,6 @@
|
||||
//!
|
||||
//! ```
|
||||
//! # #![feature(core)]
|
||||
//! use std::num::SignedInt;
|
||||
//!
|
||||
//! struct FuzzyNum {
|
||||
//! num: i32,
|
||||
//! }
|
||||
|
@ -33,6 +33,7 @@ trait GenericRadix {
|
||||
fn digit(&self, x: u8) -> u8;
|
||||
|
||||
/// Format an integer using the radix using a formatter.
|
||||
#[allow(deprecated)] // Int
|
||||
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// The radix can be as low as 2, so we need a buffer of at least 64
|
||||
// characters for a base 2 number.
|
||||
|
@ -12,9 +12,10 @@
|
||||
|
||||
//! An implementation of SipHash 2-4.
|
||||
|
||||
#![allow(deprecated)] // until the next snapshot for inherent wrapping ops
|
||||
|
||||
use prelude::*;
|
||||
use default::Default;
|
||||
use num::wrapping::WrappingOps;
|
||||
use super::Hasher;
|
||||
|
||||
/// An implementation of SipHash 2-4.
|
||||
@ -71,7 +72,7 @@ macro_rules! u8to64_le {
|
||||
|
||||
macro_rules! rotl {
|
||||
($x:expr, $b:expr) =>
|
||||
(($x << $b) | ($x >> (64.wrapping_sub($b))))
|
||||
(($x << $b) | ($x >> (64_i32.wrapping_sub($b))))
|
||||
}
|
||||
|
||||
macro_rules! compress {
|
||||
|
@ -64,8 +64,8 @@ use cmp::Ord;
|
||||
use default::Default;
|
||||
use marker;
|
||||
use mem;
|
||||
use num::{ToPrimitive, Int};
|
||||
use ops::{Add, FnMut, RangeFrom};
|
||||
use num::{Int, Zero, One, ToPrimitive};
|
||||
use ops::{Add, Sub, FnMut, RangeFrom};
|
||||
use option::Option;
|
||||
use option::Option::{Some, None};
|
||||
use marker::Sized;
|
||||
@ -843,9 +843,8 @@ pub trait Iterator {
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(core)]
|
||||
/// use std::num::SignedInt;
|
||||
///
|
||||
/// let a = [-3, 0, 1, 5, -10];
|
||||
/// let a = [-3_i32, 0, 1, 5, -10];
|
||||
/// assert_eq!(*a.iter().max_by(|x| x.abs()).unwrap(), -10);
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -875,9 +874,8 @@ pub trait Iterator {
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(core)]
|
||||
/// use std::num::SignedInt;
|
||||
///
|
||||
/// let a = [-3, 0, 1, 5, -10];
|
||||
/// let a = [-3_i32, 0, 1, 5, -10];
|
||||
/// assert_eq!(*a.iter().min_by(|x| x.abs()).unwrap(), 0);
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -2417,6 +2415,67 @@ impl<A, St, F> Iterator for Unfold<St, F> where F: FnMut(&mut St) -> Option<A> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Objects that can be stepped over in both directions.
|
||||
///
|
||||
/// The `steps_between` function provides a way to efficiently compare
|
||||
/// two `Step` objects.
|
||||
#[unstable(feature = "step_trait",
|
||||
reason = "likely to be replaced by finer-grained traits")]
|
||||
pub trait Step: Ord {
|
||||
/// Steps `self` if possible.
|
||||
fn step(&self, by: &Self) -> Option<Self>;
|
||||
|
||||
/// The number of steps between two step objects.
|
||||
///
|
||||
/// `start` should always be less than `end`, so the result should never
|
||||
/// be negative.
|
||||
///
|
||||
/// Return `None` if it is not possible to calculate steps_between
|
||||
/// without overflow.
|
||||
fn steps_between(start: &Self, end: &Self, by: &Self) -> Option<usize>;
|
||||
}
|
||||
|
||||
macro_rules! step_impl {
|
||||
($($t:ty)*) => ($(
|
||||
impl Step for $t {
|
||||
#[inline]
|
||||
fn step(&self, by: &$t) -> Option<$t> {
|
||||
(*self).checked_add(*by)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(trivial_numeric_casts)]
|
||||
fn steps_between(start: &$t, end: &$t, by: &$t) -> Option<usize> {
|
||||
if *start <= *end {
|
||||
Some(((*end - *start) / *by) as usize)
|
||||
} else {
|
||||
Some(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
macro_rules! step_impl_no_between {
|
||||
($($t:ty)*) => ($(
|
||||
impl Step for $t {
|
||||
#[inline]
|
||||
fn step(&self, by: &$t) -> Option<$t> {
|
||||
(*self).checked_add(*by)
|
||||
}
|
||||
#[inline]
|
||||
fn steps_between(_a: &$t, _b: &$t, _by: &$t) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
step_impl!(usize u8 u16 u32 isize i8 i16 i32);
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
step_impl!(u64 i64);
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
step_impl_no_between!(u64 i64);
|
||||
|
||||
/// An adapter for stepping range iterators by a custom amount.
|
||||
///
|
||||
/// The resulting iterator handles overflow by stopping. The `A`
|
||||
@ -2429,7 +2488,7 @@ pub struct StepBy<A, R> {
|
||||
range: R,
|
||||
}
|
||||
|
||||
impl<A: Add> RangeFrom<A> {
|
||||
impl<A: Step> RangeFrom<A> {
|
||||
/// Creates an iterator starting at the same point, but stepping by
|
||||
/// the given amount at each iteration.
|
||||
///
|
||||
@ -2451,7 +2510,8 @@ impl<A: Add> RangeFrom<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Int> ::ops::Range<A> {
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step> ::ops::Range<A> {
|
||||
/// Creates an iterator with the same range, but stepping by the
|
||||
/// given amount at each iteration.
|
||||
///
|
||||
@ -2505,14 +2565,17 @@ pub fn count<A>(start: A, step: A) -> Counter<A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Add<Output=A> + Clone> Iterator for StepBy<A, RangeFrom<A>> {
|
||||
impl<A> Iterator for StepBy<A, RangeFrom<A>> where
|
||||
A: Clone,
|
||||
for<'a> &'a A: Add<&'a A, Output = A>
|
||||
{
|
||||
type Item = A;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
let result = self.range.start.clone();
|
||||
self.range.start = result.clone() + self.step_by.clone();
|
||||
Some(result)
|
||||
let mut n = &self.range.start + &self.step_by;
|
||||
mem::swap(&mut n, &mut self.range.start);
|
||||
Some(n)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -2715,19 +2778,27 @@ pub fn range_step<A: Int>(start: A, stop: A, step: A) -> RangeStep<A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Int> Iterator for StepBy<A, ::ops::Range<A>> {
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + Zero + Clone> Iterator for StepBy<A, ::ops::Range<A>> {
|
||||
type Item = A;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
let rev = self.step_by < Int::zero();
|
||||
let start = self.range.start;
|
||||
if (rev && start > self.range.end) || (!rev && start < self.range.end) {
|
||||
match start.checked_add(self.step_by) {
|
||||
Some(x) => self.range.start = x,
|
||||
None => self.range.start = self.range.end.clone()
|
||||
let rev = self.step_by < A::zero();
|
||||
if (rev && self.range.start > self.range.end) ||
|
||||
(!rev && self.range.start < self.range.end)
|
||||
{
|
||||
match self.range.start.step(&self.step_by) {
|
||||
Some(mut n) => {
|
||||
mem::swap(&mut self.range.start, &mut n);
|
||||
Some(n)
|
||||
},
|
||||
None => {
|
||||
let mut n = self.range.end.clone();
|
||||
mem::swap(&mut self.range.start, &mut n);
|
||||
Some(n)
|
||||
}
|
||||
}
|
||||
Some(start)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -2774,6 +2845,7 @@ pub struct RangeStepInclusive<A> {
|
||||
#[inline]
|
||||
#[unstable(feature = "core",
|
||||
reason = "likely to be replaced by range notation and adapters")]
|
||||
#[allow(deprecated)]
|
||||
pub fn range_step_inclusive<A: Int>(start: A, stop: A, step: A) -> RangeStepInclusive<A> {
|
||||
let rev = step < Int::zero();
|
||||
RangeStepInclusive {
|
||||
@ -2787,6 +2859,7 @@ pub fn range_step_inclusive<A: Int>(start: A, stop: A, step: A) -> RangeStepIncl
|
||||
|
||||
#[unstable(feature = "core",
|
||||
reason = "likely to be replaced by range notation and adapters")]
|
||||
#[allow(deprecated)]
|
||||
impl<A: Int> Iterator for RangeStepInclusive<A> {
|
||||
type Item = A;
|
||||
|
||||
@ -2814,15 +2887,25 @@ macro_rules! range_exact_iter_impl {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Int> Iterator for ::ops::Range<A> {
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + One + Clone> Iterator for ::ops::Range<A> {
|
||||
type Item = A;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
if self.start < self.end {
|
||||
let result = self.start;
|
||||
self.start = self.start + Int::one();
|
||||
Some(result)
|
||||
match self.start.step(&A::one()) {
|
||||
Some(mut n) => {
|
||||
mem::swap(&mut n, &mut self.start);
|
||||
Some(n)
|
||||
},
|
||||
None => {
|
||||
let mut n = self.end.clone();
|
||||
mem::swap(&mut n, &mut self.start);
|
||||
Some(n)
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -2830,11 +2913,10 @@ impl<A: Int> Iterator for ::ops::Range<A> {
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
if self.start >= self.end {
|
||||
(0, Some(0))
|
||||
if let Some(hint) = Step::steps_between(&self.start, &self.end, &A::one()) {
|
||||
(hint, Some(hint))
|
||||
} else {
|
||||
let length = (self.end - self.start).to_usize();
|
||||
(length.unwrap_or(0), length)
|
||||
(0, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2844,12 +2926,15 @@ impl<A: Int> Iterator for ::ops::Range<A> {
|
||||
range_exact_iter_impl!(usize u8 u16 u32 isize i8 i16 i32);
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Int> DoubleEndedIterator for ::ops::Range<A> {
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + One + Clone> DoubleEndedIterator for ::ops::Range<A> where
|
||||
for<'a> &'a A: Sub<&'a A, Output = A>
|
||||
{
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<A> {
|
||||
if self.start < self.end {
|
||||
self.end = self.end - Int::one();
|
||||
Some(self.end)
|
||||
self.end = &self.end - &A::one();
|
||||
Some(self.end.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -2857,15 +2942,16 @@ impl<A: Int> DoubleEndedIterator for ::ops::Range<A> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: Int> Iterator for ::ops::RangeFrom<A> {
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + One> Iterator for ::ops::RangeFrom<A> {
|
||||
type Item = A;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
let result = self.start;
|
||||
self.start = self.start + Int::one();
|
||||
debug_assert!(result < self.start);
|
||||
Some(result)
|
||||
self.start.step(&A::one()).map(|mut n| {
|
||||
mem::swap(&mut n, &mut self.start);
|
||||
n
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,12 @@ use num::Float;
|
||||
use num::FpCategory as Fp;
|
||||
use option::Option;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const RADIX: u32 = 2;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MANTISSA_DIGITS: u32 = 24;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const DIGITS: u32 = 6;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -56,14 +56,14 @@ pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX: f32 = 3.40282347e+38_f32;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MIN_EXP: i32 = -125;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX_EXP: i32 = 128;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MIN_10_EXP: i32 = -37;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX_10_EXP: i32 = 38;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -73,61 +73,89 @@ pub const INFINITY: f32 = 1.0_f32/0.0_f32;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
|
||||
|
||||
/// Various useful constants.
|
||||
#[unstable(feature = "core",
|
||||
reason = "naming scheme needs to be revisited")]
|
||||
/// Basic mathematial constants.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub mod consts {
|
||||
// FIXME: replace with mathematical constants from cmath.
|
||||
|
||||
/// Archimedes' constant
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const PI: f32 = 3.14159265358979323846264338327950288_f32;
|
||||
|
||||
/// pi * 2.0
|
||||
#[unstable(feature = "core", reason = "unclear naming convention/usefulness")]
|
||||
pub const PI_2: f32 = 6.28318530717958647692528676655900576_f32;
|
||||
|
||||
/// pi/2.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32;
|
||||
|
||||
/// pi/3.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32;
|
||||
|
||||
/// pi/4.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32;
|
||||
|
||||
/// pi/6.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32;
|
||||
|
||||
/// pi/8.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32;
|
||||
|
||||
/// 1.0/pi
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32;
|
||||
|
||||
/// 2.0/pi
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32;
|
||||
|
||||
/// 2.0/sqrt(pi)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_2_SQRT_PI: f32 = 1.12837916709551257389615890312154517_f32;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to FRAC_2_SQRT_PI")]
|
||||
pub const FRAC_2_SQRTPI: f32 = 1.12837916709551257389615890312154517_f32;
|
||||
|
||||
/// sqrt(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const SQRT_2: f32 = 1.41421356237309504880168872420969808_f32;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to SQRT_2")]
|
||||
pub const SQRT2: f32 = 1.41421356237309504880168872420969808_f32;
|
||||
|
||||
/// 1.0/sqrt(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_1_SQRT_2: f32 = 0.707106781186547524400844362104849039_f32;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to FRAC_1_SQRT_2")]
|
||||
pub const FRAC_1_SQRT2: f32 = 0.707106781186547524400844362104849039_f32;
|
||||
|
||||
/// Euler's number
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const E: f32 = 2.71828182845904523536028747135266250_f32;
|
||||
|
||||
/// log2(e)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LOG2_E: f32 = 1.44269504088896340735992468100189214_f32;
|
||||
|
||||
/// log10(e)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LOG10_E: f32 = 0.434294481903251827651128918916605082_f32;
|
||||
|
||||
/// ln(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LN_2: f32 = 0.693147180559945309417232121458176568_f32;
|
||||
|
||||
/// ln(10.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32;
|
||||
}
|
||||
|
||||
|
@ -22,15 +22,12 @@ use num::Float;
|
||||
use num::FpCategory as Fp;
|
||||
use option::Option;
|
||||
|
||||
// FIXME(#5527): These constants should be deprecated once associated
|
||||
// constants are implemented in favour of referencing the respective
|
||||
// members of `Bounded` and `Float`.
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const RADIX: u32 = 2;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MANTISSA_DIGITS: u32 = 53;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const DIGITS: u32 = 15;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -59,14 +56,14 @@ pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX: f64 = 1.7976931348623157e+308_f64;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MIN_EXP: i32 = -1021;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX_EXP: i32 = 1024;
|
||||
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MIN_10_EXP: i32 = -307;
|
||||
#[unstable(feature = "core", reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const MAX_10_EXP: i32 = 308;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -76,65 +73,89 @@ pub const INFINITY: f64 = 1.0_f64/0.0_f64;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
|
||||
|
||||
/// Various useful constants.
|
||||
#[unstable(feature = "core",
|
||||
reason = "naming scheme needs to be revisited")]
|
||||
/// Basic mathematial constants.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub mod consts {
|
||||
// FIXME: replace with mathematical constants from cmath.
|
||||
|
||||
// FIXME(#5527): These constants should be deprecated once associated
|
||||
// constants are implemented in favour of referencing the respective members
|
||||
// of `Float`.
|
||||
|
||||
/// Archimedes' constant
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const PI: f64 = 3.14159265358979323846264338327950288_f64;
|
||||
|
||||
/// pi * 2.0
|
||||
#[unstable(feature = "core", reason = "unclear naming convention/usefulness")]
|
||||
pub const PI_2: f64 = 6.28318530717958647692528676655900576_f64;
|
||||
|
||||
/// pi/2.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
|
||||
|
||||
/// pi/3.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64;
|
||||
|
||||
/// pi/4.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64;
|
||||
|
||||
/// pi/6.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64;
|
||||
|
||||
/// pi/8.0
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64;
|
||||
|
||||
/// 1.0/pi
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64;
|
||||
|
||||
/// 2.0/pi
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;
|
||||
|
||||
/// 2.0/sqrt(pi)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_2_SQRT_PI: f64 = 1.12837916709551257389615890312154517_f64;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to FRAC_2_SQRT_PI")]
|
||||
pub const FRAC_2_SQRTPI: f64 = 1.12837916709551257389615890312154517_f64;
|
||||
|
||||
/// sqrt(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const SQRT_2: f64 = 1.41421356237309504880168872420969808_f64;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to SQRT_2")]
|
||||
pub const SQRT2: f64 = 1.41421356237309504880168872420969808_f64;
|
||||
|
||||
/// 1.0/sqrt(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const FRAC_1_SQRT_2: f64 = 0.707106781186547524400844362104849039_f64;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to FRAC_1_SQRT_2")]
|
||||
pub const FRAC_1_SQRT2: f64 = 0.707106781186547524400844362104849039_f64;
|
||||
|
||||
/// Euler's number
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const E: f64 = 2.71828182845904523536028747135266250_f64;
|
||||
|
||||
/// log2(e)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LOG2_E: f64 = 1.44269504088896340735992468100189214_f64;
|
||||
|
||||
/// log10(e)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LOG10_E: f64 = 0.434294481903251827651128918916605082_f64;
|
||||
|
||||
/// ln(2.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LN_2: f64 = 0.693147180559945309417232121458176568_f64;
|
||||
|
||||
/// ln(10.0)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,66 @@ use option::Option::{self, Some, None};
|
||||
use result::Result::{self, Ok, Err};
|
||||
use str::{FromStr, StrExt};
|
||||
|
||||
/// Provides intentionally-wrapped arithmetic on `T`.
|
||||
///
|
||||
/// Operations like `+` on `u32` values is intended to never overflow,
|
||||
/// and in some debug configurations overflow is detected and results
|
||||
/// in a panic. While most arithmetic falls into this category, some
|
||||
/// code explicitly expects and relies upon modular arithmetic (e.g.,
|
||||
/// hashing).
|
||||
///
|
||||
/// Wrapping arithmetic can be achieved either through methods like
|
||||
/// `wrapping_add`, or through the `Wrapping<T>` type, which says that
|
||||
/// all standard arithmetic operations on the underlying value are
|
||||
/// intended to have wrapping semantics.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
|
||||
pub struct Wrapping<T>(pub T);
|
||||
|
||||
#[unstable(feature = "core", reason = "may be removed or relocated")]
|
||||
pub mod wrapping;
|
||||
|
||||
/// Types that have a "zero" value.
|
||||
///
|
||||
/// This trait is intended for use in conjunction with `Add`, as an identity:
|
||||
/// `x + T::zero() == x`.
|
||||
#[unstable(feature = "zero_one",
|
||||
reason = "unsure of placement, wants to use associated constants")]
|
||||
pub trait Zero {
|
||||
/// The "zero" (usually, additive identity) for this type.
|
||||
fn zero() -> Self;
|
||||
}
|
||||
|
||||
/// Types that have a "one" value.
|
||||
///
|
||||
/// This trait is intended for use in conjunction with `Mul`, as an identity:
|
||||
/// `x * T::one() == x`.
|
||||
#[unstable(feature = "zero_one",
|
||||
reason = "unsure of placement, wants to use associated constants")]
|
||||
pub trait One {
|
||||
/// The "one" (usually, multiplicative identity) for this type.
|
||||
fn one() -> Self;
|
||||
}
|
||||
|
||||
macro_rules! zero_one_impl {
|
||||
($($t:ty)*) => ($(
|
||||
impl Zero for $t {
|
||||
#[inline]
|
||||
fn zero() -> $t { 0 }
|
||||
}
|
||||
impl One for $t {
|
||||
#[inline]
|
||||
fn one() -> $t { 1 }
|
||||
}
|
||||
)*)
|
||||
}
|
||||
zero_one_impl! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
||||
|
||||
/// A built-in signed or unsigned integer.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "replaced by inherent methods; for generics, use rust-lang/num")]
|
||||
#[allow(deprecated)]
|
||||
pub trait Int
|
||||
: Copy + Clone
|
||||
+ NumCast
|
||||
@ -450,6 +505,7 @@ macro_rules! uint_impl {
|
||||
$sub_with_overflow:path,
|
||||
$mul_with_overflow:path) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl Int for $T {
|
||||
#[inline]
|
||||
fn zero() -> $T { 0 }
|
||||
@ -589,6 +645,7 @@ macro_rules! int_impl {
|
||||
$sub_with_overflow:path,
|
||||
$mul_with_overflow:path) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl Int for $T {
|
||||
#[inline]
|
||||
fn zero() -> $T { 0 }
|
||||
@ -692,6 +749,9 @@ int_impl! { isize = i64, u64, 64,
|
||||
|
||||
/// A built-in two's complement integer.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "replaced by inherent methods; for generics, use rust-lang/num")]
|
||||
#[allow(deprecated)]
|
||||
pub trait SignedInt
|
||||
: Int
|
||||
+ Neg<Output=Self>
|
||||
@ -723,6 +783,7 @@ pub trait SignedInt
|
||||
macro_rules! signed_int_impl {
|
||||
($T:ty) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl SignedInt for $T {
|
||||
#[inline]
|
||||
fn abs(self) -> $T {
|
||||
@ -759,35 +820,25 @@ macro_rules! int_impl {
|
||||
$add_with_overflow:path,
|
||||
$sub_with_overflow:path,
|
||||
$mul_with_overflow:path) => {
|
||||
/// Returns the `0` value of this integer type.
|
||||
// FIXME (#5527): Should be an associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn zero() -> $T { 0 }
|
||||
|
||||
/// Returns the `1` value of this integer type.
|
||||
// FIXME (#5527): Should be an associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn one() -> $T { 1 }
|
||||
|
||||
/// Returns the smallest value that can be represented by this integer
|
||||
/// type.
|
||||
// FIXME (#5527): Should be and associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn min_value() -> $T { (-1 as $T) << ($BITS - 1) }
|
||||
|
||||
/// Returns the largest value that can be represented by this integer
|
||||
/// type.
|
||||
// FIXME (#5527): Should be and associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn max_value() -> $T { let min: $T = <$T>::min_value(); !min }
|
||||
/// Convert a string slice in a given base to an integer.
|
||||
///
|
||||
/// Leading and trailing whitespace represent an error.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * src - A string slice
|
||||
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// `None` if the string did not represent a valid number.
|
||||
/// Otherwise, `Some(n)` where `n` is the integer represented
|
||||
/// by `src`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
pub fn from_str_radix(src: &str, radix: u32) -> Result<$T, ParseIntError> {
|
||||
<Self as FromStrRadix>::from_str_radix(src, radix)
|
||||
}
|
||||
|
||||
/// Returns the number of ones in the binary representation of `self`.
|
||||
///
|
||||
@ -801,8 +852,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.count_ones(), 3);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
|
||||
|
||||
@ -818,8 +868,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.count_zeros(), 5);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn count_zeros(self) -> u32 {
|
||||
(!self).count_ones()
|
||||
@ -838,8 +887,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.leading_zeros(), 10);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn leading_zeros(self) -> u32 {
|
||||
(self as $UnsignedT).leading_zeros()
|
||||
@ -858,8 +906,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.trailing_zeros(), 3);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn trailing_zeros(self) -> u32 {
|
||||
(self as $UnsignedT).trailing_zeros()
|
||||
@ -879,8 +926,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.rotate_left(12), m);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn rotate_left(self, n: u32) -> $T {
|
||||
(self as $UnsignedT).rotate_left(n) as $T
|
||||
@ -901,8 +947,7 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(n.rotate_right(12), m);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn rotate_right(self, n: u32) -> $T {
|
||||
(self as $UnsignedT).rotate_right(n) as $T
|
||||
@ -1103,7 +1148,7 @@ macro_rules! int_impl {
|
||||
pub fn saturating_add(self, other: $T) -> $T {
|
||||
match self.checked_add(other) {
|
||||
Some(x) => x,
|
||||
None if other >= <$T>::zero() => <$T>::max_value(),
|
||||
None if other >= <$T as Zero>::zero() => <$T>::max_value(),
|
||||
None => <$T>::min_value(),
|
||||
}
|
||||
}
|
||||
@ -1115,11 +1160,41 @@ macro_rules! int_impl {
|
||||
pub fn saturating_sub(self, other: $T) -> $T {
|
||||
match self.checked_sub(other) {
|
||||
Some(x) => x,
|
||||
None if other >= <$T>::zero() => <$T>::min_value(),
|
||||
None if other >= <$T as Zero>::zero() => <$T>::min_value(),
|
||||
None => <$T>::max_value(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) addition. Computes `self + other`,
|
||||
/// wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_add(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_add(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) subtraction. Computes `self - other`,
|
||||
/// wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_sub(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_sub(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) multiplication. Computes `self *
|
||||
/// other`, wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_mul(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_mul(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Raises self to the power of `exp`, using exponentiation by squaring.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1130,12 +1205,11 @@ macro_rules! int_impl {
|
||||
///
|
||||
/// assert_eq!(2.pow(4), 16);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn pow(self, mut exp: u32) -> $T {
|
||||
let mut base = self;
|
||||
let mut acc = <$T>::one();
|
||||
let mut acc = <$T as One>::one();
|
||||
|
||||
let mut prev_base = self;
|
||||
let mut base_oflo = false;
|
||||
@ -1161,7 +1235,7 @@ macro_rules! int_impl {
|
||||
|
||||
/// Computes the absolute value of `self`. `Int::min_value()` will be
|
||||
/// returned if the number is `Int::min_value()`.
|
||||
#[unstable(feature = "core", reason = "overflow in debug builds?")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> $T {
|
||||
if self.is_negative() { -self } else { self }
|
||||
@ -1256,35 +1330,25 @@ macro_rules! uint_impl {
|
||||
$add_with_overflow:path,
|
||||
$sub_with_overflow:path,
|
||||
$mul_with_overflow:path) => {
|
||||
/// Returns the `0` value of this integer type.
|
||||
// FIXME (#5527): Should be an associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn zero() -> $T { 0 }
|
||||
|
||||
/// Returns the `1` value of this integer type.
|
||||
// FIXME (#5527): Should be an associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn one() -> $T { 1 }
|
||||
|
||||
/// Returns the smallest value that can be represented by this integer
|
||||
/// type.
|
||||
// FIXME (#5527): Should be and associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn min_value() -> $T { 0 }
|
||||
|
||||
/// Returns the largest value that can be represented by this integer
|
||||
/// type.
|
||||
// FIXME (#5527): Should be and associated constant
|
||||
#[unstable(feature = "core",
|
||||
reason = "unsure about its place in the world")]
|
||||
#[inline]
|
||||
pub fn max_value() -> $T { -1 }
|
||||
/// Convert a string slice in a given base to an integer.
|
||||
///
|
||||
/// Leading and trailing whitespace represent an error.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * src - A string slice
|
||||
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// `None` if the string did not represent a valid number.
|
||||
/// Otherwise, `Some(n)` where `n` is the integer represented
|
||||
/// by `src`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
pub fn from_str_radix(src: &str, radix: u32) -> Result<$T, ParseIntError> {
|
||||
<Self as FromStrRadix>::from_str_radix(src, radix)
|
||||
}
|
||||
|
||||
/// Returns the number of ones in the binary representation of `self`.
|
||||
///
|
||||
@ -1298,8 +1362,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.count_ones(), 3);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn count_ones(self) -> u32 {
|
||||
unsafe { $ctpop(self as $ActualT) as u32 }
|
||||
@ -1317,8 +1380,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.count_zeros(), 5);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn count_zeros(self) -> u32 {
|
||||
(!self).count_ones()
|
||||
@ -1337,8 +1399,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.leading_zeros(), 10);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn leading_zeros(self) -> u32 {
|
||||
unsafe { $ctlz(self as $ActualT) as u32 }
|
||||
@ -1357,8 +1418,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.trailing_zeros(), 3);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn trailing_zeros(self) -> u32 {
|
||||
unsafe { $cttz(self as $ActualT) as u32 }
|
||||
@ -1378,8 +1438,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.rotate_left(12), m);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn rotate_left(self, n: u32) -> $T {
|
||||
// Protect against undefined behaviour for over-long bit shifts
|
||||
@ -1402,8 +1461,7 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(n.rotate_right(12), m);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn rotate_right(self, n: u32) -> $T {
|
||||
// Protect against undefined behaviour for over-long bit shifts
|
||||
@ -1604,7 +1662,7 @@ macro_rules! uint_impl {
|
||||
pub fn saturating_add(self, other: $T) -> $T {
|
||||
match self.checked_add(other) {
|
||||
Some(x) => x,
|
||||
None if other >= <$T>::zero() => <$T>::max_value(),
|
||||
None if other >= <$T as Zero>::zero() => <$T>::max_value(),
|
||||
None => <$T>::min_value(),
|
||||
}
|
||||
}
|
||||
@ -1616,11 +1674,41 @@ macro_rules! uint_impl {
|
||||
pub fn saturating_sub(self, other: $T) -> $T {
|
||||
match self.checked_sub(other) {
|
||||
Some(x) => x,
|
||||
None if other >= <$T>::zero() => <$T>::min_value(),
|
||||
None if other >= <$T as Zero>::zero() => <$T>::min_value(),
|
||||
None => <$T>::max_value(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) addition. Computes `self + other`,
|
||||
/// wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_add(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_add(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) subtraction. Computes `self - other`,
|
||||
/// wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_sub(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_sub(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapping (modular) multiplication. Computes `self *
|
||||
/// other`, wrapping around at the boundary of the type.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn wrapping_mul(self, rhs: $T) -> $T {
|
||||
unsafe {
|
||||
intrinsics::overflowing_mul(self, rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Raises self to the power of `exp`, using exponentiation by squaring.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1631,12 +1719,11 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// assert_eq!(2.pow(4), 16);
|
||||
/// ```
|
||||
#[unstable(feature = "core",
|
||||
reason = "pending integer conventions")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn pow(self, mut exp: u32) -> $T {
|
||||
let mut base = self;
|
||||
let mut acc = <$T>::one();
|
||||
let mut acc = <$T as One>::one();
|
||||
|
||||
let mut prev_base = self;
|
||||
let mut base_oflo = false;
|
||||
@ -1664,8 +1751,8 @@ macro_rules! uint_impl {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn is_power_of_two(self) -> bool {
|
||||
(self.wrapping_sub(<$T>::one())) & self == <$T>::zero() &&
|
||||
!(self == <$T>::zero())
|
||||
(self.wrapping_sub(<$T as One>::one())) & self == <$T as Zero>::zero() &&
|
||||
!(self == <$T as Zero>::zero())
|
||||
}
|
||||
|
||||
/// Returns the smallest power of two greater than or equal to `self`.
|
||||
@ -1674,7 +1761,7 @@ macro_rules! uint_impl {
|
||||
#[inline]
|
||||
pub fn next_power_of_two(self) -> $T {
|
||||
let bits = size_of::<$T>() * 8;
|
||||
let one: $T = <$T>::one();
|
||||
let one: $T = <$T as One>::one();
|
||||
one << ((bits - self.wrapping_sub(one).leading_zeros() as usize) % bits)
|
||||
}
|
||||
|
||||
@ -2339,17 +2426,26 @@ impl_num_cast! { f64, to_f64 }
|
||||
|
||||
/// Used for representing the classification of floating point numbers
|
||||
#[derive(Copy, PartialEq, Debug)]
|
||||
#[unstable(feature = "core", reason = "may be renamed")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub enum FpCategory {
|
||||
/// "Not a Number", often obtained by dividing by zero
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Nan,
|
||||
|
||||
/// Positive or negative infinity
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Infinite ,
|
||||
|
||||
/// Positive or negative zero
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Zero,
|
||||
|
||||
/// De-normalized floating point representation (less precise than `Normal`)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Subnormal,
|
||||
|
||||
/// A regular floating point number
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Normal,
|
||||
}
|
||||
|
||||
@ -2526,13 +2622,24 @@ pub trait Float
|
||||
|
||||
/// A generic trait for converting a string with a radix (base) to a value
|
||||
#[unstable(feature = "core", reason = "needs reevaluation")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "moved to inherent methods; use e.g. i32::from_str_radix")]
|
||||
pub trait FromStrRadix {
|
||||
#[unstable(feature = "core", reason = "needs reevaluation")]
|
||||
#[deprecated(since = "1.0.0", reason = "moved to inherent methods")]
|
||||
type Err;
|
||||
|
||||
#[unstable(feature = "core", reason = "needs reevaluation")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "moved to inherent methods; use e.g. i32::from_str_radix")]
|
||||
#[allow(deprecated)]
|
||||
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::Err>;
|
||||
}
|
||||
|
||||
/// A utility function that just calls `FromStrRadix::from_str_radix`.
|
||||
#[unstable(feature = "core", reason = "needs reevaluation")]
|
||||
#[deprecated(since = "1.0.0", reason = "use e.g. i32::from_str_radix")]
|
||||
#[allow(deprecated)]
|
||||
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: u32)
|
||||
-> Result<T, T::Err> {
|
||||
FromStrRadix::from_str_radix(str, radix)
|
||||
@ -2570,12 +2677,14 @@ macro_rules! from_str_radix_float_impl {
|
||||
/// `None` if the string did not represent a valid number. Otherwise,
|
||||
/// `Some(n)` where `n` is the floating-point number represented by `src`.
|
||||
#[inline]
|
||||
#[allow(deprecated)]
|
||||
fn from_str(src: &str) -> Result<$T, ParseFloatError> {
|
||||
from_str_radix(src, 10)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl FromStrRadix for $T {
|
||||
type Err = ParseFloatError;
|
||||
|
||||
@ -2746,6 +2855,7 @@ from_str_radix_float_impl! { f64 }
|
||||
macro_rules! from_str_radix_int_impl {
|
||||
($T:ty) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl FromStr for $T {
|
||||
type Err = ParseIntError;
|
||||
#[inline]
|
||||
@ -2755,6 +2865,7 @@ macro_rules! from_str_radix_int_impl {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
impl FromStrRadix for $T {
|
||||
type Err = ParseIntError;
|
||||
fn from_str_radix(src: &str, radix: u32)
|
||||
|
@ -7,7 +7,11 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(missing_docs)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
use super::Wrapping;
|
||||
|
||||
use ops::*;
|
||||
|
||||
@ -26,6 +30,8 @@ use intrinsics::{i16_mul_with_overflow, u16_mul_with_overflow};
|
||||
use intrinsics::{i32_mul_with_overflow, u32_mul_with_overflow};
|
||||
use intrinsics::{i64_mul_with_overflow, u64_mul_with_overflow};
|
||||
|
||||
#[unstable(feature = "core", reason = "may be removed, renamed, or relocated")]
|
||||
#[deprecated(since = "1.0.0", reason = "moved to inherent methods")]
|
||||
pub trait WrappingOps {
|
||||
fn wrapping_add(self, rhs: Self) -> Self;
|
||||
fn wrapping_sub(self, rhs: Self) -> Self;
|
||||
@ -39,6 +45,49 @@ pub trait OverflowingOps {
|
||||
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
|
||||
}
|
||||
|
||||
macro_rules! sh_impl {
|
||||
($t:ty, $f:ty) => (
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Shl<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn shl(self, other: $f) -> Wrapping<$t> {
|
||||
Wrapping(self.0 << other)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Shr<$f> for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn shr(self, other: $f) -> Wrapping<$t> {
|
||||
Wrapping(self.0 >> other)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// FIXME (#23545): uncomment the remaining impls
|
||||
macro_rules! sh_impl_all {
|
||||
($($t:ty)*) => ($(
|
||||
// sh_impl! { $t, u8 }
|
||||
// sh_impl! { $t, u16 }
|
||||
// sh_impl! { $t, u32 }
|
||||
// sh_impl! { $t, u64 }
|
||||
sh_impl! { $t, usize }
|
||||
|
||||
// sh_impl! { $t, i8 }
|
||||
// sh_impl! { $t, i16 }
|
||||
// sh_impl! { $t, i32 }
|
||||
// sh_impl! { $t, i64 }
|
||||
// sh_impl! { $t, isize }
|
||||
)*)
|
||||
}
|
||||
|
||||
sh_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
||||
|
||||
macro_rules! wrapping_impl {
|
||||
($($t:ty)*) => ($(
|
||||
impl WrappingOps for $t {
|
||||
@ -61,94 +110,79 @@ macro_rules! wrapping_impl {
|
||||
}
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
wrapping_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
|
||||
|
||||
#[unstable(feature = "core", reason = "may be removed, renamed, or relocated")]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
|
||||
pub struct Wrapping<T>(pub T);
|
||||
|
||||
impl<T:WrappingOps> Add for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Add for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn add(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn add(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0.wrapping_add(other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps> Sub for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Sub for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn sub(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn sub(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0.wrapping_sub(other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps> Mul for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Mul for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn mul(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn mul(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0.wrapping_mul(other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+Not<Output=T>> Not for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Not for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
fn not(self) -> Wrapping<T> {
|
||||
fn not(self) -> Wrapping<$t> {
|
||||
Wrapping(!self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+BitXor<Output=T>> BitXor for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BitXor for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn bitxor(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn bitxor(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+BitOr<Output=T>> BitOr for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BitOr for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn bitor(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn bitor(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0 | other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+BitAnd<Output=T>> BitAnd for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BitAnd for Wrapping<$t> {
|
||||
type Output = Wrapping<$t>;
|
||||
|
||||
#[inline(always)]
|
||||
fn bitand(self, other: Wrapping<T>) -> Wrapping<T> {
|
||||
fn bitand(self, other: Wrapping<$t>) -> Wrapping<$t> {
|
||||
Wrapping(self.0 & other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+Shl<usize,Output=T>> Shl<usize> for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
|
||||
#[inline(always)]
|
||||
fn shl(self, other: usize) -> Wrapping<T> {
|
||||
Wrapping(self.0 << other)
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
impl<T:WrappingOps+Shr<usize,Output=T>> Shr<usize> for Wrapping<T> {
|
||||
type Output = Wrapping<T>;
|
||||
|
||||
#[inline(always)]
|
||||
fn shr(self, other: usize) -> Wrapping<T> {
|
||||
Wrapping(self.0 >> other)
|
||||
}
|
||||
}
|
||||
wrapping_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
|
||||
|
||||
macro_rules! overflowing_impl {
|
||||
($($t:ident)*) => ($(
|
||||
|
@ -945,9 +945,9 @@ impl TwoWaySearcher {
|
||||
// critical factorization (u, v) and p = period(v)
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
#[allow(deprecated)]
|
||||
fn maximal_suffix(arr: &[u8], reversed: bool) -> (usize, usize) {
|
||||
use num::wrapping::WrappingOps;
|
||||
let mut left = -1; // Corresponds to i in the paper
|
||||
let mut left: usize = -1; // Corresponds to i in the paper
|
||||
let mut right = 0; // Corresponds to j in the paper
|
||||
let mut offset = 1; // Corresponds to k in the paper
|
||||
let mut period = 1; // Corresponds to p in the paper
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
use core::prelude::*;
|
||||
use core::slice;
|
||||
use core::iter::{range_step, repeat};
|
||||
use core::num::wrapping::Wrapping as w;
|
||||
use core::iter::repeat;
|
||||
use core::num::Wrapping as w;
|
||||
|
||||
use {Rng, SeedableRng, Rand};
|
||||
|
||||
@ -95,7 +95,7 @@ impl IsaacRng {
|
||||
if use_rsl {
|
||||
macro_rules! memloop {
|
||||
($arr:expr) => {{
|
||||
for i in range_step(0, RAND_SIZE_USIZE, 8) {
|
||||
for i in (0..RAND_SIZE_USIZE).step_by(8) {
|
||||
a=a+$arr[i ]; b=b+$arr[i+1];
|
||||
c=c+$arr[i+2]; d=d+$arr[i+3];
|
||||
e=e+$arr[i+4]; f=f+$arr[i+5];
|
||||
@ -112,7 +112,7 @@ impl IsaacRng {
|
||||
memloop!(self.rsl);
|
||||
memloop!(self.mem);
|
||||
} else {
|
||||
for i in range_step(0, RAND_SIZE_USIZE, 8) {
|
||||
for i in (0..RAND_SIZE_USIZE).step_by(8) {
|
||||
mix!();
|
||||
self.mem[i ]=a; self.mem[i+1]=b;
|
||||
self.mem[i+2]=c; self.mem[i+3]=d;
|
||||
@ -172,7 +172,7 @@ impl IsaacRng {
|
||||
}}
|
||||
}
|
||||
|
||||
for i in range_step(0, MIDPOINT, 4) {
|
||||
for i in (0..MIDPOINT).step_by(4) {
|
||||
rngstepp!(i + 0, 13);
|
||||
rngstepn!(i + 1, 6);
|
||||
rngstepp!(i + 2, 2);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#![feature(staged_api)]
|
||||
#![staged_api]
|
||||
#![feature(core)]
|
||||
#![feature(step_by)]
|
||||
#![deprecated(reason = "use the crates.io `rand` library instead",
|
||||
since = "1.0.0-alpha")]
|
||||
|
||||
|
@ -241,7 +241,6 @@ pub mod reader {
|
||||
|
||||
use std::isize;
|
||||
use std::mem::transmute;
|
||||
use std::num::Int;
|
||||
use std::slice::bytes;
|
||||
|
||||
use serialize;
|
||||
@ -346,7 +345,7 @@ pub mod reader {
|
||||
|
||||
unsafe {
|
||||
let ptr = data.as_ptr().offset(start as isize) as *const u32;
|
||||
let val = Int::from_be(*ptr);
|
||||
let val = u32::from_be(*ptr);
|
||||
|
||||
let i = (val >> 28) as usize;
|
||||
let (shift, mask) = SHIFT_MASK_TABLE[i];
|
||||
@ -835,7 +834,6 @@ pub mod reader {
|
||||
|
||||
pub mod writer {
|
||||
use std::mem;
|
||||
use std::num::Int;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{self, SeekFrom, Cursor};
|
||||
use std::slice::bytes;
|
||||
|
@ -35,7 +35,7 @@ use std::collections::HashMap;
|
||||
use std::hash::{self, Hash, SipHasher};
|
||||
use std::io::prelude::*;
|
||||
use std::io;
|
||||
use std::num::{FromPrimitive, Int};
|
||||
use std::num::FromPrimitive;
|
||||
use std::rc::Rc;
|
||||
use std::slice::bytes;
|
||||
use std::str;
|
||||
|
@ -5491,7 +5491,6 @@ pub fn type_is_empty(cx: &ctxt, ty: Ty) -> bool {
|
||||
|
||||
pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
|
||||
-> Rc<Vec<Rc<VariantInfo<'tcx>>>> {
|
||||
use std::num::Int; // For checked_add
|
||||
memoized(&cx.enum_var_cache, id, |id: ast::DefId| {
|
||||
if ast::LOCAL_CRATE != id.krate {
|
||||
Rc::new(csearch::get_enum_variants(cx, id))
|
||||
|
@ -64,7 +64,7 @@ impl ToBits for u64 {
|
||||
fn add_bytes_to_bits<T: Int + ToBits>(bits: T, bytes: T) -> T {
|
||||
let (new_high_bits, new_low_bits) = bytes.to_bits();
|
||||
|
||||
if new_high_bits > Int::zero() {
|
||||
if new_high_bits > T::zero() {
|
||||
panic!("numeric overflow occurred.")
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ mod tests {
|
||||
use self::rand::isaac::IsaacRng;
|
||||
use serialize::hex::FromHex;
|
||||
use std::iter::repeat;
|
||||
use std::num::Int;
|
||||
use std::u64;
|
||||
use super::{Digest, Sha256, FixedBuffer};
|
||||
|
||||
// A normal addition - no overflow occurs
|
||||
@ -550,7 +550,7 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_add_bytes_to_bits_overflow() {
|
||||
super::add_bytes_to_bits::<u64>(Int::max_value(), 1);
|
||||
super::add_bytes_to_bits::<u64>(u64::MAX, 1);
|
||||
}
|
||||
|
||||
struct Test {
|
||||
|
@ -41,7 +41,6 @@ use lint::{Level, Context, LintPass, LintArray, Lint};
|
||||
|
||||
use std::collections::{HashSet, BitSet};
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::num::SignedInt;
|
||||
use std::{cmp, slice};
|
||||
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
|
||||
|
||||
|
@ -22,6 +22,7 @@ use flate;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::mem;
|
||||
#[allow(deprecated)]
|
||||
use std::num::Int;
|
||||
|
||||
pub fn run(sess: &session::Session, llmod: ModuleRef,
|
||||
@ -204,6 +205,7 @@ fn extract_compressed_bytecode_size_v1(bc: &[u8]) -> u64 {
|
||||
return read_from_le_bytes::<u64>(bc, link::RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET);
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn read_from_le_bytes<T: Int>(bytes: &[u8], position_in_bytes: usize) -> T {
|
||||
let byte_data = &bytes[position_in_bytes..position_in_bytes + mem::size_of::<T>()];
|
||||
let data = unsafe {
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
pub use self::Repr::*;
|
||||
|
||||
#[allow(deprecated)]
|
||||
use std::num::Int;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -21,6 +21,7 @@ use util::ppaux::Repr;
|
||||
|
||||
use trans::type_::Type;
|
||||
|
||||
#[allow(deprecated)]
|
||||
use std::num::Int;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
|
@ -4285,7 +4285,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
||||
id: ast::NodeId,
|
||||
hint: attr::ReprAttr)
|
||||
-> Vec<Rc<ty::VariantInfo<'tcx>>> {
|
||||
use std::num::Int;
|
||||
#![allow(trivial_numeric_casts)]
|
||||
|
||||
let rty = ty::node_id_to_type(ccx.tcx, id);
|
||||
let mut variants: Vec<Rc<ty::VariantInfo>> = Vec::new();
|
||||
|
@ -204,6 +204,8 @@ use std::io::prelude::*;
|
||||
use std::io;
|
||||
use std::mem::swap;
|
||||
use std::num::FpCategory as Fp;
|
||||
#[allow(deprecated)]
|
||||
use std::num::wrapping::WrappingOps;
|
||||
use std::ops::Index;
|
||||
use std::str::FromStr;
|
||||
use std::string;
|
||||
@ -1552,6 +1554,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)] // possible resolve bug is mapping these to traits
|
||||
fn parse_u64(&mut self) -> Result<u64, ParserError> {
|
||||
let mut accum = 0;
|
||||
let last_accum = 0; // necessary to detect overflow.
|
||||
|
@ -14,7 +14,6 @@ use io::prelude::*;
|
||||
use cmp;
|
||||
use io::{self, SeekFrom, Error, ErrorKind};
|
||||
use iter::repeat;
|
||||
use num::Int;
|
||||
use slice;
|
||||
|
||||
/// A `Cursor` is a type which wraps a non-I/O object to provide a `Seek`
|
||||
|
@ -18,6 +18,7 @@
|
||||
use prelude::v1::*;
|
||||
|
||||
use io::{self, Error, ErrorKind};
|
||||
#[allow(deprecated)] // Int
|
||||
use num::Int;
|
||||
use sys_common::net2 as net_imp;
|
||||
|
||||
@ -54,7 +55,9 @@ pub enum Shutdown {
|
||||
Both,
|
||||
}
|
||||
|
||||
#[allow(deprecated)] // Int
|
||||
fn hton<I: Int>(i: I) -> I { i.to_be() }
|
||||
#[allow(deprecated)] // Int
|
||||
fn ntoh<I: Int>(i: I) -> I { Int::from_be(i) }
|
||||
|
||||
fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,7 @@
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
#[cfg(test)] use fmt::Debug;
|
||||
use ops::{Add, Sub, Mul, Div, Rem, Neg};
|
||||
@ -23,22 +24,24 @@ use marker::Copy;
|
||||
use clone::Clone;
|
||||
use cmp::{PartialOrd, PartialEq};
|
||||
|
||||
pub use core::num::{Int, SignedInt};
|
||||
pub use core::num::{Int, SignedInt, Zero, One};
|
||||
pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive};
|
||||
pub use core::num::{from_int, from_i8, from_i16, from_i32, from_i64};
|
||||
pub use core::num::{from_uint, from_u8, from_u16, from_u32, from_u64};
|
||||
pub use core::num::{from_f32, from_f64};
|
||||
pub use core::num::{FromStrRadix, from_str_radix};
|
||||
pub use core::num::{FpCategory, ParseIntError, ParseFloatError};
|
||||
pub use core::num::wrapping;
|
||||
pub use core::num::{wrapping, Wrapping};
|
||||
|
||||
use option::Option;
|
||||
|
||||
#[unstable(feature = "std_misc", reason = "may be removed or relocated")]
|
||||
#[unstable(feature = "std_misc", reason = "likely to be removed")]
|
||||
pub mod strconv;
|
||||
|
||||
/// Mathematical operations on primitive floating point numbers.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "replaced by inherent methods; use rust-lang/num for generics")]
|
||||
pub trait Float
|
||||
: Copy + Clone
|
||||
+ NumCast
|
||||
@ -272,6 +275,7 @@ pub trait Float
|
||||
/// ```
|
||||
#[unstable(feature = "std_misc", reason = "position is undecided")]
|
||||
fn is_finite(self) -> bool;
|
||||
|
||||
/// Returns `true` if the number is neither zero, infinite,
|
||||
/// [subnormal][subnormal], or `NaN`.
|
||||
///
|
||||
@ -1148,7 +1152,7 @@ pub fn test_num<T>(ten: T, two: T) where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
use core::prelude::*;
|
||||
use super::*;
|
||||
use i8;
|
||||
use i16;
|
||||
@ -1160,6 +1164,7 @@ mod tests {
|
||||
use u32;
|
||||
use u64;
|
||||
use usize;
|
||||
use string::ToString;
|
||||
|
||||
macro_rules! test_cast_20 {
|
||||
($_20:expr) => ({
|
||||
|
@ -11,6 +11,7 @@
|
||||
// ignore-lexer-test FIXME #15679
|
||||
|
||||
#![allow(missing_docs)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
use self::ExponentFormat::*;
|
||||
use self::SignificantDigits::*;
|
||||
|
@ -51,6 +51,3 @@
|
||||
#[doc(no_inline)] pub use string::{String, ToString};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)] pub use vec::Vec;
|
||||
|
||||
// FIXME(#23454) should these be here?
|
||||
#[doc(no_inline)] pub use num::wrapping::{Wrapping, WrappingOps};
|
||||
|
@ -14,6 +14,7 @@ use old_io::{self, IoError, IoResult};
|
||||
use prelude::v1::*;
|
||||
use sys::{last_error, retry};
|
||||
use ffi::CString;
|
||||
#[allow(deprecated)] // Int
|
||||
use num::Int;
|
||||
|
||||
#[allow(deprecated)]
|
||||
|
@ -37,6 +37,7 @@ use fmt;
|
||||
use hash::{Hash, Hasher};
|
||||
use iter::{FromIterator, IntoIterator};
|
||||
use mem;
|
||||
#[allow(deprecated)] // Int
|
||||
use num::Int;
|
||||
use ops;
|
||||
use slice;
|
||||
|
@ -171,6 +171,7 @@ pub fn retry<T, F> (mut f: F) -> T where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub fn cvt<T: SignedInt>(t: T) -> io::Result<T> {
|
||||
let one: T = Int::one();
|
||||
if t == -one {
|
||||
@ -180,6 +181,7 @@ pub fn cvt<T: SignedInt>(t: T) -> io::Result<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
|
||||
where T: SignedInt, F: FnMut() -> T
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ use ffi::{OsStr, OsString};
|
||||
use io::{self, ErrorKind};
|
||||
use libc;
|
||||
use mem;
|
||||
#[allow(deprecated)]
|
||||
use num::Int;
|
||||
use old_io::{self, IoResult, IoError};
|
||||
use os::windows::ffi::{OsStrExt, OsStringExt};
|
||||
@ -315,6 +316,7 @@ pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn cvt<I: Int>(i: I) -> io::Result<I> {
|
||||
if i == Int::zero() {
|
||||
Err(io::Error::last_os_error())
|
||||
|
@ -15,6 +15,7 @@ use libc::consts::os::extra::INVALID_SOCKET;
|
||||
use libc::{self, c_int, c_void};
|
||||
use mem;
|
||||
use net::SocketAddr;
|
||||
#[allow(deprecated)]
|
||||
use num::{SignedInt, Int};
|
||||
use rt;
|
||||
use sync::{Once, ONCE_INIT};
|
||||
@ -50,6 +51,7 @@ fn last_error() -> io::Error {
|
||||
/// function must be called before another call to the socket API is made.
|
||||
///
|
||||
/// FIXME: generics needed?
|
||||
#[allow(deprecated)]
|
||||
pub fn cvt<T: SignedInt>(t: T) -> io::Result<T> {
|
||||
let one: T = Int::one();
|
||||
if t == -one {
|
||||
@ -67,6 +69,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
|
||||
}
|
||||
|
||||
/// Provides the functionality of `cvt` for a closure.
|
||||
#[allow(deprecated)]
|
||||
pub fn cvt_r<T: SignedInt, F>(mut f: F) -> io::Result<T> where F: FnMut() -> T {
|
||||
cvt(f())
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use {fmt, i64};
|
||||
use ops::{Add, Sub, Mul, Div, Neg, FnOnce};
|
||||
use option::Option;
|
||||
use option::Option::{Some, None};
|
||||
#[allow(deprecated)] // Int
|
||||
use num::Int;
|
||||
use result::Result::Ok;
|
||||
|
||||
|
@ -66,6 +66,7 @@ use parse::lexer;
|
||||
use ptr::P;
|
||||
|
||||
use std::fmt;
|
||||
#[allow(deprecated)]
|
||||
use std::num::Int;
|
||||
use std::rc::Rc;
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
@ -1141,6 +1142,7 @@ pub enum Sign {
|
||||
}
|
||||
|
||||
impl Sign {
|
||||
#[allow(deprecated)] // Int
|
||||
pub fn new<T:Int>(n: T) -> Sign {
|
||||
if n < Int::zero() {
|
||||
Minus
|
||||
|
@ -20,7 +20,6 @@ use std::borrow::{IntoCow, Cow};
|
||||
use std::char;
|
||||
use std::fmt;
|
||||
use std::mem::replace;
|
||||
use std::num;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub use ext::tt::transcribe::{TtReader, new_tt_reader, new_tt_reader_with_doc_flag};
|
||||
@ -623,7 +622,7 @@ impl<'a> StringReader<'a> {
|
||||
// find the integer representing the name
|
||||
self.scan_digits(base);
|
||||
let encoded_name: u32 = self.with_str_from(start_bpos, |s| {
|
||||
num::from_str_radix(s, 10).unwrap_or_else(|_| {
|
||||
u32::from_str_radix(s, 10).unwrap_or_else(|_| {
|
||||
panic!("expected digits representing a name, got {:?}, {}, range [{:?},{:?}]",
|
||||
s, whence, start_bpos, self.last_pos);
|
||||
})
|
||||
@ -641,7 +640,7 @@ impl<'a> StringReader<'a> {
|
||||
let start_bpos = self.last_pos;
|
||||
self.scan_digits(base);
|
||||
let encoded_ctxt : ast::SyntaxContext = self.with_str_from(start_bpos, |s| {
|
||||
num::from_str_radix(s, 10).unwrap_or_else(|_| {
|
||||
u32::from_str_radix(s, 10).unwrap_or_else(|_| {
|
||||
panic!("expected digits representing a ctxt, got {:?}, {}", s, whence);
|
||||
})
|
||||
});
|
||||
|
@ -21,6 +21,7 @@ use std::cell::{Cell, RefCell};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::iter;
|
||||
#[allow(deprecated)] // Int
|
||||
use std::num::Int;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::Rc;
|
||||
@ -372,7 +373,7 @@ pub fn maybe_aborted<T>(result: T, p: Parser) -> T {
|
||||
/// well. Can take any slice prefixed by a character escape. Returns the
|
||||
/// character and the number of characters consumed.
|
||||
pub fn char_lit(lit: &str) -> (char, isize) {
|
||||
use std::{num, char};
|
||||
use std::char;
|
||||
|
||||
let mut chars = lit.chars();
|
||||
let c = match (chars.next(), chars.next()) {
|
||||
@ -399,7 +400,7 @@ pub fn char_lit(lit: &str) -> (char, isize) {
|
||||
let msg2 = &msg[..];
|
||||
|
||||
fn esc(len: usize, lit: &str) -> Option<(char, isize)> {
|
||||
num::from_str_radix(&lit[2..len], 16).ok()
|
||||
u32::from_str_radix(&lit[2..len], 16).ok()
|
||||
.and_then(char::from_u32)
|
||||
.map(|x| (x, len as isize))
|
||||
}
|
||||
@ -408,7 +409,7 @@ pub fn char_lit(lit: &str) -> (char, isize) {
|
||||
if lit.as_bytes()[2] == b'{' {
|
||||
let idx = lit.find('}').expect(msg2);
|
||||
let subslice = &lit[3..idx];
|
||||
num::from_str_radix(subslice, 16).ok()
|
||||
u32::from_str_radix(subslice, 16).ok()
|
||||
.and_then(char::from_u32)
|
||||
.map(|x| (x, subslice.chars().count() as isize + 4))
|
||||
} else {
|
||||
@ -582,7 +583,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
|
||||
b'\'' => b'\'',
|
||||
b'0' => b'\0',
|
||||
_ => {
|
||||
match ::std::num::from_str_radix::<u64>(&lit[2..4], 16).ok() {
|
||||
match u64::from_str_radix(&lit[2..4], 16).ok() {
|
||||
Some(c) =>
|
||||
if c > 0xFF {
|
||||
panic!(err(2))
|
||||
@ -733,7 +734,7 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
|
||||
debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \
|
||||
string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix);
|
||||
|
||||
let res: u64 = match ::std::num::from_str_radix(s, base).ok() {
|
||||
let res = match u64::from_str_radix(s, base).ok() {
|
||||
Some(r) => r,
|
||||
None => { sd.span_err(sp, "int literal is too large"); 0 }
|
||||
};
|
||||
|
@ -9,6 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(missing_docs)]
|
||||
#![allow(deprecated)] // Float
|
||||
|
||||
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
||||
use std::mem;
|
||||
|
@ -22,7 +22,6 @@ use core::char;
|
||||
use core::cmp;
|
||||
use core::iter::{Filter, AdditiveIterator};
|
||||
use core::mem;
|
||||
use core::num::Int;
|
||||
use core::slice;
|
||||
use core::str::Split;
|
||||
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::num::Int;
|
||||
|
||||
struct Foo {
|
||||
x: usize,
|
||||
b: bool, //~ ERROR: struct field is never used
|
||||
|
@ -15,9 +15,10 @@ pub fn main() {
|
||||
let _ = 0u32..10i32;
|
||||
//~^ ERROR start and end of range have incompatible types
|
||||
|
||||
// Float => does not implement iterator.
|
||||
for i in 0f32..42f32 {}
|
||||
//~^ ERROR the trait `core::num::Int` is not implemented for the type `f32`
|
||||
// Bool => does not implement iterator.
|
||||
for i in false..true {}
|
||||
//~^ ERROR the trait
|
||||
//~^^ ERROR the trait
|
||||
|
||||
// Unsized type.
|
||||
let arr: &[_] = &[1, 2, 3];
|
||||
|
@ -12,11 +12,11 @@
|
||||
|
||||
#![feature(core)]
|
||||
|
||||
use std::num::Int;
|
||||
use std::ops::Add;
|
||||
|
||||
extern "C" fn foo<T: WrappingOps>(a: T, b: T) -> T { a.wrapping_add(b) }
|
||||
extern "C" fn foo<T: Add>(a: T, b: T) -> T::Output { a + b }
|
||||
|
||||
fn main() {
|
||||
assert_eq!(99u8, foo(255u8, 100u8));
|
||||
assert_eq!(99u16, foo(65535u16, 100u16));
|
||||
assert_eq!(100u8, foo(0u8, 100u8));
|
||||
assert_eq!(100u16, foo(0u16, 100u16));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user