From ea369cbc2f733568779215fd2aa68a54d5b75327 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 30 Mar 2019 10:03:47 +0100 Subject: [PATCH] Added an example that shows how the remainder function on floating point values is computed internally. --- src/libcore/ops/arith.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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;