File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,10 @@ impl f32 {
254
254
255
255
/// Calculates the Euclidean modulo (self mod rhs), which is never negative.
256
256
///
257
- /// In particular, the result `n` satisfies `0 <= n < rhs.abs()`.
257
+ /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
258
+ /// most cases. However, due to a floating point round-off error it can
259
+ /// result in `r == rhs.abs()`, violating the mathematical definition, if
260
+ /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`.
258
261
///
259
262
/// # Examples
260
263
///
@@ -266,6 +269,8 @@ impl f32 {
266
269
/// assert_eq!((-a).mod_euc(b), 1.0);
267
270
/// assert_eq!(a.mod_euc(-b), 3.0);
268
271
/// assert_eq!((-a).mod_euc(-b), 1.0);
272
+ /// // limitation due to round-off error
273
+ /// assert!((-std::f32::EPSILON).mod_euc(3.0) != 0.0);
269
274
/// ```
270
275
#[ inline]
271
276
#[ unstable( feature = "euclidean_division" , issue = "49048" ) ]
Original file line number Diff line number Diff line change @@ -230,7 +230,10 @@ impl f64 {
230
230
231
231
/// Calculates the Euclidean modulo (self mod rhs), which is never negative.
232
232
///
233
- /// In particular, the result `n` satisfies `0 <= n < rhs.abs()`.
233
+ /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
234
+ /// most cases. However, due to a floating point round-off error it can
235
+ /// result in `r == rhs.abs()`, violating the mathematical definition, if
236
+ /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`.
234
237
///
235
238
/// # Examples
236
239
///
@@ -242,6 +245,8 @@ impl f64 {
242
245
/// assert_eq!((-a).mod_euc(b), 1.0);
243
246
/// assert_eq!(a.mod_euc(-b), 3.0);
244
247
/// assert_eq!((-a).mod_euc(-b), 1.0);
248
+ /// // limitation due to round-off error
249
+ /// assert!((-std::f64::EPSILON).mod_euc(3.0) != 0.0);
245
250
/// ```
246
251
#[ inline]
247
252
#[ unstable( feature = "euclidean_division" , issue = "49048" ) ]
You can’t perform that action at this time.
0 commit comments