Closed
Description
The newly added method std::f64::mod_euc()
can produce values equal to the modulus when applied to a small negative float and sufficiently big modulus. AFAIK this should never happen.
I tried this code on nightly rustc 1.27.0-nightly (ac3c2288f 2018-04-18)
and the version on playground:
#![feature(euclidean_division)]
fn main() {
let f = -std::f64::EPSILON;
let m = 3.0f64;
assert!(f.mod_euc(m) < m);
}
https://play.rust-lang.org/?gist=01a506080183f14067553856de6763ab&version=nightly
I expected to see this happen:
The operation should produce only values in between 0. <= x < modulos
.
Instead, this happened:
But it produced a value equal to the modulus, in this case 3.
. This is true for all sufficiently big floats relative to the machine epsilon.
Discussion
It is likely a bug in the implementation ignoring some floating point arithmetic oddities. I haven't looked deeper yet.