Open
Description
Feature gate: #![feature(const_float_round_methods)]
This is a tracking issue for making const
some methods of floating point types:
f64::{floor, ceil, trunc, fract, round, round_ties_even}
- and the corresponding methods for
f16
,f32
andf128
This extends the work done in #130843
Public API
// in `core`
impl <float> {
// ...
pub const fn floor(self) -> Self;
pub const fn ceil(self) -> Self;
pub const fn trunc(self) -> Self;
pub const fn fract(self) -> Self;
pub const fn round(self) -> Self;
pub const fn round_ties_even(self) -> Self;
// ...
}
Steps / History
- Opened a discussion topic on the internals forum: Const rounding methods in float types
- Since all the required machinery was already implemented in the Miri, the implementation was straightforward.
- Implementation: Add
const
support for float rounding methods #141521 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should the rounding methods on
f16
andf128
be gated behind#[rustc_const_unstable(feature = {"f16", "f128"}, issue = "116909")]
(from Tracking Issue forf16
andf128
float types #116909) or#[rustc_const_unstable(feature = "const_float_round_methods", issue = "<this one>")]
? The answer is both! Check out this comment: Addconst
support for float rounding methods #141521 (comment).