File tree 3 files changed +57
-0
lines changed
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -1388,6 +1388,21 @@ extern "rust-intrinsic" {
1388
1388
/// [`f64::round`](../../std/primitive.f64.html#method.round)
1389
1389
pub fn roundf64 ( x : f64 ) -> f64 ;
1390
1390
1391
+ /// Returns the nearest integer to an `f32`. Rounds half-way to the nearest even
1392
+ /// integer.
1393
+ ///
1394
+ /// The version of this intrinsic in the standard libary is
1395
+ /// [`f32::round`](../../std/primitive.f32.html#method.round_to_even)
1396
+ #[ cfg( not( bootstrap) ) ]
1397
+ pub fn roundevenf32 ( x : f32 ) -> f32 ;
1398
+ /// Returns the nearest integer to an `f64`. Rounds half-way to the nearest even
1399
+ /// integer.
1400
+ ///
1401
+ /// The version of this intrinsic in the standard libary is
1402
+ /// [`f64::round`](../../std/primitive.f64.html#method.round_to_even)
1403
+ #[ cfg( not( bootstrap) ) ]
1404
+ pub fn roundevenf64 ( x : f64 ) -> f64 ;
1405
+
1391
1406
/// Float addition that allows optimizations based on algebraic rules.
1392
1407
/// May assume inputs are finite.
1393
1408
///
Original file line number Diff line number Diff line change @@ -87,6 +87,27 @@ impl f32 {
87
87
unsafe { intrinsics:: roundf32 ( self ) }
88
88
}
89
89
90
+ /// Returns the nearest integer to a number. Round half-way cases to the
91
+ /// nearest even integer.
92
+ ///
93
+ /// # Examples
94
+ ///
95
+ /// ```
96
+ /// # #![cfg_attr(not(bootstrap), feature(round_to_even))]
97
+ /// let f = 3.3_f32;
98
+ /// let g = -3.3_f32;
99
+ ///
100
+ /// assert_eq!(f.round_to_even(), 3.0);
101
+ /// assert_eq!(g.round_to_even(), -3.0);
102
+ /// ```
103
+ #[ cfg( not( bootstrap) ) ]
104
+ #[ must_use = "method returns a new number and does not mutate the original value" ]
105
+ #[ unstable( feature = "round_to_even" , issue = "none" ) ]
106
+ #[ inline]
107
+ pub fn round_to_even ( self ) -> f32 {
108
+ unsafe { intrinsics:: roundevenf32 ( self ) }
109
+ }
110
+
90
111
/// Returns the integer part of a number.
91
112
///
92
113
/// # Examples
Original file line number Diff line number Diff line change @@ -87,6 +87,27 @@ impl f64 {
87
87
unsafe { intrinsics:: roundf64 ( self ) }
88
88
}
89
89
90
+ /// Returns the nearest integer to a number. Round half-way cases to the
91
+ /// nearest even integer.
92
+ ///
93
+ /// # Examples
94
+ ///
95
+ /// ```
96
+ /// # #![cfg_attr(not(bootstrap), feature(round_to_even))]
97
+ /// let f = 3.3_f64;
98
+ /// let g = -3.3_f64;
99
+ ///
100
+ /// assert_eq!(f.round_to_even(), 3.0);
101
+ /// assert_eq!(g.round_to_even(), -3.0);
102
+ /// ```
103
+ #[ cfg( not( bootstrap) ) ]
104
+ #[ must_use = "method returns a new number and does not mutate the original value" ]
105
+ #[ unstable( feature = "round_to_even" , issue = "none" ) ]
106
+ #[ inline]
107
+ pub fn round_to_even ( self ) -> f64 {
108
+ unsafe { intrinsics:: roundevenf64 ( self ) }
109
+ }
110
+
90
111
/// Returns the integer part of a number.
91
112
///
92
113
/// # Examples
You can’t perform that action at this time.
0 commit comments