Skip to content

Commit

Permalink
Rollup merge of #59529 - DevQps:improve-rem-docs, r=cuviper
Browse files Browse the repository at this point in the history
Added documentation on the remainder (Rem) operator for floating points.

# Description

As has been explained in #57738 the remainder operator on floating points is not clear.
This PR requests adds some information on how the `Rem` / remainder operator on floating points works.

Note also that this description is for both `Rem<f32> for f32` and `Rem<f64> for f64` implementations.

Ps. I wasn't really sure on how to formulate things. So please suggest changes if you have better idea's!

closes #57738
  • Loading branch information
Centril committed Apr 2, 2019
2 parents 57a4f17 + a1c7905 commit 21e2e98
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libcore/ops/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ rem_impl_integer! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

macro_rules! rem_impl_float {
($($t:ty)*) => ($(

/// The remainder from the division of two floats.
///
/// The remainder has the same sign as the dividend and is computed as:
/// `x - (x / y).trunc() * y`.
///
/// # Examples
/// ```
/// let x: f32 = 50.50;
/// let y: f32 = 8.125;
/// let remainder = x - (x / y).trunc() * y;
///
/// // The answer to both operations is 1.75
/// assert_eq!(x % y, remainder);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
impl Rem for $t {
type Output = $t;
Expand Down

0 comments on commit 21e2e98

Please sign in to comment.