diff options
| author | bors <bors@rust-lang.org> | 2023-03-07 09:43:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-07 09:43:12 +0000 |
| commit | 792933c8d7a454730dc379b12e5028a45e6e4e18 (patch) | |
| tree | 9d4198a8851c6f10a753df52144be88f63807f38 | |
| parent | 1b57cb6762a36c2f7823e87829c18b2ccd00f6de (diff) | |
| parent | 20d6292596c86b0610074def2f426a25443ecb6d (diff) | |
| download | rust-792933c8d7a454730dc379b12e5028a45e6e4e18.tar.gz rust-792933c8d7a454730dc379b12e5028a45e6e4e18.zip | |
Auto merge of #95317 - Jules-Bertholet:round_ties_to_even, r=pnkfelix,m-ou-se,scottmcm
Add `round_ties_even` to `f32` and `f64` Tracking issue: #96710 Redux of #82273. See also #55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
| -rw-r--r-- | src/intrinsics/mod.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index e74aabf2fcb..24f8d5e464e 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -281,8 +281,12 @@ fn codegen_float_intrinsic_call<'tcx>( sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64), sym::truncf32 => ("truncf", 1, fx.tcx.types.f32), sym::truncf64 => ("trunc", 1, fx.tcx.types.f64), + sym::rintf32 => ("rintf", 1, fx.tcx.types.f32), + sym::rintf64 => ("rint", 1, fx.tcx.types.f64), sym::roundf32 => ("roundf", 1, fx.tcx.types.f32), sym::roundf64 => ("round", 1, fx.tcx.types.f64), + sym::roundevenf32 => ("roundevenf", 1, fx.tcx.types.f32), + sym::roundevenf64 => ("roundeven", 1, fx.tcx.types.f64), sym::sinf32 => ("sinf", 1, fx.tcx.types.f32), sym::sinf64 => ("sin", 1, fx.tcx.types.f64), sym::cosf32 => ("cosf", 1, fx.tcx.types.f32), |
