Enum scientific::Rounding
source · #[non_exhaustive]pub enum Rounding {
RoundDown,
RoundUp,
RoundTowardsZero,
RoundAwayFromZero,
RoundHalfDown,
RoundHalfUp,
RoundHalfTowardsZero,
RoundHalfAwayFromZero,
RoundHalfToEven,
RoundHalfToOdd,
}
Expand description
Enum to implement different rounding methods.
Method | Result is -2 | Result is -1 | Result is 0 | Result is 1 | Result is 2 | Implementor |
---|---|---|---|---|---|---|
Directed, Down | [-2.0, -1.0) | [-1.0, 0.0) | [0.0, 1.0) | [1.0, 2.0) | [2.0, 3.0) | RoundDown |
Directed, Up | (-3.0, -2.0] | (-2.0, -1.0] | (-1.0, 0.0] | (0.0, 1.0] | (1.0, 2.0] | RoundUp |
Directed, Towards 0 | (-3.0, -2.0] | (-2.0, -1.0] | (-1.0, 1.0) | [1.0, 2.0) | [2.0, 3.0) | RoundTowardsZero |
Directed, Away From 0 | [-2.0, -1.0) | [-1.0, 0.0) | 0.0 | (0.0, 1.0] | (1.0, 2.0] | RoundAwayFromZero |
Nearest, Half Down | (-2.5, -1.5] | (-1.5, -0.5] | (-0.5, 0.5] | (0.5, 1.5] | (1.5, 2.5] | RoundHalfDown |
Nearest, Half Up | [-2.5, -1.5) | [-1.5, -0.5) | [-0.5, 0.5) | [0.5, 1.5) | [1.5, 2.5) | RoundHalfUp |
Nearest, Half Towards 0 | [-2.5, -1.5) | [-1.5, -0.5) | [-0.5, 0.5] | (0.5, 1.5] | (1.5, 2.5] | RoundHalfTowardsZero |
Nearest, Half Away From 0 | (-2.5, -1.5] | (-1.5, -0.5] | (-0.5, 0.5) | [0.5, 1.5) | [1.5, 2.5) | RoundHalfAwayFromZero |
Nearest, Half To Even | [-2.5, -1.5] | (-1.5, -0.5) | [-0.5, 0.5] | (0.5, 1.5) | [1.5, 2.5] | RoundHalfToEven |
Nearest, half To Odd | (-2.5, -1.5) | [-1.5, -0.5] | (-0.5, 0.5) | [0.5, 1.5] | (1.5, 2.5) | RoundHalfToOdd |
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
RoundDown
Also known as floor.
RoundUp
Also known as ceiling.
RoundTowardsZero
Also known as truncate.
RoundAwayFromZero
Used by f64::round
.
RoundHalfDown
RoundHalfUp
RoundHalfTowardsZero
RoundHalfAwayFromZero
[Default] Probably what you learned in school.
RoundHalfToEven
Often used in binary IEEE Floating-Point arithmetic.
Not for the rounding operation but by other operations, which create more digits as can be stored.
RoundHalfToOdd
Trait Implementations§
impl Copy for Rounding
Auto Trait Implementations§
impl Freeze for Rounding
impl RefUnwindSafe for Rounding
impl Send for Rounding
impl Sync for Rounding
impl Unpin for Rounding
impl UnwindSafe for Rounding
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more