GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix integer literals above MAX_SAFE_INTEGER changing value on Lua 5.3+ by bardrop · Pull Request #1740 · TypeScriptToLua/TypeScriptToLua

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #1734

printNumericLiteral printed numbers with String(value). For integer values above Number.MAX_SAFE_INTEGER, String() rounds to 17 significant digits and has no point or exponent, so Lua 5.3+ reads it as an exact 64-bit integer with a different value:

const a = 4611686018427387904; // 2 ** 62
print(a === 2 ** 62);
local a = 4611686018427388000 -- integer, 96 more than 2^62
print(a == 2 ^ 62)            -- false

The printer now adds .0 when the value is an integer outside the safe range and the text has no exponent (4611686018427388000.0). Lua then reads it as a float, which rounds to the same double JS has. Values at or below 2^53 - 1 print as before, and values like 1e+21 already have an exponent, so no snapshots change. The fix is in the printer, so it also covers inlined const enum values and hex literals (0x4000000000000000).

Tests: added functional tests in test/unit/expressions.spec.ts (run on every Lua target except JIT) for decimal, negative and hex literals above 2^53, plus a const enum case. 17 fail before the change (5.3, 5.4, 5.5 and universal) and all pass after. npm test (lint + full jest run) passes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bardrop
fix integer literals above MAX_SAFE_INTEGER changing value on Lua 5.3+
698cef3
String() rounds large doubles to 17 significant digits and drops the
point, so Lua 5.3+ read 4611686018427387904 as the exact integer
4611686018427388000 instead of 2^62. Print a trailing .0 for integer
values outside the safe range so Lua reads them as the same double.

Fixes TypeScriptToLua#1734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Large integer literals between 2^53 and 2^63 emit as rounded Lua 5.3+ integers

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@bardrop
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.