Skip to content

Conversation

@rubiefawn
Copy link
Contributor

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().

@Veratil
Copy link
Contributor

Veratil commented Nov 3, 2025

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?

@rubiefawn
Copy link
Contributor Author

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

@rubiefawn rubiefawn requested a review from szeli1 November 13, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants