Trait malachite_base::num::conversion::traits::RoundingFrom
source · pub trait RoundingFrom<T>: Sized {
fn rounding_from(value: T, rm: RoundingMode) -> Self;
}
Expand description
Converts a value from one type to another, where the conversion is made according to a
specified RoundingMode
.
Required Methods§
fn rounding_from(value: T, rm: RoundingMode) -> Self
Implementations on Foreign Types§
source§impl RoundingFrom<u8> for f32
impl RoundingFrom<u8> for f32
source§fn rounding_from(value: u8, rm: RoundingMode) -> f32
fn rounding_from(value: u8, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for u8
impl RoundingFrom<f32> for u8
source§fn rounding_from(value: f32, rm: RoundingMode) -> u8
fn rounding_from(value: f32, rm: RoundingMode) -> u8
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u8> for f64
impl RoundingFrom<u8> for f64
source§fn rounding_from(value: u8, rm: RoundingMode) -> f64
fn rounding_from(value: u8, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for u8
impl RoundingFrom<f64> for u8
source§fn rounding_from(value: f64, rm: RoundingMode) -> u8
fn rounding_from(value: f64, rm: RoundingMode) -> u8
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u16> for f32
impl RoundingFrom<u16> for f32
source§fn rounding_from(value: u16, rm: RoundingMode) -> f32
fn rounding_from(value: u16, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for u16
impl RoundingFrom<f32> for u16
source§fn rounding_from(value: f32, rm: RoundingMode) -> u16
fn rounding_from(value: f32, rm: RoundingMode) -> u16
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u16> for f64
impl RoundingFrom<u16> for f64
source§fn rounding_from(value: u16, rm: RoundingMode) -> f64
fn rounding_from(value: u16, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for u16
impl RoundingFrom<f64> for u16
source§fn rounding_from(value: f64, rm: RoundingMode) -> u16
fn rounding_from(value: f64, rm: RoundingMode) -> u16
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u32> for f32
impl RoundingFrom<u32> for f32
source§fn rounding_from(value: u32, rm: RoundingMode) -> f32
fn rounding_from(value: u32, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for u32
impl RoundingFrom<f32> for u32
source§fn rounding_from(value: f32, rm: RoundingMode) -> u32
fn rounding_from(value: f32, rm: RoundingMode) -> u32
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u32> for f64
impl RoundingFrom<u32> for f64
source§fn rounding_from(value: u32, rm: RoundingMode) -> f64
fn rounding_from(value: u32, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for u32
impl RoundingFrom<f64> for u32
source§fn rounding_from(value: f64, rm: RoundingMode) -> u32
fn rounding_from(value: f64, rm: RoundingMode) -> u32
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u64> for f32
impl RoundingFrom<u64> for f32
source§fn rounding_from(value: u64, rm: RoundingMode) -> f32
fn rounding_from(value: u64, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for u64
impl RoundingFrom<f32> for u64
source§fn rounding_from(value: f32, rm: RoundingMode) -> u64
fn rounding_from(value: f32, rm: RoundingMode) -> u64
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u64> for f64
impl RoundingFrom<u64> for f64
source§fn rounding_from(value: u64, rm: RoundingMode) -> f64
fn rounding_from(value: u64, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for u64
impl RoundingFrom<f64> for u64
source§fn rounding_from(value: f64, rm: RoundingMode) -> u64
fn rounding_from(value: f64, rm: RoundingMode) -> u64
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u128> for f32
impl RoundingFrom<u128> for f32
source§fn rounding_from(value: u128, rm: RoundingMode) -> f32
fn rounding_from(value: u128, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for u128
impl RoundingFrom<f32> for u128
source§fn rounding_from(value: f32, rm: RoundingMode) -> u128
fn rounding_from(value: f32, rm: RoundingMode) -> u128
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<u128> for f64
impl RoundingFrom<u128> for f64
source§fn rounding_from(value: u128, rm: RoundingMode) -> f64
fn rounding_from(value: u128, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for u128
impl RoundingFrom<f64> for u128
source§fn rounding_from(value: f64, rm: RoundingMode) -> u128
fn rounding_from(value: f64, rm: RoundingMode) -> u128
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<usize> for f32
impl RoundingFrom<usize> for f32
source§fn rounding_from(value: usize, rm: RoundingMode) -> f32
fn rounding_from(value: usize, rm: RoundingMode) -> f32
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for usize
impl RoundingFrom<f32> for usize
source§fn rounding_from(value: f32, rm: RoundingMode) -> usize
fn rounding_from(value: f32, rm: RoundingMode) -> usize
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<usize> for f64
impl RoundingFrom<usize> for f64
source§fn rounding_from(value: usize, rm: RoundingMode) -> f64
fn rounding_from(value: usize, rm: RoundingMode) -> f64
Converts a value of an unsigned type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the value is larger than the maximum finite float (which can only happen when converting au128
to anf32
), the maximum finite float is returned.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for usize
impl RoundingFrom<f64> for usize
source§fn rounding_from(value: f64, rm: RoundingMode) -> usize
fn rounding_from(value: f64, rm: RoundingMode) -> usize
Converts a value of a floating point type to a value of an unsigned type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is negative, zero is returned. If the float is greater than the maximum representable unsigned value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable unsigned value, the maximum unsigned value is returned. If the float is negative, zero is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the unsigned type andrm
isCeiling
orUp
. - If
value
is negative andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i8> for f32
impl RoundingFrom<i8> for f32
source§fn rounding_from(value: i8, rm: RoundingMode) -> f32
fn rounding_from(value: i8, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for i8
impl RoundingFrom<f32> for i8
source§fn rounding_from(value: f32, rm: RoundingMode) -> i8
fn rounding_from(value: f32, rm: RoundingMode) -> i8
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i8> for f64
impl RoundingFrom<i8> for f64
source§fn rounding_from(value: i8, rm: RoundingMode) -> f64
fn rounding_from(value: i8, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for i8
impl RoundingFrom<f64> for i8
source§fn rounding_from(value: f64, rm: RoundingMode) -> i8
fn rounding_from(value: f64, rm: RoundingMode) -> i8
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i16> for f32
impl RoundingFrom<i16> for f32
source§fn rounding_from(value: i16, rm: RoundingMode) -> f32
fn rounding_from(value: i16, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for i16
impl RoundingFrom<f32> for i16
source§fn rounding_from(value: f32, rm: RoundingMode) -> i16
fn rounding_from(value: f32, rm: RoundingMode) -> i16
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i16> for f64
impl RoundingFrom<i16> for f64
source§fn rounding_from(value: i16, rm: RoundingMode) -> f64
fn rounding_from(value: i16, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for i16
impl RoundingFrom<f64> for i16
source§fn rounding_from(value: f64, rm: RoundingMode) -> i16
fn rounding_from(value: f64, rm: RoundingMode) -> i16
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i32> for f32
impl RoundingFrom<i32> for f32
source§fn rounding_from(value: i32, rm: RoundingMode) -> f32
fn rounding_from(value: i32, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for i32
impl RoundingFrom<f32> for i32
source§fn rounding_from(value: f32, rm: RoundingMode) -> i32
fn rounding_from(value: f32, rm: RoundingMode) -> i32
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i32> for f64
impl RoundingFrom<i32> for f64
source§fn rounding_from(value: i32, rm: RoundingMode) -> f64
fn rounding_from(value: i32, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for i32
impl RoundingFrom<f64> for i32
source§fn rounding_from(value: f64, rm: RoundingMode) -> i32
fn rounding_from(value: f64, rm: RoundingMode) -> i32
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i64> for f32
impl RoundingFrom<i64> for f32
source§fn rounding_from(value: i64, rm: RoundingMode) -> f32
fn rounding_from(value: i64, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for i64
impl RoundingFrom<f32> for i64
source§fn rounding_from(value: f32, rm: RoundingMode) -> i64
fn rounding_from(value: f32, rm: RoundingMode) -> i64
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i64> for f64
impl RoundingFrom<i64> for f64
source§fn rounding_from(value: i64, rm: RoundingMode) -> f64
fn rounding_from(value: i64, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for i64
impl RoundingFrom<f64> for i64
source§fn rounding_from(value: f64, rm: RoundingMode) -> i64
fn rounding_from(value: f64, rm: RoundingMode) -> i64
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i128> for f32
impl RoundingFrom<i128> for f32
source§fn rounding_from(value: i128, rm: RoundingMode) -> f32
fn rounding_from(value: i128, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for i128
impl RoundingFrom<f32> for i128
source§fn rounding_from(value: f32, rm: RoundingMode) -> i128
fn rounding_from(value: f32, rm: RoundingMode) -> i128
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<i128> for f64
impl RoundingFrom<i128> for f64
source§fn rounding_from(value: i128, rm: RoundingMode) -> f64
fn rounding_from(value: i128, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for i128
impl RoundingFrom<f64> for i128
source§fn rounding_from(value: f64, rm: RoundingMode) -> i128
fn rounding_from(value: f64, rm: RoundingMode) -> i128
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<isize> for f32
impl RoundingFrom<isize> for f32
source§fn rounding_from(value: isize, rm: RoundingMode) -> f32
fn rounding_from(value: isize, rm: RoundingMode) -> f32
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f32> for isize
impl RoundingFrom<f32> for isize
source§fn rounding_from(value: f32, rm: RoundingMode) -> isize
fn rounding_from(value: f32, rm: RoundingMode) -> isize
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.
source§impl RoundingFrom<isize> for f64
impl RoundingFrom<isize> for f64
source§fn rounding_from(value: isize, rm: RoundingMode) -> f64
fn rounding_from(value: isize, rm: RoundingMode) -> f64
Converts a value of a signed type to a value of a floating point type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest float less than or equal to the value is returned. - If the rounding mode is
Ceiling
, the smallest float greater than or equal to the value is returned. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the value is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest float is returned. If the value is exactly between two floats, the float with the zero least-significant bit in its representation is selected.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is Exact
but value
is not exactly equal to any value of
the primitive float type.
Examples
See here.
source§impl RoundingFrom<f64> for isize
impl RoundingFrom<f64> for isize
source§fn rounding_from(value: f64, rm: RoundingMode) -> isize
fn rounding_from(value: f64, rm: RoundingMode) -> isize
Converts a value of a floating point type to a value of a signed type
according to a specified
RoundingMode
.
- If the rounding mode is
Floor
, the largest number less than or equal to the value is returned. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the function panics. - If the rounding mode is
Ceiling
, the smallest number greater than or equal to the value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned. If the float is greater than the maximum representable signed value, the function panics. - If the rounding mode is
Down
, then the rounding proceeds as withFloor
if the float is non-negative and as withCeiling
if the value is negative. - If the rounding mode is
Up
, then the rounding proceeds as withCeiling
if the value is non-negative and as withFloor
if the value is negative. - If the rounding mode is
Nearest
, then the nearest value is returned. If the value is exactly between two numbers, the even one is selected. If the float is greater than the maximum representable signed value, the maximum signed value is returned. If the float is smaller than the minimum representable signed value, the minimum signed value is returned.
Worst-case complexity
Constant time and additional memory.
Panics
- If
value
isNaN
. - If
rm
isExact
butvalue
is not exactly equal to any value of the unsigned type. - If
value
is greater than the maximum value of the signed type andrm
isCeiling
orUp
. - If
value
is smaller than the minimum value of the signed type andrm
isFloor
orUp
.
Examples
See here.