-
Notifications
You must be signed in to change notification settings - Fork 51
Let's make rint() work correctly once and for all. #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ffd3c83 to
0406cf4
Compare
|
@uis246 Comparison for test values with all deltas from C's rint function highlighted:
It actually matches roundf exactly on x86, but is explicit about things not cleared up in the standard. It in particular fixes the negative zero DP outputs when fed exactly 0. Let's consider this the best possible compromise between Quake and ISO C. |
|
BTW, DP's change to rint came here: So the goal of DP's change in 2006 was specifically to avoid the undefined behavior (which on x86 usually returns -2.14748365e+09, and on ARM usually saturates). |
|
I'm averse to changing the behavior of this to anything other than stock Quake, which obviously DP's version is not stock apparently, for compatibility reasons, because it involves floating point, and to give an example, last time we had 64 bit QCVM, there were so many codepaths with downcasting bugs that I had to turn it off until they were fixed in normal builds, and it caused so many subtle bugs in map logic. But if this doesn't break entity logic, timing, etc, and is more correct, sure. Do buttons return to their original position when pushed? Do elevators randomly kill you or just not work? Do doors close? Do monsters seem to act weird(er than they already do in DP)? |
|
Let's put it behind a default-on prvm_ganeplayfix? Could even also add a setting -1 that replicates original Quake brokenness?Am 25.08.2025 19:38 schrieb Cloudwalk9 ***@***.***>:Cloudwalk9 left a comment (DarkPlacesEngine/DarkPlaces#282)
I'm averse to changing the behavior of this to anything other than stock Quake, which obviously DP's version is not stock apparently, for compatibility reasons, because it involves floating point, and last time we had 64 bit QCVM, there were so many codepaths with downcasting bugs that I had to turn it off for now and it caused so many subtle bugs in map logic.
But if this doesn't break entity logic, timing, etc, and is more correct, sure. Do buttons return to their original position when pushed? Do elevators randomly kill you or just not work? Do doors close? Do monsters seem to act weird(er than they already do in DP)?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
0406cf4 to
b9c3d0e
Compare
|
Put it behind a gameplayfix, that defaults to 1, and on 0 replicates the old broken Quake behavior. |
8cf50bd to
0da6063
Compare
This matches what rint() does by default in all current compilers, but does not depend on rounding mode. NOTE: VM_rint from Quake is _not_ rint from the C standard; it does not round to _even_ when breaking ties. It actually is C23's roundeven(). Fixes issue #276.
0da6063 to
674dbf1
Compare
|
Any news here? |
This new rint() now returns always matches output sign to input.
It should match C23's round() perfectly, but is explicit about the handling of negative zeroes in input and output and still keeps the original Quake logic for safety.