pub struct Approx;Expand description
Approximate conversion
This rounding mode allows an implementation-defined rounding mode. The result must be close to the input value (see below).
Example: 2.1_f32 may convert to 2_i32 or to 3_i32 (either
implementation is valid so long as the behaviour is well-defined).
§Limits of approximation
(This section applies to all Rounding modes provided by easy-cast
except for Exact.)
The output value of a successful conversion must be close to the input
value. More precisely, the distance between the input and output values
should be less than the distance between the two closest representable
values in the target type.
For example, 1.9_f32 may be approximated to 1_i32 or 2_i32 since
mathematically 1.9 lies between 1 and 2. As another example,
1_f64 + (f32::EPSILON as f64) / 2.0 may be approximated to
1_f32 or 1_f32 + f32::EPSILON.
Infinity “values” like f32::INFINITY are a bit special; essentially we
allow any input of the appropriate sign to approximate to “infinity” where
the input may not approximate to another value. For example, the above rules
may be used to calculate the maximum u128 value which is allowed to
approximate to f32::MAX (0xFFFFFF7F_FFFFFFFF_FFFFFFFF_FFFFFFFF);
the value above this should thus approximate to f32::INFINITY.
Trait Implementations§
Source§impl<S, T: ConvExact<S>> ConvTo<S, Approx> for T
impl<S, T: ConvExact<S>> ConvTo<S, Approx> for T
impl Copy for Approx
Source§impl Rounding for Approx
impl Rounding for Approx
Source§type MaximumError = RangeError
type MaximumError = RangeError
Auto Trait Implementations§
impl Freeze for Approx
impl RefUnwindSafe for Approx
impl Send for Approx
impl Sync for Approx
impl Unpin for Approx
impl UnsafeUnpin for Approx
impl UnwindSafe for Approx
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
Source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, <S as CastApprox<T>>::Error>
fn try_cast_approx(self) -> Result<T, <S as CastApprox<T>>::Error>
Self to T