Trait easy_cast::CastFloat [−][src]
Two sets of methods are provided:
cast_*
methods are for “success expected” conversions. In debug builds and when using thealways_assert
or theassert_float
feature flag, out-of-range conversions will panic. In other cases, conversions may produce incorrect values (according to the behaviour of as, which is saturating cast since Rust 1.45.0 and undefined for older compilers). Non-finite source values (inf
andNaN
) are considered out-of-range.try_cast_*
methods are for fallible conversions and always produce an error if the conversion would be out of range.
Required methods
fn cast_trunc(self) -> T
[src]
Cast to integer, truncating
Rounds towards zero (same as as
).
fn cast_nearest(self) -> T
[src]
Cast to the nearest integer
Half-way cases are rounded away from 0
.
fn cast_floor(self) -> T
[src]
Cast the floor to an integer
Returns the largest integer less than or equal to self
.
fn cast_ceil(self) -> T
[src]
Cast the ceiling to an integer
Returns the smallest integer greater than or equal to self
.
fn try_cast_trunc(self) -> Result<T, Error>
[src]
Try converting to integer with truncation
Rounds towards zero (same as as
).
fn try_cast_nearest(self) -> Result<T, Error>
[src]
Try converting to the nearest integer
Half-way cases are rounded away from 0
.
fn try_cast_floor(self) -> Result<T, Error>
[src]
Try converting the floor to an integer
Returns the largest integer less than or equal to x
.
fn try_cast_ceil(self) -> Result<T, Error>
[src]
Try convert the ceiling to an integer
Returns the smallest integer greater than or equal to x
.