Merge pull request #78 from kennytm/master
impl PrimInt for primitive types, and remove some unstable features.
This commit is contained in:
commit
7861e4c6da
|
@ -38,14 +38,13 @@
|
|||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#![feature(core)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate num;
|
||||
extern crate test;
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::num::{FromPrimitive, ToPrimitive};
|
||||
use num::traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
use test::Bencher;
|
||||
|
||||
|
@ -133,7 +132,7 @@ fn main() {
|
|||
let n = if args.len() < 2 {
|
||||
DEFAULT_DIGITS
|
||||
} else {
|
||||
FromStr::from_str(args[1].as_slice()).unwrap()
|
||||
FromStr::from_str(&args[1]).unwrap()
|
||||
};
|
||||
pidigits(n);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
//! approximate a square root to arbitrary precision:
|
||||
//!
|
||||
//! ```
|
||||
//! # #![feature(core)]
|
||||
//! extern crate num;
|
||||
//!
|
||||
//! use num::FromPrimitive;
|
||||
|
@ -44,7 +43,7 @@
|
|||
//!
|
||||
//! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
|
||||
//#![cfg_attr(test, deny(warnings))]
|
||||
#![cfg_attr(test, feature(hash, test))]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/num/",
|
||||
|
@ -145,5 +144,8 @@ pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) ->
|
|||
|
||||
#[cfg(test)]
|
||||
fn hash<T: hash::Hash>(x: &T) -> u64 {
|
||||
hash::hash::<T, hash::SipHasher>(x)
|
||||
use std::hash::Hasher;
|
||||
let mut hasher = hash::SipHasher::new();
|
||||
x.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
|
|
@ -677,14 +677,6 @@ pub trait PrimInt
|
|||
macro_rules! prim_int_impl {
|
||||
($($T:ty)*) => ($(
|
||||
impl PrimInt for $T {
|
||||
fn min_value() -> Self {
|
||||
<$T>::min_value()
|
||||
}
|
||||
|
||||
fn max_value() -> Self {
|
||||
<$T>::max_value()
|
||||
}
|
||||
|
||||
fn count_ones(self) -> u32 {
|
||||
<$T>::count_ones(self)
|
||||
}
|
||||
|
@ -736,6 +728,8 @@ macro_rules! prim_int_impl {
|
|||
)*)
|
||||
}
|
||||
|
||||
prim_int_impl!(u8 u16 u32 u64 usize i8 i16 i32 i64 isize);
|
||||
|
||||
/// A generic trait for converting a value to a number.
|
||||
pub trait ToPrimitive {
|
||||
/// Converts the value of `self` to an `isize`.
|
||||
|
@ -1329,8 +1323,8 @@ pub trait Float
|
|||
/// predicate instead.
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(core)]
|
||||
/// use std::num::{Float, FpCategory};
|
||||
/// use num::traits::Float;
|
||||
/// use std::num::FpCategory;
|
||||
/// use std::f32;
|
||||
///
|
||||
/// let num = 12.4f32;
|
||||
|
@ -1880,7 +1874,6 @@ pub trait Float
|
|||
/// the operations were performed separately.
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(std_misc, core)]
|
||||
/// use num::traits::Float;
|
||||
/// use std::f64;
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue