Skip to content

Commit 7b85215

Browse files
committed
Auto merge of rust-lang#95317 - Jules-Bertholet:round_ties_to_even, r=pnkfelix,m-ou-se,scottmcm
Add `round_ties_even` to `f32` and `f64` Tracking issue: rust-lang#96710 Redux of rust-lang#82273. See also rust-lang#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`?
2 parents ea83d6f + ac4e9ca commit 7b85215

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/intrinsic/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ fn get_simple_intrinsic<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, name: Symbol) ->
6868
sym::nearbyintf64 => "nearbyint",
6969
sym::roundf32 => "roundf",
7070
sym::roundf64 => "round",
71+
sym::roundevenf32 => "roundevenf",
72+
sym::roundevenf64 => "roundeven",
7173
sym::abort => "abort",
7274
_ => return None,
7375
};

0 commit comments

Comments
 (0)