Repository navigation
Add platform option for Lua 5.2 numeric text - #393
Merged
Merged
Conversation
Add LuaNumberFormat.DotNet and LuaNumberFormat.Lua on LuaPlatform, keeping the existing invariant managed default and public LuaValue.ToString(). Route Lua numeric text through shared string/span formatting so the Lua option uses C-locale %.14g and portable signed inf/nan spellings across conversion, concatenation, replacements, explicit-base tonumber and I/O. Explicit floating-point formats keep their requested finite precision. Normalize Windows CRT NaN classifiers instead of making serialized text host-dependent. Preserve NaN bits, sign, arithmetic and string parsing. Document the policy and precision implications in both READMEs. Validation: Release solution build passes without warnings for all runtime targets. Full runtime suites pass on .NET 8/10, plus 73 generator tests; all 58 numeric policy cases pass on both frameworks. CSharpier and benchmark --verify pass. Native Lua 5.2 comparisons cover 18,567 implicit conversions and 15 I/O cases with zero differences after NaN suffix normalization. Explicit format comparisons identify existing Windows CRT hex-format spelling/flag differences, which are intentionally not emulated. Paired .NET 10 default conversion benchmarks remain within about 4% of main, with unchanged allocations; Lua mode's shorter 1/3 output is about 4-16% faster in the sampled conversion workloads.
5 tasks
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.
Recreates #384 as an opt-in platform policy, preserving the existing managed default.
DotNetpreserves invariant managed numeric text.Luauses Lua 5.2's default C-locale%.14g: 14 significant digits, lowercase exponents, signed zero, and portable signedinf/nan. For example,tostring(1/3)produces0.33333333333333.The option covers
tostringand numeric__tostringresults,%s/%q, concatenation,table.concat, all numericgsubreplacements, explicit-basetonumbernumeric inputs, and numeric I/O (including accepted numeric input/output filenames). Coroutines inherit it independently of string mode. Explicit floating-point formats retain their requested finite precision; their special-value spellings follow the option. Public C#LuaValue.ToString(), arithmetic, NaN bits and parsing of numeric strings remain unchanged.C Lua 5.2 details
LUA_NUMBER_FMTas%.14g. Numeric coercion and numeric I/O use it.sprintf; they do not all use 14 digits.%qquotes numeric text in Lua 5.2.nan(ind)/nan(snan), as Microsoft documents. TheLuaoption normalizes these to signednan, without serializing CRT classifier suffixes or changing the input bits. Existing portable finite%aformatting is retained; Windows CRT hexadecimal-format quirks are not emulated.tonumber(1e14,10)returns nil inLuamode because its intermediate text is1e+14; the managed default is preserved.Validation
--verifypass.