Repository navigation
Jass: print a large real literal as the float it means - #1436
Merged
Merged
Conversation
…e real without an exponent
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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, and100000000000000000000.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'sREAL_MAX(2^128) was a small wrapped number there.What changes
imtojass.ExprTranslation.realLiteral): a literal past 2^24 is printed as the float it means.16777219.becomes16777220.).3000000000.becomes5859375. * 512.). Jass multiplies these exactly.16777215. * 2^30 * 2^30 * 2^30 * 2^14. Jass has no product that gives infinity: 2^150 compares below 3e38 and prints0.000, while the largest float compares above 3e38.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 asInfinity.Measured in game (3.0.0, Jass build of this branch)
3000000000.,-3000000000.,10000000000.,2147483648.and16777219.equal the values computed from exact operands.R2S(3000000000.)is3000000000.000,R2I(3000000000.)is 2147483647, and6000000000. / 3000000000.is 2. TheREAL_MAXliteral compares above 3e38 and equals the computed largest float. A compile-time1e7equals 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 that16777219.is printed as16777220..CompiletimeTests.compiletimeRealsBecomeDecimalLiteralsandCompiletimeHashtableTests.largeAndSmallRealsAreReplayedAsDecimals.Each test fails without its fix.
LuaBackendAuditTests,CompiletimeTests,CompiletimeHashtableTests,OptimizerTestsandInterpreterTestspass locally.Not changed
0.1are 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.1e10 * 1e10differs from the float nearest 1e20). That is arithmetic and is not modelled.