Skip to content

Commit 0b8715b

Browse files
Rollup merge of #130568 - eduardosm:const-float-methods, r=RalfJung,tgross35
Make some float methods unstable `const fn` 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: rust-lang/rust#130843 ```rust 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
2 parents 95e0d5b + e60d62b commit 0b8715b

File tree

2 files changed

+0
-43
lines changed

2 files changed

+0
-43
lines changed

src/intrinsics/mod.rs

-39
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
145145
this.write_scalar(Scalar::from_bool(branch), dest)?;
146146
}
147147

148-
// Floating-point operations
149-
"fabsf32" => {
150-
let [f] = check_arg_count(args)?;
151-
let f = this.read_scalar(f)?.to_f32()?;
152-
// This is a "bitwise" operation, so there's no NaN non-determinism.
153-
this.write_scalar(Scalar::from_f32(f.abs()), dest)?;
154-
}
155-
"fabsf64" => {
156-
let [f] = check_arg_count(args)?;
157-
let f = this.read_scalar(f)?.to_f64()?;
158-
// This is a "bitwise" operation, so there's no NaN non-determinism.
159-
this.write_scalar(Scalar::from_f64(f.abs()), dest)?;
160-
}
161-
162148
"floorf32" | "ceilf32" | "truncf32" | "roundf32" | "rintf32" => {
163149
let [f] = check_arg_count(args)?;
164150
let f = this.read_scalar(f)?.to_f32()?;
@@ -249,31 +235,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
249235
this.write_scalar(res, dest)?;
250236
}
251237

252-
"minnumf32" | "maxnumf32" | "copysignf32" => {
253-
let [a, b] = check_arg_count(args)?;
254-
let a = this.read_scalar(a)?.to_f32()?;
255-
let b = this.read_scalar(b)?.to_f32()?;
256-
let res = match intrinsic_name {
257-
"minnumf32" => this.adjust_nan(a.min(b), &[a, b]),
258-
"maxnumf32" => this.adjust_nan(a.max(b), &[a, b]),
259-
"copysignf32" => a.copy_sign(b), // bitwise, no NaN adjustments
260-
_ => bug!(),
261-
};
262-
this.write_scalar(Scalar::from_f32(res), dest)?;
263-
}
264-
"minnumf64" | "maxnumf64" | "copysignf64" => {
265-
let [a, b] = check_arg_count(args)?;
266-
let a = this.read_scalar(a)?.to_f64()?;
267-
let b = this.read_scalar(b)?.to_f64()?;
268-
let res = match intrinsic_name {
269-
"minnumf64" => this.adjust_nan(a.min(b), &[a, b]),
270-
"maxnumf64" => this.adjust_nan(a.max(b), &[a, b]),
271-
"copysignf64" => a.copy_sign(b), // bitwise, no NaN adjustments
272-
_ => bug!(),
273-
};
274-
this.write_scalar(Scalar::from_f64(res), dest)?;
275-
}
276-
277238
"fmaf32" => {
278239
let [a, b, c] = check_arg_count(args)?;
279240
let a = this.read_scalar(a)?.to_f32()?;

src/operator.rs

-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,4 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
115115
nan
116116
}
117117
}
118-
119-
fn adjust_nan<F1: Float + FloatConvert<F2>, F2: Float>(&self, f: F2, inputs: &[F1]) -> F2 {
120-
if f.is_nan() { self.generate_nan(inputs) } else { f }
121-
}
122118
}

0 commit comments

Comments
 (0)