]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #50342 - fkjogu:euclidean, r=BurntSushi
authorkennytm <kennytm@gmail.com>
Wed, 27 Jun 2018 22:15:38 +0000 (06:15 +0800)
committerGitHub <noreply@github.com>
Wed, 27 Jun 2018 22:15:38 +0000 (06:15 +0800)
Document round-off error in `.mod_euc()`-method, see issue #50179

Due to a round-off error the method `.mod_euc()` of both `f32` and `f64` can produce mathematical invalid outputs. If `self` in magnitude is much small than the modulus `rhs` and negative, `self + rhs` in the first branch cannot be represented in the given precision and results into `rhs`. In the mathematical strict sense, this breaks the definition. But given the limitation of floating point arithmetic it can be thought of the closest representable value to the true result, although it is not strictly in the domain `[0.0, rhs)` of the function. It is rather the left side asymptotical limit. It would be desirable that it produces the mathematical more sound approximation of `0.0`, the right side asymptotical limit. But this breaks the property, that `self == self.div_euc(rhs) * rhs + a.mod_euc(rhs)`.

The discussion in issue #50179 did not find an satisfying conclusion to which property is deemed more important. But at least we can document the behaviour. Which this pull request does.


Trivial merge