Skip to content

Tracking Issue for float conversion methods (float_conversions) #159913

Description

@valentynkit

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions