about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian <chris_veenman@hotmail.com>2019-03-30 10:03:47 +0100
committerChristian <chris_veenman@hotmail.com>2019-03-30 10:03:47 +0100
commitea369cbc2f733568779215fd2aa68a54d5b75327 (patch)
tree9402c5d3ffb09d039cc7654d974fadbb32dcedb6
parent8fe108796d9674bb828023539089b6e0636d9ea1 (diff)
downloadrust-ea369cbc2f733568779215fd2aa68a54d5b75327.tar.gz
rust-ea369cbc2f733568779215fd2aa68a54d5b75327.zip
Added an example that shows how the remainder function on floating point values is computed internally.
-rw-r--r--src/libcore/ops/arith.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libcore/ops/arith.rs b/src/libcore/ops/arith.rs
index 007a8db6c47..484461687e4 100644
--- a/src/libcore/ops/arith.rs
+++ b/src/libcore/ops/arith.rs
@@ -540,7 +540,17 @@ macro_rules! rem_impl_float {
 
         /// The remainder from the division of two floats.
         ///
-        /// The remainder has the same sign as the dividend. For example: `-5.0 % 2.0 = -1.0`.
+        /// The remainder has the same sign as the dividend and is computed as:
+        /// `x - (x / y).trunc() * y`.
+        ///
+        /// # Examples
+        /// ```
+        /// let x: f32 = 4.0;
+        /// let y: f32 = 2.5;
+        /// let remainder = x - (x / y).trunc() * y;
+        ///
+        /// assert_eq!(x % y, remainder);
+        /// ```
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Rem for $t {
             type Output = $t;