pub enum Rounding {
    Up,
    Down,
    NearestPrefUp,
    NearestPrefDown,
}
Expand description

The rounding method to use for unsigned quantities.

Variants§

§

Up

§

Down

§

NearestPrefUp

§

NearestPrefDown

Implementations§

Returns the value for Rounding which would give the same result ignorant of the sign.

Examples found in repository?
src/fixed_point.rs (line 158)
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	fn checked_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
		n: N,
		d: D,
	) -> Option<Self> {
		if d == D::zero() {
			return None
		}

		let n: I129 = n.into();
		let d: I129 = d.into();
		let negative = n.negative != d.negative;

		multiply_by_rational_with_rounding(
			n.value,
			Self::DIV.unique_saturated_into(),
			d.value,
			Rounding::from_signed(SignedRounding::Minor, negative),
		)
		.and_then(|value| from_i129(I129 { value, negative }))
		.map(Self::from_inner)
	}

	/// Checked multiplication for integer type `N`. Equal to `self * n`.
	///
	/// Returns `None` if the result does not fit in `N`.
	fn checked_mul_int<N: FixedPointOperand>(self, n: N) -> Option<N> {
		let lhs: I129 = self.into_inner().into();
		let rhs: I129 = n.into();
		let negative = lhs.negative != rhs.negative;

		multiply_by_rational_with_rounding(
			lhs.value,
			rhs.value,
			Self::DIV.unique_saturated_into(),
			Rounding::from_signed(SignedRounding::Minor, negative),
		)
		.and_then(|value| from_i129(I129 { value, negative }))
	}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert from a value of T into an equivalent instance of Self. Read more
Consume self to return an equivalent value of T. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Consume self to return an equivalent value of T.