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]
This commit is contained in:
parent
b75683cadf
commit
fe47202034
6 changed files with 106 additions and 118 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue