Skip to content

Commit b949594

Browse files
authored
Rollup merge of #141521 - ruancomelli:const-float-rounding, r=RalfJung
Add `const` support for float rounding methods # Add `const` support for float rounding methods This PR makes the following float rounding methods `const`: - `f64::{floor, ceil, trunc, round, round_ties_even}` - and the corresponding methods for `f16`, `f32` and `f128` Tracking issue: rust-lang/rust#141555 ## Procedure I followed rust-lang/rust@c09ed3e as closely as I could in making float methods `const`, and also received great guidance from https://internals.rust-lang.org/t/const-rounding-methods-in-float-types/22957/3?u=ruancomelli. ## Note This is my first code contribution to the Rust project, so please let me know if I missed anything - I'd be more than happy to revise and learn more. Thank you for taking the time to review it!
2 parents 3910a6f + f5b7e7e commit b949594

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

src/intrinsics/mod.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -159,67 +159,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
159159
this.write_scalar(Scalar::from_bool(branch), dest)?;
160160
}
161161

162-
"floorf16" | "ceilf16" | "truncf16" | "roundf16" | "round_ties_even_f16" => {
163-
let [f] = check_intrinsic_arg_count(args)?;
164-
let f = this.read_scalar(f)?.to_f16()?;
165-
let mode = match intrinsic_name {
166-
"floorf16" => Round::TowardNegative,
167-
"ceilf16" => Round::TowardPositive,
168-
"truncf16" => Round::TowardZero,
169-
"roundf16" => Round::NearestTiesToAway,
170-
"round_ties_even_f16" => Round::NearestTiesToEven,
171-
_ => bug!(),
172-
};
173-
let res = f.round_to_integral(mode).value;
174-
let res = this.adjust_nan(res, &[f]);
175-
this.write_scalar(res, dest)?;
176-
}
177-
"floorf32" | "ceilf32" | "truncf32" | "roundf32" | "round_ties_even_f32" => {
178-
let [f] = check_intrinsic_arg_count(args)?;
179-
let f = this.read_scalar(f)?.to_f32()?;
180-
let mode = match intrinsic_name {
181-
"floorf32" => Round::TowardNegative,
182-
"ceilf32" => Round::TowardPositive,
183-
"truncf32" => Round::TowardZero,
184-
"roundf32" => Round::NearestTiesToAway,
185-
"round_ties_even_f32" => Round::NearestTiesToEven,
186-
_ => bug!(),
187-
};
188-
let res = f.round_to_integral(mode).value;
189-
let res = this.adjust_nan(res, &[f]);
190-
this.write_scalar(res, dest)?;
191-
}
192-
"floorf64" | "ceilf64" | "truncf64" | "roundf64" | "round_ties_even_f64" => {
193-
let [f] = check_intrinsic_arg_count(args)?;
194-
let f = this.read_scalar(f)?.to_f64()?;
195-
let mode = match intrinsic_name {
196-
"floorf64" => Round::TowardNegative,
197-
"ceilf64" => Round::TowardPositive,
198-
"truncf64" => Round::TowardZero,
199-
"roundf64" => Round::NearestTiesToAway,
200-
"round_ties_even_f64" => Round::NearestTiesToEven,
201-
_ => bug!(),
202-
};
203-
let res = f.round_to_integral(mode).value;
204-
let res = this.adjust_nan(res, &[f]);
205-
this.write_scalar(res, dest)?;
206-
}
207-
"floorf128" | "ceilf128" | "truncf128" | "roundf128" | "round_ties_even_f128" => {
208-
let [f] = check_intrinsic_arg_count(args)?;
209-
let f = this.read_scalar(f)?.to_f128()?;
210-
let mode = match intrinsic_name {
211-
"floorf128" => Round::TowardNegative,
212-
"ceilf128" => Round::TowardPositive,
213-
"truncf128" => Round::TowardZero,
214-
"roundf128" => Round::NearestTiesToAway,
215-
"round_ties_even_f128" => Round::NearestTiesToEven,
216-
_ => bug!(),
217-
};
218-
let res = f.round_to_integral(mode).value;
219-
let res = this.adjust_nan(res, &[f]);
220-
this.write_scalar(res, dest)?;
221-
}
222-
223162
"sqrtf32" => {
224163
let [f] = check_intrinsic_arg_count(args)?;
225164
let f = this.read_scalar(f)?.to_f32()?;

0 commit comments

Comments
 (0)