Tracking Issue for float conversion methods (float_conversions)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.)
- ACP: rust-lang/libs-team#810
- Implementation: #159954
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- The ACP also proposes
castfrom integers to floats. It shares thecastmethod name on integer types with the integer-to-integercastfrom rust-lang/libs-team#811, which is being unified with the rest of the integer cast methods in the meta-ACP rust-lang/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the public API and unresolved questions listed in this tracking issue, then read implementation PR #159954. The work is done when the final comment period and stabilization PR are complete and the tracking checklist and labels are updated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100