Skip to main content

Nearest

Struct Nearest 

Source
pub struct Nearest;
Available on crate features libm or std only.
Expand description

Round to the nearest representable value

The precise behaviour of half-way cases is implementation-defined. Provided implementations follow common practices: float-to-int conversions use the round() inherent function which rounds away from zero while int-to-float conversions follow the behaviour of as numeric casts which rounds ties to even.

Example: 2.5_f32 converts to 3_i32, -2.5_f32 converts to -3_i32. Another example: converting i32::MAX to f32 rounds up to 231.

The § Limits of approximation as specified by Approx apply.

Trait Implementations§

Source§

impl Clone for Nearest

Source§

fn clone(&self) -> Nearest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, T: ConvExact<S>> ConvTo<S, Nearest> for T

Source§

type Error = <T as ConvExact<S>>::Error

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, s: S) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, s: S) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for i8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for i16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for i32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for i64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for i128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for isize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for u8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for u16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for u32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for u64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for usize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Nearest> for u128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f32) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f32) -> u128

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for i8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for i16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for i32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for i64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for i128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for isize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for u8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for u16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for u32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for u64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for u128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Nearest> for usize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Nearest, x: f64) -> Result<Self, RangeError>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Nearest, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<i32, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: i32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: i32) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i64, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: i64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: i64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i64, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: i64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: i64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i128, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: i128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: i128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i128, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: i128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: i128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<isize, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: isize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: isize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<isize, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: isize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: isize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u32, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: u32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: u32) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u64, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: u64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: u64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u64, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: u64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: u64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u128, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: u128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: u128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u128, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: u128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: u128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<usize, Nearest> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: usize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: usize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<usize, Nearest> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Nearest, x: usize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Nearest, x: usize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl Copy for Nearest

Source§

impl Debug for Nearest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Nearest

Source§

fn default() -> Nearest

Returns the “default value” for a type. Read more
Source§

impl Rounding for Nearest

Source§

type MaximumError = RangeError

Maximum error type

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Cast<T> for S
where T: Conv<S>,

Source§

type Error = <T as Conv<S>>::Error

Conversion error type Read more
Source§

fn cast(self) -> T

Cast from Self to T Read more
Source§

fn try_cast(self) -> Result<T, <S as Cast<T>>::Error>

Try converting from Self to T
Source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

Source§

type Error = <T as ConvApprox<S>>::Error

Conversion error type Read more
Source§

fn try_cast_approx(self) -> Result<T, <S as CastApprox<T>>::Error>

Try approximate conversion from Self to T
Source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
Source§

impl<R, S, T> CastTo<T, R> for S
where R: Rounding, T: ConvTo<S, R>,

Source§

type Error = <T as ConvTo<S, R>>::Error

Conversion error type Read more
Source§

fn try_cast_to(self, mode: R) -> Result<T, <S as CastTo<T, R>>::Error>

Try converting from Self to T, rounding according to mode
Source§

fn cast_to(self, mode: R) -> T

Convert from Self to T, rounding according to mode Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.