diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-04-18 12:48:48 +1000 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-04-19 10:41:45 +1000 |
| commit | fe472020347d8eeb727f3a31e9cdc7268bb579f6 (patch) | |
| tree | 63cabb323fb76aea7150d09744e0d8c8275b40d6 /src/libstd/num/mod.rs | |
| parent | b75683cadf6c4c55360202cd6a0106be80532451 (diff) | |
Merge the Round trait into the Float trait
Move the rounding functions into the `std::num::Float` trait and then remove `std::num::Round`. This continues the flattening of the numeric traits tracked in #10387. The aim is to make `std::num` very simple and tied to the built in types, leaving the definition of more complex numeric towers to third-party libraries. [breaking-change]
Diffstat (limited to 'src/libstd/num/mod.rs')
| -rw-r--r-- | src/libstd/num/mod.rs | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 12befed743a..b3e15a97086 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -162,25 +162,6 @@ pub fn abs_sub<T: Signed>(x: T, y: T) -> T { /// A trait for values which cannot be negative pub trait Unsigned: Num {} -/// A collection of rounding operations. -pub trait Round { - /// Return the largest integer less than or equal to a number. - fn floor(&self) -> Self; - - /// Return the smallest integer greater than or equal to a number. - fn ceil(&self) -> Self; - - /// Return the nearest integer to a number. Round half-way cases away from - /// `0.0`. - fn round(&self) -> Self; - - /// Return the integer part of a number. - fn trunc(&self) -> Self; - - /// Return the fractional part of a number. - fn fract(&self) -> Self; -} - /// Raises a value to the power of exp, using exponentiation by squaring. /// /// # Example @@ -347,7 +328,7 @@ pub enum FPCategory { // // FIXME(#8888): Several of these functions have a parameter named // `unused_self`. Removing it requires #8888 to be fixed. -pub trait Float: Signed + Round + Primitive { +pub trait Float: Signed + Primitive { /// Returns the maximum of the two numbers. fn max(self, other: Self) -> Self; /// Returns the minimum of the two numbers. @@ -431,6 +412,22 @@ pub trait Float: Signed + Round + Primitive { /// Returns the mantissa, exponent and sign as integers, respectively. fn integer_decode(&self) -> (u64, i16, i8); + /// Return the largest integer less than or equal to a number. + fn floor(&self) -> Self; + + /// Return the smallest integer greater than or equal to a number. + fn ceil(&self) -> Self; + + /// Return the nearest integer to a number. Round half-way cases away from + /// `0.0`. + fn round(&self) -> Self; + + /// Return the integer part of a number. + fn trunc(&self) -> Self; + + /// Return the fractional part of a number. + fn fract(&self) -> Self; + /// Archimedes' constant. fn pi() -> Self; |
