Skip to content

Make some float methods unstable const fn#130568

Merged
bors merged 2 commits intorust-lang:masterfrom
eduardosm:const-float-methods
Oct 15, 2024
Merged

Make some float methods unstable const fn#130568
bors merged 2 commits intorust-lang:masterfrom
eduardosm:const-float-methods

Conversation

@eduardosm
Copy link
Copy Markdown
Contributor

@eduardosm eduardosm commented Sep 19, 2024

Some float methods are now const fn under the const_float_methods feature gate.

I also made some unstable methods const fn, keeping their constness under their respective feature gate.

In order to support min, max, abs and copysign, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval (cc @RalfJung).

Tracking issue: #130843

impl <float> {
    // #[feature(const_float_methods)]
    pub const fn recip(self) -> Self;
    pub const fn to_degrees(self) -> Self;
    pub const fn to_radians(self) -> Self;
    pub const fn max(self, other: Self) -> Self;
    pub const fn min(self, other: Self) -> Self;
    pub const fn clamp(self, min: Self, max: Self) -> Self;
    pub const fn abs(self) -> Self;
    pub const fn signum(self) -> Self;
    pub const fn copysign(self, sign: Self) -> Self;

    // #[feature(float_minimum_maximum)]
    pub const fn maximum(self, other: Self) -> Self;
    pub const fn minimum(self, other: Self) -> Self;

    // Only f16/f128 (f32/f64 already const)
    pub const fn is_sign_positive(self) -> bool;
    pub const fn is_sign_negative(self) -> bool;
    pub const fn next_up(self) -> Self;
    pub const fn next_down(self) -> Self;
}

r? libs-api

try-job: dist-s390x-linux

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.