Skip to content

Interpreters and Lua: real division by zero stops, R2I saturates, as measured - #1435

Merged
Frotty merged 3 commits into
masterfrom
interp-real-division-by-zero
Oct 11, 2026
Merged

Frotty merged 3 commits into
masterfrom
interp-real-division-by-zero

Conversation

@Frotty

@Frotty Frotty commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Two interpreter models of Jass's real arithmetic were wrong, and so was the Lua R2I outside the 32-bit range. Each was measured on the 3.0.0 client with operands computed at run time, so no literal reader touches them.

A real division by zero stops the thread

Jass stops the thread on 1. / 0., -1. / 0., 0. / 0., 5. % 0. and ModuloReal(5., 0.), each run in a guarded callback in a test map. The interpreters answered an infinity, so a real modulo by zero (Blizzard.j's formula since #1433) answered the dividend, and the program went on.

  • WurstOperator.divideReal throws the same ArithmeticException as an integer division by zero. The IM interpreter (/ and the real modulo) and the Jass interpreter (ILconstNum.div) both divide reals through it.
  • The game's Lua does not stop: 1. / 0. is 1.7014e38 (the largest float, not an infinity), -1. / 0. its negative, and 0. / 0. is 1. The Lua backend adds no check, which would cost every real division whose divisor is not a literal.

R2I saturates; R2S and R2SW print the whole number; real literals past 2^31 are what wraps

computed at run time Jass the game's Lua the interpreter before
R2I(50000. * 100000.) (5000000320) 2147483647 2147483647 705032704 (wrapped)
R2I(-(50000. * 100000.)) -2147483648 -2147483648 -705032704
R2I( a computed 1e20 ) 2147483647 wrapped
R2S(30000. * 100000.) 3000000000.000 -1294967296.000
R2SW(-(30000. * 100000.), 1, 3) -3000000000.000 1294967296.000

The wrap the interpreter modelled came from literals. Jass reads a real literal whose integer part passes 2^31 as wrapped to 32 bits, signed: 3000000000. > 0. is false in Jass, and 10000000000. reads as 1410065408. The earlier measurements of R2I, R2S and R2SW used such literals, so they recorded the literal reader, not the natives.

  • WurstOperator.realToInt (the interpreter's R2I) saturates, as Java's cast does, with NaN as 0.
  • R2S and R2SW print the whole integer part, exactly, also past the long range.
  • On Lua, the inline R2I and __wurst_rawR2I answer the bound themselves outside the range. Before, they called the global R2I, which the game has but nothing defined for the test runtime. The test runtime's own R2I fallback saturates too.
  • Not modelled, and recorded in docs/WC3_RUNTIME.md: Jass's wrapped reading of such literals (the interpreter, like Lua, reads them correctly), and the game printing a computed 5e9 as 5000000320.000.

Tests

  • realDivisionByZeroStopsTheInterpreters (new): 1. / 0., 5. % 0. and 0. / 0. stop the interpreter and the Jass interpreter.
  • r2iSaturatesInEveryRun (new): R2I of a computed 5000000320, its negative and its square, plus a real modulo whose quotient leaves the range, in the interpreter, on Jass and on Lua.
  • stringNativesAsMeasured: the literal-based R2S/R2SW/R2I expectations become the computed measurements above.
  • Each fails on master.
  • Passed: LuaBackendAuditTests, LuaTranslationTests, InterpreterTests, LuaNativesTests, CompiletimeTests, CompiletimeNativesTest, BugTests, OptimizerTests, NewFeatureTests, RealWorldExamples. The full suite is left to CI.

…n Jass

Measured on the 3.0.0 client: 1. / 0., 0. / 0., 5. % 0. and ModuloReal(5., 0.) stop the thread in Jass. The interpreters answered an infinity and went on; a real division or modulo by zero is now the same error as an integer one.
@Frotty

Frotty commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T15:01:11.863298Z 441416f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b96b0e8c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty Frotty changed the title Interpreters: a real division by zero stops, as it stops the thread in Jass Interpreters and Lua: real division by zero stops, R2I saturates, as measured Oct 11, 2026
…d values

Measured on the 3.0.0 client with operands computed at run time: R2I saturates outside the 32-bit range in Jass and in the game's Lua, and R2S and R2SW print the whole integer part. The wrap the interpreter modelled was Jass's reading of real literals past 2^31. The interpreter's R2I saturates and its R2S and R2SW print the whole number; on Lua the R2I lowering answers the bound itself instead of calling the global R2I, which the test runtime did not define.
@Frotty

Frotty commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: dc729dd7cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 441416fc57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit 6421419 into master Oct 11, 2026
3 checks passed
@Frotty
Frotty deleted the interp-real-division-by-zero branch October 11, 2026 19:48
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.

1 participant