Stablize Euclidean Modulo (feature euclidean_division)

This commit is contained in:
CrLF0710 2019-07-07 12:16:13 +08:00
parent b0bd5f236d
commit 72ac8ce9aa
4 changed files with 20 additions and 41 deletions

View file

@ -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]
@ -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]
@ -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]
@ -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]
@ -1566,7 +1562,6 @@ 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));
@ -1574,7 +1569,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringi
"::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) {
@ -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]
@ -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;
@ -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]
@ -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;
@ -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]
@ -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]
@ -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]
@ -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]
@ -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]
@ -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) {
@ -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) {
@ -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]
@ -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]

View file

@ -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)]

View file

@ -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
@ -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 {
@ -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);
@ -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 {

View file

@ -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
@ -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 {
@ -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);
@ -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 {