Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stablize Euclidean Modulo (feature euclidean_division) #61884

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,12 @@ returning `None` if `rhs == 0` or the division results in overflow.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!((", stringify!($SelfT),
"::min_value() + 1).checked_div_euclid(-1), Some(", stringify!($Max), "));
assert_eq!(", stringify!($SelfT), "::min_value().checked_div_euclid(-1), None);
assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -774,14 +773,13 @@ if `rhs == 0` or the division results in overflow.
Basic usage:

```
#![feature(euclidean_division)]
use std::", stringify!($SelfT), ";

assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));
assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);
assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -1210,11 +1208,10 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);
assert_eq!((-128i8).wrapping_div_euclid(-1), -128);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -1269,11 +1266,10 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);
assert_eq!((-128i8).wrapping_rem_euclid(-1), 0);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -1566,15 +1562,14 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
use std::", stringify!($SelfT), ";

assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));
assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringify!($SelfT),
"::MIN, true));
```"),
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
Expand Down Expand Up @@ -1636,13 +1631,12 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
use std::", stringify!($SelfT), ";

assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));
assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -1873,7 +1867,6 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
let a: ", stringify!($SelfT), " = 7; // or any other integer type
let b = 4;

Expand All @@ -1882,7 +1875,7 @@ assert_eq!(a.div_euclid(-b), -1); // 7 >= -4 * -1
assert_eq!((-a).div_euclid(b), -2); // -7 >= 4 * -2
assert_eq!((-a).div_euclid(-b), 2); // -7 >= -4 * 2
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -1913,7 +1906,6 @@ This function will panic if `rhs` is 0.
Basic usage:

```
#![feature(euclidean_division)]
let a: ", stringify!($SelfT), " = 7; // or any other integer type
let b = 4;

Expand All @@ -1922,7 +1914,7 @@ assert_eq!((-a).rem_euclid(b), 1);
assert_eq!(a.rem_euclid(-b), 3);
assert_eq!((-a).rem_euclid(-b), 1);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -2753,11 +2745,10 @@ if `rhs == 0`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(128", stringify!($SelfT), ".checked_div_euclid(2), Some(64));
assert_eq!(1", stringify!($SelfT), ".checked_div_euclid(0), None);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -2805,11 +2796,10 @@ if `rhs == 0`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));
assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -3127,10 +3117,9 @@ is exactly equal to `self.wrapping_div(rhs)`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -3179,10 +3168,9 @@ is exactly equal to `self.wrapping_rem(rhs)`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down Expand Up @@ -3448,11 +3436,10 @@ This function will panic if `rhs` is 0.
Basic usage

```
#![feature(euclidean_division)]
assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));
```"),
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
Expand Down Expand Up @@ -3508,11 +3495,10 @@ This function will panic if `rhs` is 0.
Basic usage

```
#![feature(euclidean_division)]
assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));
```"),
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
Expand Down Expand Up @@ -3696,10 +3682,9 @@ is exactly equal to `self / rhs`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(7", stringify!($SelfT), ".div_euclid(4), 1); // or any other integer type
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand All @@ -3722,10 +3707,9 @@ is exactly equal to `self % rhs`.
Basic usage:

```
#![feature(euclidean_division)]
assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type
```"),
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(dec2flt)]
#![feature(euclidean_division)]
#![feature(exact_size_is_empty)]
#![feature(fixed_size_array)]
#![feature(flt2dec)]
Expand Down
6 changes: 2 additions & 4 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(euclidean_division)]
/// let a: f32 = 7.0;
/// let b = 4.0;
/// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0
Expand All @@ -265,7 +264,7 @@ impl f32 {
/// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
/// ```
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
pub fn div_euclid(self, rhs: f32) -> f32 {
let q = (self / rhs).trunc();
if self % rhs < 0.0 {
Expand All @@ -288,7 +287,6 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(euclidean_division)]
/// let a: f32 = 7.0;
/// let b = 4.0;
/// assert_eq!(a.rem_euclid(b), 3.0);
Expand All @@ -299,7 +297,7 @@ impl f32 {
/// assert!((-std::f32::EPSILON).rem_euclid(3.0) != 0.0);
/// ```
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
pub fn rem_euclid(self, rhs: f32) -> f32 {
let r = self % rhs;
if r < 0.0 {
Expand Down
6 changes: 2 additions & 4 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(euclidean_division)]
/// let a: f64 = 7.0;
/// let b = 4.0;
/// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0
Expand All @@ -241,7 +240,7 @@ impl f64 {
/// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
/// ```
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
pub fn div_euclid(self, rhs: f64) -> f64 {
let q = (self / rhs).trunc();
if self % rhs < 0.0 {
Expand All @@ -264,7 +263,6 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(euclidean_division)]
/// let a: f64 = 7.0;
/// let b = 4.0;
/// assert_eq!(a.rem_euclid(b), 3.0);
Expand All @@ -275,7 +273,7 @@ impl f64 {
/// assert!((-std::f64::EPSILON).rem_euclid(3.0) != 0.0);
/// ```
#[inline]
#[unstable(feature = "euclidean_division", issue = "49048")]
#[stable(feature = "euclidean_division", since = "1.38.0")]
pub fn rem_euclid(self, rhs: f64) -> f64 {
let r = self % rhs;
if r < 0.0 {
Expand Down