Remove Signed trait and add SignedInt trait
The methods have been moved into Float and SignedInt
This commit is contained in:
@@ -97,7 +97,7 @@ syn keyword rustTrait FromIterator IntoIterator Extend ExactSize
|
|||||||
syn keyword rustTrait Iterator DoubleEndedIterator
|
syn keyword rustTrait Iterator DoubleEndedIterator
|
||||||
syn keyword rustTrait RandomAccessIterator CloneableIterator
|
syn keyword rustTrait RandomAccessIterator CloneableIterator
|
||||||
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator
|
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator
|
||||||
syn keyword rustTrait NumCast Signed Int UnsignedInt Float
|
syn keyword rustTrait NumCast Int SignedInt UnsignedInt Float
|
||||||
syn keyword rustTrait FloatMath ToPrimitive FromPrimitive
|
syn keyword rustTrait FloatMath ToPrimitive FromPrimitive
|
||||||
syn keyword rustTrait Box
|
syn keyword rustTrait Box
|
||||||
syn keyword rustTrait GenericPath Path PosixPath WindowsPath
|
syn keyword rustTrait GenericPath Path PosixPath WindowsPath
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
//! operators, you could do the following:
|
//! operators, you could do the following:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
|
//! use core::num::SignedInt;
|
||||||
|
//!
|
||||||
//! // Our type.
|
//! // Our type.
|
||||||
//! struct SketchyNum {
|
//! struct SketchyNum {
|
||||||
//! num : int
|
//! num : int
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ impl<'a, T> Pointer for &'a mut T {
|
|||||||
macro_rules! floating(($ty:ident) => {
|
macro_rules! floating(($ty:ident) => {
|
||||||
impl Float for $ty {
|
impl Float for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::{Float, Signed};
|
use num::Float;
|
||||||
|
|
||||||
let digits = match fmt.precision {
|
let digits = match fmt.precision {
|
||||||
Some(i) => float::DigExact(i),
|
Some(i) => float::DigExact(i),
|
||||||
@@ -641,7 +641,7 @@ macro_rules! floating(($ty:ident) => {
|
|||||||
|
|
||||||
impl LowerExp for $ty {
|
impl LowerExp for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::{Float, Signed};
|
use num::Float;
|
||||||
|
|
||||||
let digits = match fmt.precision {
|
let digits = match fmt.precision {
|
||||||
Some(i) => float::DigExact(i),
|
Some(i) => float::DigExact(i),
|
||||||
@@ -662,7 +662,7 @@ macro_rules! floating(($ty:ident) => {
|
|||||||
|
|
||||||
impl UpperExp for $ty {
|
impl UpperExp for $ty {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||||
use num::{Float, Signed};
|
use num::Float;
|
||||||
|
|
||||||
let digits = match fmt.precision {
|
let digits = match fmt.precision {
|
||||||
Some(i) => float::DigExact(i),
|
Some(i) => float::DigExact(i),
|
||||||
|
|||||||
@@ -573,6 +573,8 @@ pub trait Iterator<A> {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// use core::num::SignedInt;
|
||||||
|
///
|
||||||
/// let xs = [-3i, 0, 1, 5, -10];
|
/// let xs = [-3i, 0, 1, 5, -10];
|
||||||
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
|
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
|
||||||
/// ```
|
/// ```
|
||||||
@@ -597,6 +599,8 @@ pub trait Iterator<A> {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// use core::num::SignedInt;
|
||||||
|
///
|
||||||
/// let xs = [-3i, 0, 1, 5, -10];
|
/// let xs = [-3i, 0, 1, 5, -10];
|
||||||
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
|
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
|
||||||
/// ```
|
/// ```
|
||||||
|
|||||||
@@ -242,6 +242,41 @@ impl Float for f32 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn fract(self) -> f32 { self - self.trunc() }
|
fn fract(self) -> f32 { self - self.trunc() }
|
||||||
|
|
||||||
|
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
|
||||||
|
/// number is `Float::nan()`.
|
||||||
|
#[inline]
|
||||||
|
fn abs(self) -> f32 {
|
||||||
|
unsafe { intrinsics::fabsf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a number that represents the sign of `self`.
|
||||||
|
///
|
||||||
|
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
|
||||||
|
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
|
||||||
|
/// - `Float::nan()` if the number is `Float::nan()`
|
||||||
|
#[inline]
|
||||||
|
fn signum(self) -> f32 {
|
||||||
|
if self.is_nan() {
|
||||||
|
Float::nan()
|
||||||
|
} else {
|
||||||
|
unsafe { intrinsics::copysignf32(1.0, self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive, including `+0.0` and
|
||||||
|
/// `Float::infinity()`.
|
||||||
|
#[inline]
|
||||||
|
fn is_positive(self) -> bool {
|
||||||
|
self > 0.0 || (1.0 / self) == Float::infinity()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is negative, including `-0.0` and
|
||||||
|
/// `Float::neg_infinity()`.
|
||||||
|
#[inline]
|
||||||
|
fn is_negative(self) -> bool {
|
||||||
|
self < 0.0 || (1.0 / self) == Float::neg_infinity()
|
||||||
|
}
|
||||||
|
|
||||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
||||||
/// error. This produces a more accurate result with better performance than
|
/// error. This produces a more accurate result with better performance than
|
||||||
/// a separate multiplication operation followed by an add.
|
/// a separate multiplication operation followed by an add.
|
||||||
@@ -254,6 +289,7 @@ impl Float for f32 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn recip(self) -> f32 { 1.0 / self }
|
fn recip(self) -> f32 { 1.0 / self }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn powi(self, n: i32) -> f32 {
|
fn powi(self, n: i32) -> f32 {
|
||||||
unsafe { intrinsics::powif32(self, n) }
|
unsafe { intrinsics::powif32(self, n) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,6 +248,41 @@ impl Float for f64 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn fract(self) -> f64 { self - self.trunc() }
|
fn fract(self) -> f64 { self - self.trunc() }
|
||||||
|
|
||||||
|
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
|
||||||
|
/// number is `Float::nan()`.
|
||||||
|
#[inline]
|
||||||
|
fn abs(self) -> f64 {
|
||||||
|
unsafe { intrinsics::fabsf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a number that represents the sign of `self`.
|
||||||
|
///
|
||||||
|
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
|
||||||
|
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
|
||||||
|
/// - `Float::nan()` if the number is `Float::nan()`
|
||||||
|
#[inline]
|
||||||
|
fn signum(self) -> f64 {
|
||||||
|
if self.is_nan() {
|
||||||
|
Float::nan()
|
||||||
|
} else {
|
||||||
|
unsafe { intrinsics::copysignf64(1.0, self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive, including `+0.0` and
|
||||||
|
/// `Float::infinity()`.
|
||||||
|
#[inline]
|
||||||
|
fn is_positive(self) -> bool {
|
||||||
|
self > 0.0 || (1.0 / self) == Float::infinity()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is negative, including `-0.0` and
|
||||||
|
/// `Float::neg_infinity()`.
|
||||||
|
#[inline]
|
||||||
|
fn is_negative(self) -> bool {
|
||||||
|
self < 0.0 || (1.0 / self) == Float::neg_infinity()
|
||||||
|
}
|
||||||
|
|
||||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
||||||
/// error. This produces a more accurate result with better performance than
|
/// error. This produces a more accurate result with better performance than
|
||||||
/// a separate multiplication operation followed by an add.
|
/// a separate multiplication operation followed by an add.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
macro_rules! assert_approx_eq(
|
macro_rules! assert_approx_eq(
|
||||||
($a:expr, $b:expr) => ({
|
($a:expr, $b:expr) => ({
|
||||||
|
use num::Float;
|
||||||
let (a, b) = (&$a, &$b);
|
let (a, b) = (&$a, &$b);
|
||||||
assert!((*a - *b).abs() < 1.0e-6,
|
assert!((*a - *b).abs() < 1.0e-6,
|
||||||
"{} is not approximately equal to {}", *a, *b);
|
"{} is not approximately equal to {}", *a, *b);
|
||||||
|
|||||||
@@ -33,113 +33,6 @@ pub fn div_rem<T: Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
|
|||||||
(x / y, x % y)
|
(x / y, x % y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A built-in signed number.
|
|
||||||
pub trait Signed: Neg<Self> {
|
|
||||||
/// Computes the absolute value of `self`.
|
|
||||||
fn abs(self) -> Self;
|
|
||||||
|
|
||||||
/// Returns a number (either `-1`, `0` or `1`) representing sign of `self`.
|
|
||||||
fn signum(self) -> Self;
|
|
||||||
|
|
||||||
/// Returns `true` if `self` is a positive value.
|
|
||||||
fn is_positive(self) -> bool;
|
|
||||||
|
|
||||||
/// Returns `true` if `self` is a negative value.
|
|
||||||
fn is_negative(self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! signed_int_impl {
|
|
||||||
($T:ty) => {
|
|
||||||
impl Signed for $T {
|
|
||||||
/// Computes the absolute value. `Int::min_value()` will be returned
|
|
||||||
/// if the number is `Int::min_value()`.
|
|
||||||
#[inline]
|
|
||||||
fn abs(self) -> $T {
|
|
||||||
if self.is_negative() { -self } else { self }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// - `0` if the number is zero
|
|
||||||
/// - `1` if the number is positive
|
|
||||||
/// - `-1` if the number is negative
|
|
||||||
#[inline]
|
|
||||||
fn signum(self) -> $T {
|
|
||||||
match self {
|
|
||||||
n if n > 0 => 1,
|
|
||||||
0 => 0,
|
|
||||||
_ => -1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if `self` is positive and `false` if the number
|
|
||||||
/// is zero or negative.
|
|
||||||
#[inline]
|
|
||||||
fn is_positive(self) -> bool { self > 0 }
|
|
||||||
|
|
||||||
/// Returns `true` if `self` is negative and `false` if the number
|
|
||||||
/// is zero or positive.
|
|
||||||
#[inline]
|
|
||||||
fn is_negative(self) -> bool { self < 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signed_int_impl!(i8)
|
|
||||||
signed_int_impl!(i16)
|
|
||||||
signed_int_impl!(i32)
|
|
||||||
signed_int_impl!(i64)
|
|
||||||
signed_int_impl!(int)
|
|
||||||
|
|
||||||
macro_rules! signed_float_impl {
|
|
||||||
($T:ty, $fabs:path, $fcopysign:path) => {
|
|
||||||
impl Signed for $T {
|
|
||||||
/// Computes the absolute value. Returns `Float::nan()` if the
|
|
||||||
/// number is `Float::nan()`.
|
|
||||||
#[inline]
|
|
||||||
fn abs(self) -> $T {
|
|
||||||
unsafe { $fabs(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
|
|
||||||
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
|
|
||||||
/// - `Float::nan()` if the number is `Float::nan()`
|
|
||||||
#[inline]
|
|
||||||
fn signum(self) -> $T {
|
|
||||||
if self.is_nan() {
|
|
||||||
Float::nan()
|
|
||||||
} else {
|
|
||||||
unsafe { $fcopysign(1.0, self) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if the number is positive, including `+0.0` and
|
|
||||||
/// `Float::infinity()`.
|
|
||||||
#[inline]
|
|
||||||
fn is_positive(self) -> bool {
|
|
||||||
self > 0.0 || (1.0 / self) == Float::infinity()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if the number is negative, including `-0.0` and
|
|
||||||
/// `Float::neg_infinity()`.
|
|
||||||
#[inline]
|
|
||||||
fn is_negative(self) -> bool {
|
|
||||||
self < 0.0 || (1.0 / self) == Float::neg_infinity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
signed_float_impl!(f32,
|
|
||||||
intrinsics::fabsf32,
|
|
||||||
intrinsics::copysignf32)
|
|
||||||
|
|
||||||
signed_float_impl!(f64,
|
|
||||||
intrinsics::fabsf64,
|
|
||||||
intrinsics::copysignf64)
|
|
||||||
|
|
||||||
/// Raises a `base` to the power of `exp`, using exponentiation by squaring.
|
/// Raises a `base` to the power of `exp`, using exponentiation by squaring.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@@ -702,6 +595,63 @@ int_impl!(int = i64, u64, 64,
|
|||||||
intrinsics::i64_sub_with_overflow,
|
intrinsics::i64_sub_with_overflow,
|
||||||
intrinsics::i64_mul_with_overflow)
|
intrinsics::i64_mul_with_overflow)
|
||||||
|
|
||||||
|
/// A built-in two's complement integer.
|
||||||
|
pub trait SignedInt
|
||||||
|
: Int
|
||||||
|
+ Neg<Self>
|
||||||
|
{
|
||||||
|
/// Computes the absolute value of `self`. `Int::min_value()` will be
|
||||||
|
/// returned if the number is `Int::min_value()`.
|
||||||
|
fn abs(self) -> Self;
|
||||||
|
|
||||||
|
/// Returns a number representing sign of `self`.
|
||||||
|
///
|
||||||
|
/// - `0` if the number is zero
|
||||||
|
/// - `1` if the number is positive
|
||||||
|
/// - `-1` if the number is negative
|
||||||
|
fn signum(self) -> Self;
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive and `false` if the number
|
||||||
|
/// is zero or negative.
|
||||||
|
fn is_positive(self) -> bool;
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is negative and `false` if the number
|
||||||
|
/// is zero or positive.
|
||||||
|
fn is_negative(self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! signed_int_impl {
|
||||||
|
($T:ty) => {
|
||||||
|
impl SignedInt for $T {
|
||||||
|
#[inline]
|
||||||
|
fn abs(self) -> $T {
|
||||||
|
if self.is_negative() { -self } else { self }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn signum(self) -> $T {
|
||||||
|
match self {
|
||||||
|
n if n > 0 => 1,
|
||||||
|
0 => 0,
|
||||||
|
_ => -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_positive(self) -> bool { self > 0 }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_negative(self) -> bool { self < 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signed_int_impl!(i8)
|
||||||
|
signed_int_impl!(i16)
|
||||||
|
signed_int_impl!(i32)
|
||||||
|
signed_int_impl!(i64)
|
||||||
|
signed_int_impl!(int)
|
||||||
|
|
||||||
/// A built-in unsigned integer.
|
/// A built-in unsigned integer.
|
||||||
pub trait UnsignedInt: Int {
|
pub trait UnsignedInt: Int {
|
||||||
/// Returns `true` iff `self == 2^k` for some `k`.
|
/// Returns `true` iff `self == 2^k` for some `k`.
|
||||||
@@ -1257,7 +1207,7 @@ pub trait Float
|
|||||||
+ NumCast
|
+ NumCast
|
||||||
+ PartialOrd
|
+ PartialOrd
|
||||||
+ PartialEq
|
+ PartialEq
|
||||||
+ Signed
|
+ Neg<Self>
|
||||||
+ Add<Self,Self>
|
+ Add<Self,Self>
|
||||||
+ Sub<Self,Self>
|
+ Sub<Self,Self>
|
||||||
+ Mul<Self,Self>
|
+ Mul<Self,Self>
|
||||||
@@ -1327,6 +1277,22 @@ pub trait Float
|
|||||||
/// Return the fractional part of a number.
|
/// Return the fractional part of a number.
|
||||||
fn fract(self) -> Self;
|
fn fract(self) -> Self;
|
||||||
|
|
||||||
|
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
|
||||||
|
/// number is `Float::nan()`.
|
||||||
|
fn abs(self) -> Self;
|
||||||
|
/// Returns a number that represents the sign of `self`.
|
||||||
|
///
|
||||||
|
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
|
||||||
|
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
|
||||||
|
/// - `Float::nan()` if the number is `Float::nan()`
|
||||||
|
fn signum(self) -> Self;
|
||||||
|
/// Returns `true` if `self` is positive, including `+0.0` and
|
||||||
|
/// `Float::infinity()`.
|
||||||
|
fn is_positive(self) -> bool;
|
||||||
|
/// Returns `true` if `self` is negative, including `-0.0` and
|
||||||
|
/// `Float::neg_infinity()`.
|
||||||
|
fn is_negative(self) -> bool;
|
||||||
|
|
||||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
||||||
/// error. This produces a more accurate result with better performance than
|
/// error. This produces a more accurate result with better performance than
|
||||||
/// a separate multiplication operation followed by an add.
|
/// a separate multiplication operation followed by an add.
|
||||||
@@ -1494,14 +1460,6 @@ one_impl!(i64, 1i64)
|
|||||||
one_impl!(f32, 1.0f32)
|
one_impl!(f32, 1.0f32)
|
||||||
one_impl!(f64, 1.0f64)
|
one_impl!(f64, 1.0f64)
|
||||||
|
|
||||||
#[deprecated = "Use `Signed::abs`"]
|
|
||||||
pub fn abs<T: Signed>(value: T) -> T {
|
|
||||||
value.abs()
|
|
||||||
}
|
|
||||||
#[deprecated = "Use `Signed::signum`"]
|
|
||||||
pub fn signum<T: Signed>(value: T) -> T {
|
|
||||||
value.signum()
|
|
||||||
}
|
|
||||||
#[deprecated = "Use `UnsignedInt::next_power_of_two`"]
|
#[deprecated = "Use `UnsignedInt::next_power_of_two`"]
|
||||||
pub fn next_power_of_two<T: UnsignedInt>(n: T) -> T {
|
pub fn next_power_of_two<T: UnsignedInt>(n: T) -> T {
|
||||||
n.next_power_of_two()
|
n.next_power_of_two()
|
||||||
|
|||||||
@@ -51,7 +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::{Signed, ToPrimitive, FromPrimitive};
|
pub use num::{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};
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ fn test_partial_max() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_user_defined_eq() {
|
fn test_user_defined_eq() {
|
||||||
|
use core::num::SignedInt;
|
||||||
|
|
||||||
// Our type.
|
// Our type.
|
||||||
struct SketchyNum {
|
struct SketchyNum {
|
||||||
num : int
|
num : int
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
use core::iter::*;
|
use core::iter::*;
|
||||||
use core::iter::order::*;
|
use core::iter::order::*;
|
||||||
|
use core::num::SignedInt;
|
||||||
use core::uint;
|
use core::uint;
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::ops::Slice;
|
use core::ops::Slice;
|
||||||
|
|||||||
@@ -15,7 +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 core::num::{Int, SignedInt};
|
||||||
use num;
|
use num;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ that do not need to record state.
|
|||||||
#![experimental]
|
#![experimental]
|
||||||
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use core::num::Int;
|
use core::num::{Float, Int};
|
||||||
|
|
||||||
use {Rng, Rand};
|
use {Rng, Rand};
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ use lint::{Context, LintPass, LintArray};
|
|||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::hash_map::{Occupied, Vacant};
|
use std::collections::hash_map::{Occupied, Vacant};
|
||||||
|
use std::num::SignedInt;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
|
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
|
||||||
use syntax::abi;
|
use syntax::abi;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
macro_rules! assert_approx_eq(
|
macro_rules! assert_approx_eq(
|
||||||
($a:expr, $b:expr) => ({
|
($a:expr, $b:expr) => ({
|
||||||
|
use num::Float;
|
||||||
let (a, b) = (&$a, &$b);
|
let (a, b) = (&$a, &$b);
|
||||||
assert!((*a - *b).abs() < 1.0e-6,
|
assert!((*a - *b).abs() < 1.0e-6,
|
||||||
"{} is not approximately equal to {}", *a, *b);
|
"{} is not approximately equal to {}", *a, *b);
|
||||||
|
|||||||
@@ -23,9 +23,8 @@ use option::Option;
|
|||||||
#[cfg(test)] use ops::{Add, Sub, Mul, Div, Rem};
|
#[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::{Unsigned, pow, Bounded};
|
pub use core::num::{Unsigned, pow, Bounded};
|
||||||
pub use core::num::{Primitive, Int, UnsignedInt};
|
pub use core::num::{Primitive, Int, SignedInt, UnsignedInt};
|
||||||
pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive};
|
pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive};
|
||||||
pub use core::num::{next_power_of_two, is_power_of_two};
|
pub use core::num::{next_power_of_two, is_power_of_two};
|
||||||
pub use core::num::{checked_next_power_of_two};
|
pub use core::num::{checked_next_power_of_two};
|
||||||
|
|||||||
@@ -67,7 +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::{Signed, ToPrimitive, FromPrimitive};
|
#[doc(no_inline)] pub use num::{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};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use num;
|
use num;
|
||||||
use num::Int;
|
use num::{Int, SignedInt};
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
use io::{mod, IoResult, IoError};
|
use io::{mod, IoResult, IoError};
|
||||||
use sys_common::mkerr_libc;
|
use sys_common::mkerr_libc;
|
||||||
@@ -117,7 +117,7 @@ pub fn decode_error_detailed(errno: i32) -> IoError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn retry<T: Signed + Int> (f: || -> T) -> T {
|
pub fn retry<T: SignedInt> (f: || -> T) -> T {
|
||||||
let one: T = Int::one();
|
let one: T = Int::one();
|
||||||
loop {
|
loop {
|
||||||
let n = f();
|
let n = f();
|
||||||
|
|||||||
@@ -60,7 +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::num::{Float, FloatMath, Int};
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::task::TaskBuilder;
|
use std::task::TaskBuilder;
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ mod tests {
|
|||||||
|
|
||||||
macro_rules! assert_approx_eq(
|
macro_rules! assert_approx_eq(
|
||||||
($a:expr, $b:expr) => ({
|
($a:expr, $b:expr) => ({
|
||||||
|
use std::num::Float;
|
||||||
let (a, b) = (&$a, &$b);
|
let (a, b) = (&$a, &$b);
|
||||||
assert!((*a - *b).abs() < 1.0e-6,
|
assert!((*a - *b).abs() < 1.0e-6,
|
||||||
"{} is not approximately equal to {}", *a, *b);
|
"{} is not approximately equal to {}", *a, *b);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ extern crate libc;
|
|||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
use std::num::SignedInt;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|||||||
@@ -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::SignedInt;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _f = 10i.abs; //~ ERROR attempted to take value of method
|
let _f = 10i.abs; //~ ERROR attempted to take value of method
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
macro_rules! assert_approx_eq(
|
macro_rules! assert_approx_eq(
|
||||||
($a:expr, $b:expr) => ({
|
($a:expr, $b:expr) => ({
|
||||||
|
use std::num::Float;
|
||||||
let (a, b) = (&$a, &$b);
|
let (a, b) = (&$a, &$b);
|
||||||
assert!((*a - *b).abs() < 1.0e-6,
|
assert!((*a - *b).abs() < 1.0e-6,
|
||||||
"{} is not approximately equal to {}", *a, *b);
|
"{} is not approximately equal to {}", *a, *b);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
macro_rules! assert_approx_eq(
|
macro_rules! assert_approx_eq(
|
||||||
($a:expr, $b:expr) => ({
|
($a:expr, $b:expr) => ({
|
||||||
|
use std::num::Float;
|
||||||
let (a, b) = (&$a, &$b);
|
let (a, b) = (&$a, &$b);
|
||||||
assert!((*a - *b).abs() < 1.0e-6,
|
assert!((*a - *b).abs() < 1.0e-6,
|
||||||
"{} is not approximately equal to {}", *a, *b);
|
"{} is not approximately equal to {}", *a, *b);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
// Test for issue #4183: use of Self in supertraits.
|
// Test for issue #4183: use of Self in supertraits.
|
||||||
|
|
||||||
|
use std::num::Float as StdFloat;
|
||||||
|
|
||||||
pub static FUZZY_EPSILON: f64 = 0.1;
|
pub static FUZZY_EPSILON: f64 = 0.1;
|
||||||
|
|
||||||
pub trait FuzzyEq<Eps> {
|
pub trait FuzzyEq<Eps> {
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
//
|
//
|
||||||
// ignore-lexer-test FIXME #15679
|
// ignore-lexer-test FIXME #15679
|
||||||
|
|
||||||
|
|
||||||
#![feature(non_ascii_idents)]
|
#![feature(non_ascii_idents)]
|
||||||
|
|
||||||
|
use std::num::Float;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let ε = 0.00001f64;
|
let ε = 0.00001f64;
|
||||||
let Π = 3.14f64;
|
let Π = 3.14f64;
|
||||||
|
|||||||
Reference in New Issue
Block a user