pub enum RoundingMode {
HalfToEven,
HalfAwayFromZero,
HalfTowardZero,
Trunc,
Floor,
Ceiling,
}Expand description
Selector for the rounding rule applied when a scale-narrowing operation discards fractional digits.
See the module-level documentation for when each rule applies.
§Precision
N/A: this is a tag; no arithmetic is performed by constructing or comparing variants.
Variants§
HalfToEven
Round to nearest; on ties, round to the even neighbour.
IEEE-754 roundTiesToEven; also called banker’s rounding.
Unbiased — repeated rounding does not drift sums. Crate default.
Examples (truncate to integer): 0.5 -> 0, 1.5 -> 2,
2.5 -> 2, -0.5 -> 0, -1.5 -> -2.
HalfAwayFromZero
Round to nearest; on ties, round away from zero. Commercial rounding. Mildly biased in magnitude.
Examples: 0.5 -> 1, 1.5 -> 2, -0.5 -> -1, -1.5 -> -2.
HalfTowardZero
Round to nearest; on ties, round toward zero. Mildly biased toward zero. Rare in practice; included for completeness.
Examples: 0.5 -> 0, 1.5 -> 1, -0.5 -> 0, -1.5 -> -1.
Trunc
Truncate toward zero. Discards the fractional part. Cheapest
in integer arithmetic; matches Rust’s as cast for integer
narrowing.
Examples: 0.7 -> 0, -0.7 -> 0, 1.9 -> 1, -1.9 -> -1.
Floor
Round toward negative infinity (floor).
Examples: 0.7 -> 0, -0.7 -> -1, 1.9 -> 1, -1.9 -> -2.
Ceiling
Round toward positive infinity (ceiling).
Examples: 0.7 -> 1, -0.7 -> 0, 1.9 -> 2, -1.9 -> -1.
Trait Implementations§
Source§impl Clone for RoundingMode
impl Clone for RoundingMode
Source§fn clone(&self) -> RoundingMode
fn clone(&self) -> RoundingMode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RoundingMode
Source§impl Debug for RoundingMode
impl Debug for RoundingMode
impl Eq for RoundingMode
Source§impl Hash for RoundingMode
impl Hash for RoundingMode
Source§impl PartialEq for RoundingMode
impl PartialEq for RoundingMode
Source§fn eq(&self, other: &RoundingMode) -> bool
fn eq(&self, other: &RoundingMode) -> bool
self and other values to be equal, and is used by ==.