rust-lang / rust-lang/rust

Tracking Issue for float conversion methods (float_conversions)

Open
#159,913 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-unimplemented T-libs
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 cast from integers to floats. It shares the cast method name on integer types with the integer-to-integer cast from 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.