Skip to content

Commit

Permalink
Removed generic infinity, NaN and negative zero functions
Browse files Browse the repository at this point in the history
Removed Round impl for integers
  • Loading branch information
Kimundi committed Feb 15, 2013
1 parent df36a8d commit 3edc7c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 87 deletions.
12 changes: 0 additions & 12 deletions src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,6 @@ impl num::One for T {
static pure fn one() -> T { 1 }
}
impl num::Round for T {
#[inline(always)]
pure fn round(&self, _: num::RoundMode) -> T { *self }
#[inline(always)]
pure fn floor(&self) -> T { *self }
#[inline(always)]
pure fn ceil(&self) -> T { *self }
#[inline(always)]
pure fn fract(&self) -> T { 0 }
}
#[cfg(notest)]
impl ops::Add<T,T> for T {
pure fn add(&self, other: &T) -> T { *self + *other }
Expand Down
70 changes: 7 additions & 63 deletions src/libcore/num/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ pub trait Round {
pure fn fract(&self) -> Self;
}

pub enum RoundMode {
RoundDown,
RoundUp,
RoundToZero,
RoundFromZero
}

/**
* Cast a number the the enclosing type
*
Expand Down Expand Up @@ -82,13 +89,6 @@ pub trait NumCast {
pure fn to_float(&self) -> float;
}

pub enum RoundMode {
RoundDown,
RoundUp,
RoundToZero,
RoundFromZero
}

pub trait ToStrRadix {
pub pure fn to_str_radix(&self, radix: uint) -> ~str;
}
Expand All @@ -99,62 +99,6 @@ pub trait FromStrRadix {

// Generic math functions:

/// Dynamically calculates the value `inf` (`1/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn infinity<T:One+Zero+Div<T,T>>() -> T {
let _0: T = Zero::zero();
let _1: T = One::one();
_1 / _0
}

/// Dynamically calculates the value `-inf` (`-1/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn neg_infinity<T:One+Zero+Div<T,T>+Neg<T>>() -> T {
let _0: T = Zero::zero();
let _1: T = One::one();
- _1 / _0
}

/// Dynamically calculates the value `NaN` (`0/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn NaN<T:Zero+Div<T,T>>() -> T {
let _0: T = Zero::zero();
_0 / _0
}

/// Returns `true` if `num` has the value `inf` (`1/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn is_infinity<T:One+Zero+Eq+Div<T,T>>(num: &T) -> bool {
(*num) == (infinity::<T>())
}

/// Returns `true` if `num` has the value `-inf` (`-1/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn is_neg_infinity<T:One+Zero+Eq+Div<T,T>+Neg<T>>(num: &T)
-> bool {
(*num) == (neg_infinity::<T>())
}

/// Returns `true` if `num` has the value `NaN` (is not equal to itself).
#[inline(always)]
pub pure fn is_NaN<T:Eq>(num: &T) -> bool {
(*num) != (*num)
}

/// Returns `true` if `num` has the value `-0` (`1/num == -1/0`).
/// Can fail on integer types.
#[inline(always)]
pub pure fn is_neg_zero<T:One+Zero+Eq+Div<T,T>+Neg<T>>(num: &T) -> bool {
let _1: T = One::one();
let _0: T = Zero::zero();
*num == _0 && is_neg_infinity(&(_1 / *num))
}

/**
* Calculates a power to a given radix, optimized for uint `pow` and `radix`.
*
Expand Down
12 changes: 0 additions & 12 deletions src/libcore/num/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ impl num::One for T {
static pure fn one() -> T { 1 }
}
impl num::Round for T {
#[inline(always)]
pure fn round(&self, _: num::RoundMode) -> T { *self }
#[inline(always)]
pure fn floor(&self) -> T { *self }
#[inline(always)]
pure fn ceil(&self) -> T { *self }
#[inline(always)]
pure fn fract(&self) -> T { 0 }
}
#[cfg(notest)]
impl ops::Add<T,T> for T {
pure fn add(&self, other: &T) -> T { *self + *other }
Expand Down

0 comments on commit 3edc7c0

Please sign in to comment.