Skip to content

Jass: print a large real literal as the float it means - #1436

Merged
Frotty merged 1 commit into
masterfrom
jass-large-real-literals
Oct 12, 2026
Merged

Frotty merged 1 commit into
masterfrom
jass-large-real-literals

Conversation

@Frotty

@Frotty Frotty commented Oct 12, 2026

Copy link
Copy Markdown
Member

Jass reads a real literal's integer part as a 32-bit integer. Measured on the 3.0.0 client, the literal 3000000000. is negative, 10000000000. reads as 1410065408, and 100000000000000000000. as 1661992960 (10^20 modulo 2^32). Past 2^24 the integer part is also truncated: 16777219. reads as 16777218. The interpreter and the game's Lua both read these literals as the nearest float. So the same program meant something else on Jass, and the stdlib's REAL_MAX (2^128) was a small wrapped number there.

What changes

  • Jass backend (imtojass.ExprTranslation.realLiteral): a literal past 2^24 is printed as the float it means.
    • Below 2^31 it is printed as the float's own digits (16777219. becomes 16777220.).
    • From 2^31 on it is a product of exact factors: the odd part and powers of two up to 2^30 (3000000000. becomes 5859375. * 512.). Jass multiplies these exactly.
    • A literal past the largest float becomes the largest float, 16777215. * 2^30 * 2^30 * 2^30 * 2^14. Jass has no product that gives infinity: 2^150 compares below 3e38 and prints 0.000, while the largest float compares above 3e38.
    • Literals up to 2^24 are printed unchanged, so most output stays byte-identical.
  • Compile-time reals (CompiletimeFunctionRunner): a real written back from compile-time code was "" + float. Java prints that with an exponent from 10^7 on and below 10^-3 (3.0E12), which pjass rejects as a syntax error. It is now the shortest plain decimal that reads back as the same float, for constants and for replayed hashtable reals. A non-finite compile-time real is reported as an error instead of being emitted as Infinity.

Measured in game (3.0.0, Jass build of this branch)

3000000000., -3000000000., 10000000000., 2147483648. and 16777219. equal the values computed from exact operands. R2S(3000000000.) is 3000000000.000, R2I(3000000000.) is 2147483647, and 6000000000. / 3000000000. is 2. The REAL_MAX literal compares above 3e38 and equals the computed largest float. A compile-time 1e7 equals the computed one.

Tests

  • LuaBackendAuditTests.largeRealLiteralsMeanTheSameFloatInEveryRun: runs on the interpreter, Jass and Lua, and asserts that no emitted Jass literal has an integer part of 2^31 or more and that 16777219. is printed as 16777220..
  • CompiletimeTests.compiletimeRealsBecomeDecimalLiterals and CompiletimeHashtableTests.largeAndSmallRealsAreReplayedAsDecimals.

Each test fails without its fix. LuaBackendAuditTests, CompiletimeTests, CompiletimeHashtableTests, OptimizerTests and InterpreterTests pass locally.

Not changed

  • Short decimal literals such as 0.1 are still read one float off by Jass (measured, docs/WC3_RUNTIME.md). Printing every literal as an exact fraction would cost a division wherever it is read.
  • Jass real multiplication does not round to nearest (1e10 * 1e10 differs from the float nearest 1e20). That is arithmetic and is not modelled.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-12T08:01:40.967461Z eeb7136 PR opened
ℹ️ 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.

@Frotty
Frotty merged commit 82c1bd2 into master Oct 12, 2026
3 checks passed
@Frotty
Frotty deleted the jass-large-real-literals branch October 12, 2026 11:25
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