coerce values to accumulator type for AddSource/SubSource #479
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When combining values, they're automatically promoted to the most permissive data type (float is preferred over integer if either operand is a float), but the accumulator type is fixed by the first thing stored in it. So if the accumulator is an integer and a float value is subtracted, the accumulator was being changed into a float, the subtraction was performed, then the result was turned back into an integer to store in the accumulator.
Because subtracting a decimal value results in another decimal value slightly lower than if only the whole part was subtracted, forcing that result back to an integer results in a value one lower than if the integer conversion had occurred before the subtraction.
Given the expression:
If multiple coercions occur, the result is 0:
But if the coercion only appies to the modifier, the result is 1:
Given the way the accumulator functions, I think the coercion should only be applied to the modifier.
This is also consistent with rcheevos prior to 12.0. More information is here: https://discord.com/channels/476211979464343552/1437468039162630244/1437589445355503717