]> git.lizzy.rs Git - rust.git/commit
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)
commit63531f515d74e20806454961fd5d05a7f1cce354
treeb581eb859a7c3247162c8b34f32e92444d68f46b
parente5462b82e3c3090be8b5d1f7fa0b687afa6e3546
parentbd853a6469fb71b4719d05c20535a70e75d1aa78
Rollup merge of #50342 - fkjogu:euclidean, r=BurntSushi

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.