float_cmp false positive: catching underflow #2834
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Presently,
float_cmp
informs thatis an incorrect comparison of float. If I was comparing two distinct floats, then I would agree; however, the check here is meant to detect when the addition of
h
tot
doesn't actually increaset
.The check for an exact equality is necessary here, and the suggestion of using
EPSILON
is incorrect ast + h
might still be distinct fromt
(especially ift
andh
are both much less thanEPSILON
). Technically, one would check that(t + h) - t < MIN_POSITIVE
, but this is only because it is equivalent to(t + h) - t == 0.0
(and has the drawback of obscuring the real intention of the check in the first place).In my case, I'm using this check to ensure that the step size used when solving an ODE never stops increasing
t
(which is not the best check in this use-case and can be improved, but I'm sure there are other cases where this check might still be desirable and valid).From checking the standard library, I'm not sure whether there is a better way of checking for this situation other than through
t == t + h
.The text was updated successfully, but these errors were encountered: