You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Evaluator / Javaluator computes x * 2^-1 wrongly instead of rejecting it #197
A unary minus directly after ^ is mishandled when another operator comes before it. A bare 2^-1 is rejected, but x * 2^-1 is accepted and returns a wrong number.
Repro
Codex 1.3.0-dev.2 (studio.magemonkey.codex.util.eval.Evaluator, published 1.3.0-SNAPSHOT build 20261115.232732-2):
Unary minus elsewhere is fine. The string evaluator (Evaluator.eval / DoubleEvaluator.evaluate) gives the same wrong result, so the bug is in the bundled Javaluator parser and predates Evaluator.compile. ^ is left associative, which may be related to how the unary minus binds.
Expected: either the correct value or a parse/compile error. Never a silently wrong number.
Impact
Divinity's combat.yml lets admins write damage formulas. A plausible damage * 2^-1 would silently compute wrong damage.
Downstream workaround to remove once fixed
magemonkeystudio/divinity#387 added a guard: CombatFormulas rejects any override where ^ is followed (ignoring whitespace) by -, and tells the admin to write 2^(-1). After this is fixed, Divinity should:
remove the NEGATIVE_EXPONENT check in src/main/java/studio/magemonkey/divinity/manager/damage/formula/CombatFormulas.java;
remove its test CombatFormulasTest.brokenFormula_negativeExponentWithoutBrackets_isRejected (negativeExponentWithBrackets_isAccepted can stay);
drop the related wording in src/main/resources/combat.yml and doc/COMBAT_RESTRUCTURE_NOTES.md;
raise MIN_CORE_VERSION to the Codex build with the fix.
Activity