lmms icon indicating copy to clipboard operation
lmms copied to clipboard

Adjust model rounding behavior to avoid a potential future mystery bug

Open rubiefawn opened this issue 3 months ago • 2 comments

AutomatableModel::fittedValue() currently rounds values using nearbyintf(), whose behavior depends on the current rounding mode. The default rounding mode appears to be FE_TONEAREST and is not ever changed in the entire LMMS codebase, so fittedValue() has been doing the same thing as round(), but with the added possibility of exploding if someone in the future decides to call fesetround() somewhere. This PR replaces nearbyintf() with round() to be more explicit about the behavior and eliminate the possibility of any spooky action resulting from different rounding modes.

This PR also cleans up formatting and replaces two ifs with a call to clamp().

rubiefawn avatar Nov 03 '25 21:11 rubiefawn

According to cppref:

If the current rounding mode is FE_TONEAREST, this function rounds to even in halfway cases (like std::rint, but unlike std::round).

So it seems there might be a behavior difference?

Veratil avatar Nov 03 '25 21:11 Veratil

There is. The behavior of round() seems more sensible to me, and rint() is also dependent on the current rounding mode.

rubiefawn avatar Nov 03 '25 21:11 rubiefawn