File tree 3 files changed +55
-0
lines changed
3 files changed +55
-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 stabilized version of this intrinsic is
1395
+ /// [`f32::round`](../../std/primitive.f32.html#method.round)
1396
+ #[ cfg( not( bootstrap) ) ]
1397
+ pub fn roundevenf32 ( x : f32 ) -> f32 ;
1398
+ /// Returns the nearest integer to an `f32`. Rounds half-way to the nearest even
1399
+ /// integer.
1400
+ ///
1401
+ /// The stabilized version of this intrinsic is
1402
+ /// [`f64::round`](../../std/primitive.f64.html#method.round)
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,26 @@ 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
+ /// let f = 3.3_f32;
97
+ /// let g = -3.3_f32;
98
+ ///
99
+ /// assert_eq!(f.round(), 3.0);
100
+ /// assert_eq!(g.round(), -3.0);
101
+ /// ```
102
+ #[ cfg( not( bootstrap) ) ]
103
+ #[ must_use = "method returns a new number and does not mutate the original value" ]
104
+ #[ unstable( feature = "round_to_even" , issue = "none" ) ]
105
+ #[ inline]
106
+ pub fn round_to_even ( self ) -> f32 {
107
+ unsafe { intrinsics:: roundevenf32 ( self ) }
108
+ }
109
+
90
110
/// Returns the integer part of a number.
91
111
///
92
112
/// # Examples
Original file line number Diff line number Diff line change @@ -87,6 +87,26 @@ impl f64 {
87
87
unsafe { intrinsics:: roundf64 ( self ) }
88
88
}
89
89
90
+ /// Returns the nearest integer to a number. RRound half-way cases to the
91
+ /// nearest even integer.
92
+ ///
93
+ /// # Examples
94
+ ///
95
+ /// ```
96
+ /// let f = 3.3_f64;
97
+ /// let g = -3.3_f64;
98
+ ///
99
+ /// assert_eq!(f.round(), 3.0);
100
+ /// assert_eq!(g.round(), -3.0);
101
+ /// ```
102
+ #[ cfg( not( bootstrap) ) ]
103
+ #[ must_use = "method returns a new number and does not mutate the original value" ]
104
+ #[ unstable( feature = "round_to_even" , issue = "none" ) ]
105
+ #[ inline]
106
+ pub fn round_to_even ( self ) -> f64 {
107
+ unsafe { intrinsics:: roundevenf64 ( self ) }
108
+ }
109
+
90
110
/// Returns the integer part of a number.
91
111
///
92
112
/// # Examples
You can’t perform that action at this time.
0 commit comments