Remove lots of numeric traits from the preludes

Num, NumCast, Unsigned, Float, Primitive and Int have been removed.
This commit is contained in:
Brendan Zabarauskas 2014-11-10 16:26:10 +11:00
parent 891559e30d
commit e965ba85ca
48 changed files with 100 additions and 66 deletions

View file

@ -51,6 +51,7 @@ expensive. So we'd like to define a function that takes the points just as
a reference. a reference.
~~~ ~~~
# use std::num::Float;
# struct Point {x: f64, y: f64} # struct Point {x: f64, y: f64}
# fn sqrt(f: f64) -> f64 { 0.0 } # fn sqrt(f: f64) -> f64 { 0.0 }
fn compute_distance(p1: &Point, p2: &Point) -> f64 { fn compute_distance(p1: &Point, p2: &Point) -> f64 {

View file

@ -225,6 +225,7 @@ Here is another example showing how futures allow you to background
computations. The workload will be distributed on the available cores. computations. The workload will be distributed on the available cores.
```{rust} ```{rust}
# use std::num::Float;
# use std::sync::Future; # use std::sync::Future;
fn partial_sum(start: uint) -> f64 { fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64; let mut local_sum = 0f64;
@ -262,6 +263,7 @@ several computations on a single large vector of floats. Each task needs the
full vector to perform its duty. full vector to perform its duty.
```{rust} ```{rust}
use std::num::Float;
use std::rand; use std::rand;
use std::sync::Arc; use std::sync::Arc;

View file

@ -38,7 +38,7 @@ use std::cmp;
use std::intrinsics::{TyDesc, get_tydesc}; use std::intrinsics::{TyDesc, get_tydesc};
use std::intrinsics; use std::intrinsics;
use std::mem; use std::mem;
use std::num::UnsignedInt; use std::num::{Int, UnsignedInt};
use std::ptr; use std::ptr;
use std::rc::Rc; use std::rc::Rc;
use std::rt::heap::{allocate, deallocate}; use std::rt::heap::{allocate, deallocate};

View file

@ -22,6 +22,7 @@
//! //!
//! ``` //! ```
//! use std::collections::{BitvSet, Bitv}; //! use std::collections::{BitvSet, Bitv};
//! use std::num::Float;
//! use std::iter; //! use std::iter;
//! //!
//! let max_prime = 10000; //! let max_prime = 10000;
@ -69,6 +70,7 @@ use core::default::Default;
use core::fmt; use core::fmt;
use core::iter::{Chain, Enumerate, Repeat, Skip, Take}; use core::iter::{Chain, Enumerate, Repeat, Skip, Take};
use core::iter; use core::iter;
use core::num::Int;
use core::slice; use core::slice;
use core::u32; use core::u32;
use std::hash; use std::hash;

View file

@ -15,6 +15,7 @@
use core::prelude::*; use core::prelude::*;
use core::fmt; use core::fmt;
use core::num::Int;
// FIXME(contentions): implement union family of methods? (general design may be wrong here) // FIXME(contentions): implement union family of methods? (general design may be wrong here)

View file

@ -69,6 +69,7 @@ use alloc::boxed::Box;
use alloc::rc::Rc; use alloc::rc::Rc;
use core::intrinsics::TypeId; use core::intrinsics::TypeId;
use core::mem; use core::mem;
use core::num::Int;
use vec::Vec; use vec::Vec;

View file

@ -21,7 +21,7 @@ use core::default::Default;
use core::fmt; use core::fmt;
use core::kinds::marker::{ContravariantLifetime, InvariantType}; use core::kinds::marker::{ContravariantLifetime, InvariantType};
use core::mem; use core::mem;
use core::num::UnsignedInt; use core::num::{Int, UnsignedInt};
use core::ops; use core::ops;
use core::ptr; use core::ptr;
use core::raw::Slice as RawSlice; use core::raw::Slice as RawSlice;

View file

@ -234,6 +234,8 @@ impl Float for f32 {
/// The fractional part of the number, satisfying: /// The fractional part of the number, satisfying:
/// ///
/// ```rust /// ```rust
/// use core::num::Float;
///
/// let x = 1.65f32; /// let x = 1.65f32;
/// assert!(x == x.trunc() + x.fract()) /// assert!(x == x.trunc() + x.fract())
/// ``` /// ```

View file

@ -240,6 +240,8 @@ impl Float for f64 {
/// The fractional part of the number, satisfying: /// The fractional part of the number, satisfying:
/// ///
/// ```rust /// ```rust
/// use core::num::Float;
///
/// let x = 1.65f64; /// let x = 1.65f64;
/// assert!(x == x.trunc() + x.fract()) /// assert!(x == x.trunc() + x.fract())
/// ``` /// ```

View file

@ -204,6 +204,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0b01001100u8; /// let n = 0b01001100u8;
/// ///
/// assert_eq!(n.count_ones(), 3); /// assert_eq!(n.count_ones(), 3);
@ -215,6 +217,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0b01001100u8; /// let n = 0b01001100u8;
/// ///
/// assert_eq!(n.count_zeros(), 5); /// assert_eq!(n.count_zeros(), 5);
@ -230,6 +234,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0b0101000u16; /// let n = 0b0101000u16;
/// ///
/// assert_eq!(n.leading_zeros(), 10); /// assert_eq!(n.leading_zeros(), 10);
@ -242,6 +248,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0b0101000u16; /// let n = 0b0101000u16;
/// ///
/// assert_eq!(n.trailing_zeros(), 3); /// assert_eq!(n.trailing_zeros(), 3);
@ -254,6 +262,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// let m = 0x3456789ABCDEF012u64; /// let m = 0x3456789ABCDEF012u64;
/// ///
@ -267,6 +277,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// let m = 0xDEF0123456789ABCu64; /// let m = 0xDEF0123456789ABCu64;
/// ///
@ -279,6 +291,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// let m = 0xEFCDAB8967452301u64; /// let m = 0xEFCDAB8967452301u64;
/// ///
@ -293,6 +307,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// ///
/// if cfg!(target_endian = "big") { /// if cfg!(target_endian = "big") {
@ -313,6 +329,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// ///
/// if cfg!(target_endian = "little") { /// if cfg!(target_endian = "little") {
@ -333,6 +351,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// ///
/// if cfg!(target_endian = "big") { /// if cfg!(target_endian = "big") {
@ -353,6 +373,8 @@ pub trait Int
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::num::Int;
///
/// let n = 0x0123456789ABCDEFu64; /// let n = 0x0123456789ABCDEFu64;
/// ///
/// if cfg!(target_endian = "little") { /// if cfg!(target_endian = "little") {

View file

@ -51,9 +51,7 @@ pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
pub use iter::{FromIterator, Extend}; pub use iter::{FromIterator, Extend};
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator}; pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize}; pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
pub use num::{Num, NumCast}; pub use num::{Signed, ToPrimitive, FromPrimitive};
pub use num::{Signed, Unsigned, Float};
pub use num::{Primitive, Int, ToPrimitive, FromPrimitive};
pub use option::{Option, Some, None}; pub use option::{Option, Some, None};
pub use ptr::RawPtr; pub use ptr::RawPtr;
pub use result::{Result, Ok, Err}; pub use result::{Result, Ok, Err};

View file

@ -12,7 +12,6 @@ use core::iter::*;
use core::iter::order::*; use core::iter::order::*;
use core::uint; use core::uint;
use core::cmp; use core::cmp;
use core::num;
use core::ops::Slice; use core::ops::Slice;
use test::Bencher; use test::Bencher;
@ -689,50 +688,6 @@ fn test_double_ended_range() {
#[test] #[test]
fn test_range() { fn test_range() {
/// A mock type to check Range when ToPrimitive returns None
struct Foo;
impl ToPrimitive for Foo {
fn to_i64(&self) -> Option<i64> { None }
fn to_u64(&self) -> Option<u64> { None }
}
impl Add<Foo, Foo> for Foo {
fn add(&self, _: &Foo) -> Foo {
Foo
}
}
impl PartialEq for Foo {
fn eq(&self, _: &Foo) -> bool {
true
}
}
impl PartialOrd for Foo {
fn partial_cmp(&self, _: &Foo) -> Option<Ordering> {
None
}
}
impl Clone for Foo {
fn clone(&self) -> Foo {
Foo
}
}
impl Mul<Foo, Foo> for Foo {
fn mul(&self, _: &Foo) -> Foo {
Foo
}
}
impl num::One for Foo {
fn one() -> Foo {
Foo
}
}
assert!(range(0i, 5).collect::<Vec<int>>() == vec![0i, 1, 2, 3, 4]); assert!(range(0i, 5).collect::<Vec<int>>() == vec![0i, 1, 2, 3, 4]);
assert!(range(-10i, -1).collect::<Vec<int>>() == assert!(range(-10i, -1).collect::<Vec<int>>() ==
vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]); vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]);
@ -746,7 +701,6 @@ fn test_range() {
// this test is only meaningful when sizeof uint < sizeof u64 // this test is only meaningful when sizeof uint < sizeof u64
assert_eq!(range(uint::MAX - 1, uint::MAX).size_hint(), (1, Some(1))); assert_eq!(range(uint::MAX - 1, uint::MAX).size_hint(), (1, Some(1)));
assert_eq!(range(-10i, -1).size_hint(), (9, Some(9))); assert_eq!(range(-10i, -1).size_hint(), (9, Some(9)));
assert_eq!(range(Foo, Foo).size_hint(), (0, None));
} }
#[test] #[test]

View file

@ -15,6 +15,7 @@ macro_rules! int_module (($T:ty, $T_i:ident) => (
mod tests { mod tests {
use core::$T_i::*; use core::$T_i::*;
use core::int; use core::int;
use core::num::Int;
use num; use num;
#[test] #[test]

View file

@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use core::num::cast; use core::cmp::PartialEq;
use core::fmt::Show;
use core::num::{NumCast, cast};
use core::ops::{Add, Sub, Mul, Div, Rem};
mod int_macros; mod int_macros;
mod i8; mod i8;
@ -24,7 +27,12 @@ mod u64;
mod uint; mod uint;
/// Helper function for testing numeric operations /// Helper function for testing numeric operations
pub fn test_num<T: Int + ::std::fmt::Show>(ten: T, two: T) { pub fn test_num<T>(ten: T, two: T) where
T: PartialEq + NumCast
+ Add<T, T> + Sub<T, T>
+ Mul<T, T> + Div<T, T>
+ Rem<T, T> + Show
{
assert_eq!(ten.add(&two), cast(12i).unwrap()); assert_eq!(ten.add(&two), cast(12i).unwrap());
assert_eq!(ten.sub(&two), cast(8i).unwrap()); assert_eq!(ten.sub(&two), cast(8i).unwrap());
assert_eq!(ten.mul(&two), cast(20i).unwrap()); assert_eq!(ten.mul(&two), cast(20i).unwrap());

View file

@ -14,6 +14,7 @@ macro_rules! uint_module (($T:ty, $T_i:ident) => (
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use core::$T_i::*; use core::$T_i::*;
use core::num::Int;
use num; use num;
#[test] #[test]

View file

@ -11,6 +11,7 @@
//! The ChaCha random number generator. //! The ChaCha random number generator.
use core::prelude::*; use core::prelude::*;
use core::num::Int;
use {Rng, SeedableRng, Rand}; use {Rng, SeedableRng, Rand};

View file

@ -23,6 +23,7 @@ that do not need to record state.
#![experimental] #![experimental]
use core::prelude::*; use core::prelude::*;
use core::num::Int;
use {Rng, Rand}; use {Rng, Rand};

View file

@ -13,6 +13,7 @@
// this is surprisingly complicated to be both generic & correct // this is surprisingly complicated to be both generic & correct
use core::prelude::*; use core::prelude::*;
use core::num::Int;
use Rng; use Rng;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
@ -162,6 +163,7 @@ float_impl! { f64 }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::num::Int;
use std::prelude::*; use std::prelude::*;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
use super::Range; use super::Range;

View file

@ -114,10 +114,11 @@ pub enum Error {
pub mod reader { pub mod reader {
use std::char; use std::char;
use std::mem::transmute;
use std::int; use std::int;
use std::option::{None, Option, Some};
use std::io::extensions::u64_from_be_bytes; use std::io::extensions::u64_from_be_bytes;
use std::mem::transmute;
use std::num::Int;
use std::option::{None, Option, Some};
use serialize; use serialize;

View file

@ -23,6 +23,7 @@ use flate;
use std::iter; use std::iter;
use std::mem; use std::mem;
use std::num::Int;
pub fn run(sess: &session::Session, llmod: ModuleRef, pub fn run(sess: &session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[String]) { tm: TargetMachineRef, reachable: &[String]) {

View file

@ -21,6 +21,7 @@ use middle::ty;
use std::fmt; use std::fmt;
use std::iter::AdditiveIterator; use std::iter::AdditiveIterator;
use std::iter::range_inclusive; use std::iter::range_inclusive;
use std::num::Float;
use std::slice; use std::slice;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast_util::walk_pat; use syntax::ast_util::walk_pat;

View file

@ -21,6 +21,7 @@ use util::ppaux::Repr;
use middle::trans::type_::Type; use middle::trans::type_::Type;
use std::num::Int;
use syntax::abi; use syntax::abi;
use syntax::ast; use syntax::ast;

View file

@ -15,6 +15,7 @@
#![allow(deprecated)] // to_be32 #![allow(deprecated)] // to_be32
use std::iter::range_step; use std::iter::range_step;
use std::num::Int;
use std::slice::bytes::{MutableByteVector, copy_memory}; use std::slice::bytes::{MutableByteVector, copy_memory};
use serialize::hex::ToHex; use serialize::hex::ToHex;
@ -530,6 +531,7 @@ mod tests {
use self::rand::isaac::IsaacRng; use self::rand::isaac::IsaacRng;
use self::rand::Rng; use self::rand::Rng;
use serialize::hex::FromHex; use serialize::hex::FromHex;
use std::num::Int;
// A normal addition - no overflow occurs // A normal addition - no overflow occurs
#[test] #[test]

View file

@ -199,7 +199,7 @@ use std::collections::{HashMap, TreeMap};
use std::{char, f64, fmt, io, num, str}; use std::{char, f64, fmt, io, num, str};
use std::io::MemWriter; use std::io::MemWriter;
use std::mem::{swap, transmute}; use std::mem::{swap, transmute};
use std::num::{FPNaN, FPInfinite}; use std::num::{Float, FPNaN, FPInfinite, Int};
use std::str::ScalarValue; use std::str::ScalarValue;
use std::string; use std::string;
use std::vec::Vec; use std::vec::Vec;
@ -2455,6 +2455,7 @@ mod tests {
TrailingCharacters, TrailingComma}; TrailingCharacters, TrailingComma};
use std::{i64, u64, f32, f64, io}; use std::{i64, u64, f32, f64, io};
use std::collections::TreeMap; use std::collections::TreeMap;
use std::num::Float;
use std::string; use std::string;
#[deriving(Decodable, Eq, PartialEq, Show)] #[deriving(Decodable, Eq, PartialEq, Show)]

View file

@ -190,6 +190,7 @@ like:
```rust ```rust
use std::fmt; use std::fmt;
use std::f64; use std::f64;
use std::num::Float;
struct Vector2D { struct Vector2D {
x: int, x: int,

View file

@ -20,6 +20,7 @@ use prelude::*;
use from_str::FromStr; use from_str::FromStr;
use intrinsics; use intrinsics;
use libc::c_int; use libc::c_int;
use num::{Float, FloatMath};
use num::strconv; use num::strconv;
use num; use num;

View file

@ -19,6 +19,7 @@ use prelude::*;
use from_str::FromStr; use from_str::FromStr;
use intrinsics; use intrinsics;
use libc::c_int; use libc::c_int;
use num::{Float, FloatMath};
use num::strconv; use num::strconv;
use num; use num;

View file

@ -18,7 +18,9 @@
use option::Option; use option::Option;
#[cfg(test)] use cmp::PartialEq;
#[cfg(test)] use fmt::Show; #[cfg(test)] use fmt::Show;
#[cfg(test)] use ops::{Add, Sub, Mul, Div, Rem};
pub use core::num::{Num, div_rem, Zero, zero, One, one}; pub use core::num::{Num, div_rem, Zero, zero, One, one};
pub use core::num::{Signed, abs, signum}; pub use core::num::{Signed, abs, signum};
@ -135,7 +137,12 @@ pub fn abs_sub<T: FloatMath>(x: T, y: T) -> T {
/// Helper function for testing numeric operations /// Helper function for testing numeric operations
#[cfg(test)] #[cfg(test)]
pub fn test_num<T: Int + Show>(ten: T, two: T) { pub fn test_num<T>(ten: T, two: T) where
T: PartialEq + NumCast
+ Add<T, T> + Sub<T, T>
+ Mul<T, T> + Div<T, T>
+ Rem<T, T> + Show
{
assert_eq!(ten.add(&two), cast(12i).unwrap()); assert_eq!(ten.add(&two), cast(12i).unwrap());
assert_eq!(ten.sub(&two), cast(8i).unwrap()); assert_eq!(ten.sub(&two), cast(8i).unwrap());
assert_eq!(ten.mul(&two), cast(20i).unwrap()); assert_eq!(ten.mul(&two), cast(20i).unwrap());

View file

@ -67,9 +67,7 @@
#[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator}; #[doc(no_inline)] pub use iter::{Iterator, DoubleEndedIterator};
#[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator}; #[doc(no_inline)] pub use iter::{RandomAccessIterator, CloneableIterator};
#[doc(no_inline)] pub use iter::{OrdIterator, MutableDoubleEndedIterator}; #[doc(no_inline)] pub use iter::{OrdIterator, MutableDoubleEndedIterator};
#[doc(no_inline)] pub use num::{Num, NumCast}; #[doc(no_inline)] pub use num::{Signed, ToPrimitive, FromPrimitive};
#[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float};
#[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive};
#[doc(no_inline)] pub use boxed::Box; #[doc(no_inline)] pub use boxed::Box;
#[doc(no_inline)] pub use option::{Option, Some, None}; #[doc(no_inline)] pub use option::{Option, Some, None};
#[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath}; #[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};

View file

@ -78,6 +78,7 @@ mod test {
use super::ReaderRng; use super::ReaderRng;
use io::MemReader; use io::MemReader;
use num::Int;
use rand::Rng; use rand::Rng;
#[test] #[test]

View file

@ -15,6 +15,7 @@ use io::{mod, IoError, IoResult};
use prelude::*; use prelude::*;
use sys::{last_error, retry, fs}; use sys::{last_error, retry, fs};
use c_str::CString; use c_str::CString;
use num::Int;
use path::BytesContainer; use path::BytesContainer;
use collections; use collections;

View file

@ -11,6 +11,7 @@
use alloc::arc::Arc; use alloc::arc::Arc;
use libc::{mod, c_char, c_int}; use libc::{mod, c_char, c_int};
use mem; use mem;
use num::Int;
use ptr::{mod, null, null_mut}; use ptr::{mod, null, null_mut};
use rt::mutex; use rt::mutex;
use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr}; use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};

View file

@ -18,6 +18,7 @@
extern crate libc; extern crate libc;
use num; use num;
use num::Int;
use prelude::*; use prelude::*;
use io::{mod, IoResult, IoError}; use io::{mod, IoResult, IoError};
use sys_common::mkerr_libc; use sys_common::mkerr_libc;

View file

@ -20,6 +20,7 @@ use ptr::P;
use std::fmt; use std::fmt;
use std::fmt::Show; use std::fmt::Show;
use std::num::Int;
use std::rc::Rc; use std::rc::Rc;
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};

View file

@ -20,6 +20,7 @@ use ptr::P;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::io::File; use std::io::File;
use std::rc::Rc; use std::rc::Rc;
use std::num::Int;
use std::str; use std::str;
use std::iter; use std::iter;

View file

@ -87,6 +87,7 @@ use std::collections::HashSet;
use std::io::fs::PathExtensions; use std::io::fs::PathExtensions;
use std::mem::replace; use std::mem::replace;
use std::mem; use std::mem;
use std::num::Float;
use std::rc::Rc; use std::rc::Rc;
use std::iter; use std::iter;

View file

@ -60,6 +60,7 @@ use std::io::fs::PathExtensions;
use std::io::stdio::StdWriter; use std::io::stdio::StdWriter;
use std::io::{File, ChanReader, ChanWriter}; use std::io::{File, ChanReader, ChanWriter};
use std::io; use std::io;
use std::num::{Int, FloatMath};
use std::os; use std::os;
use std::string::String; use std::string::String;
use std::task::TaskBuilder; use std::task::TaskBuilder;

View file

@ -16,6 +16,7 @@ use std::fmt::Show;
use std::hash::Hash; use std::hash::Hash;
use std::io; use std::io;
use std::mem; use std::mem;
use std::num::{Float, FloatMath};
fn local_cmp<T:Float>(x: T, y: T) -> Ordering { fn local_cmp<T:Float>(x: T, y: T) -> Ordering {
// arbitrarily decide that NaNs are larger than everything. // arbitrarily decide that NaNs are larger than everything.
@ -1042,11 +1043,11 @@ mod tests {
} }
#[test] #[test]
fn test_sum_f64s() { fn test_sum_f64s() {
assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(0.0), 5.2999); assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999);
} }
#[test] #[test]
fn test_sum_f64_between_ints_that_sum_to_0() { fn test_sum_f64_between_ints_that_sum_to_0() {
assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(0.0), 1.2); assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(), 1.2);
} }
} }
@ -1058,7 +1059,7 @@ mod bench {
#[bench] #[bench]
pub fn sum_three_items(b: &mut Bencher) { pub fn sum_three_items(b: &mut Bencher) {
b.iter(|| { b.iter(|| {
[1e20f64, 1.5f64, -1e20f64].sum(0.0); [1e20f64, 1.5f64, -1e20f64].sum();
}) })
} }
#[bench] #[bench]
@ -1067,7 +1068,7 @@ mod bench {
let v = Vec::from_fn(500, |i| nums[i%5]); let v = Vec::from_fn(500, |i| nums[i%5]);
b.iter(|| { b.iter(|| {
v.as_slice().sum(0.0); v.as_slice().sum();
}) })
} }
} }

View file

@ -13,6 +13,7 @@
// ignore-lexer-test FIXME #15679 // ignore-lexer-test FIXME #15679
use std::f32::consts::PI; use std::f32::consts::PI;
use std::num::{Float, FloatMath};
use std::rand::{Rng, StdRng}; use std::rand::{Rng, StdRng};
struct Vec2 { struct Vec2 {

View file

@ -43,6 +43,7 @@
use std::io; use std::io;
use std::io::{BufferedWriter, File}; use std::io::{BufferedWriter, File};
use std::cmp::min; use std::cmp::min;
use std::num::Float;
use std::os; use std::os;
const LINE_LENGTH: uint = 60; const LINE_LENGTH: uint = 60;

View file

@ -19,6 +19,7 @@ extern crate collections;
use std::collections::HashMap; use std::collections::HashMap;
use std::mem::replace; use std::mem::replace;
use std::num::Float;
use std::option; use std::option;
use std::os; use std::os;
use std::string::String; use std::string::String;

View file

@ -38,6 +38,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE. // OF THE POSSIBILITY OF SUCH DAMAGE.
use std::num::Float;
const PI: f64 = 3.141592653589793; const PI: f64 = 3.141592653589793;
const SOLAR_MASS: f64 = 4.0 * PI * PI; const SOLAR_MASS: f64 = 4.0 * PI * PI;
const YEAR: f64 = 365.24; const YEAR: f64 = 365.24;

View file

@ -45,6 +45,7 @@
use std::iter::AdditiveIterator; use std::iter::AdditiveIterator;
use std::mem; use std::mem;
use std::num::Float;
use std::os; use std::os;
use std::raw::Repr; use std::raw::Repr;
use std::simd::f64x2; use std::simd::f64x2;

View file

@ -15,6 +15,7 @@
use std::io; use std::io;
use std::io::stdio::StdReader; use std::io::stdio::StdReader;
use std::io::BufferedReader; use std::io::BufferedReader;
use std::num::Int;
use std::os; use std::os;
// Computes a single solution to a given 9x9 sudoku // Computes a single solution to a given 9x9 sudoku

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::num::Int;
extern "C" fn foo<T: Int>(a: T, b: T) -> T { a + b } extern "C" fn foo<T: Int>(a: T, b: T) -> T { a + b }
fn main() { fn main() {

View file

@ -11,6 +11,7 @@
extern crate collections; extern crate collections;
use std::collections::Bitv; use std::collections::Bitv;
use std::num::Float;
fn main() { fn main() {
// Generate sieve of Eratosthenes for n up to 1e6 // Generate sieve of Eratosthenes for n up to 1e6

View file

@ -12,6 +12,7 @@
// A more complex example of numeric extensions // A more complex example of numeric extensions
use std::cmp::{PartialEq, PartialOrd}; use std::cmp::{PartialEq, PartialOrd};
use std::num::NumCast;
pub trait TypeExt {} pub trait TypeExt {}

View file

@ -11,11 +11,11 @@
use std::cmp::{PartialEq, PartialOrd}; use std::cmp::{PartialEq, PartialOrd};
use std::num::NumCast; use std::num::NumCast;
pub trait NumExt: PartialEq + PartialOrd + Num + NumCast {} pub trait NumExt: PartialEq + PartialOrd + NumCast {}
impl NumExt for f32 {} impl NumExt for f32 {}
fn num_eq_one<T:NumExt>(n: T) { fn num_eq_one<T: NumExt>(n: T) {
println!("{}", n == NumCast::from(1i).unwrap()) println!("{}", n == NumCast::from(1i).unwrap())
} }