Skip to content

Commit 96adbf6

Browse files
committed
Auto merge of #885 - Aaron1011:fix/f-round, r=RalfJung
Add misssing 'roundf32' and 'roundf64' intrinsics
2 parents bc82f83 + 4c11c6b commit 96adbf6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/shims/intrinsics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
225225
}
226226

227227
"sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" |
228-
"log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => {
228+
"log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" | "roundf32" => {
229229
// FIXME: Using host floats.
230230
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
231231
let f = match intrinsic_name.get() {
@@ -241,13 +241,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
241241
"floorf32" => f.floor(),
242242
"ceilf32" => f.ceil(),
243243
"truncf32" => f.trunc(),
244+
"roundf32" => f.round(),
244245
_ => bug!(),
245246
};
246247
this.write_scalar(Scalar::from_u32(f.to_bits()), dest)?;
247248
}
248249

249250
"sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" |
250-
"log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => {
251+
"log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" | "roundf64" => {
251252
// FIXME: Using host floats.
252253
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
253254
let f = match intrinsic_name.get() {
@@ -263,6 +264,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
263264
"floorf64" => f.floor(),
264265
"ceilf64" => f.ceil(),
265266
"truncf64" => f.trunc(),
267+
"roundf64" => f.round(),
266268
_ => bug!(),
267269
};
268270
this.write_scalar(Scalar::from_u64(f.to_bits()), dest)?;

tests/run-pass/intrinsics-math.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub fn main() {
8585
assert_approx_eq!(1.0f32.tan(), 1.557408f32);
8686
assert_approx_eq!(1.0f64.tan(), 1.557408f64);
8787

88+
assert_eq!(3.3_f32.round(), 3.0);
89+
assert_eq!(3.3_f64.round(), 3.0);
90+
8891
extern {
8992
fn ldexp(x: f64, n: i32) -> f64;
9093
}

0 commit comments

Comments
 (0)