Feature gate: #![feature(float_conversions)]
This is a tracking issue for the float conversion methods from ACP rust-lang/libs-team#810: cast (float to float), to_int_saturating, to_int_checked, and to_int_strict on f16, f32, f64, and f128.
Public API
// core::convert
pub trait FloatToFloat<Flt> { /* sealed */ }
impl f32 { // and f16, f64, f128
pub fn cast<Flt>(self) -> Flt where Self: FloatToFloat<Flt>;
pub fn to_int_saturating<Int>(self) -> Int where Self: FloatToInt<Int>;
pub fn to_int_checked<Int>(self) -> Option<Int> where Self: FloatToInt<Int>;
pub fn to_int_strict<Int>(self) -> Int where Self: FloatToInt<Int>;
}
cast is self as Flt. to_int_saturating is self as Int (saturating, NaN to 0, per the libs-api decision). to_int_checked truncates toward zero and returns None on NaN, infinity, or out of range. to_int_strict is to_int_checked().unwrap().
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
Unresolved Questions
Feature gate:
#![feature(float_conversions)]This is a tracking issue for the float conversion methods from ACP rust-lang/libs-team#810:
cast(float to float),to_int_saturating,to_int_checked, andto_int_strictonf16,f32,f64, andf128.Public API
castisself as Flt.to_int_saturatingisself as Int(saturating,NaNto 0, per the libs-api decision).to_int_checkedtruncates toward zero and returnsNoneonNaN, infinity, or out of range.to_int_strictisto_int_checked().unwrap().Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)Unresolved Questions
castfrom integers to floats. It shares thecastmethod name on integer types with the integer-to-integercastfrom ACP: convenient numeric conversions dependent on overflow-checks libs-team#811, which is being unified with the rest of the integer cast methods in the meta-ACP Meta-ACP: Integer cast methods libs-team#833, so it is left out here until that naming settles.to_int_wrapping(float to int) is an open question in the ACP and is not included.