Expand description
Lua numeral conversion core (stone candidate: pure functions, no runtime
types). Two consumers: the lexer (literal tokens, shape pre-validated by
scanning) and the VM/stdlib (str2num — luaO_str2num semantics with
whitespace and sign). Versioning is expressed as capability flags so this
module stays dialect-agnostic.
Enums§
- Float
Fmt - Float rendering flavor per dialect generation — each PUC line
prints floats with a different
LUA_NUMBER_FMT(v2.14 HD, pinned by the per-dialect diff corpus): - Num
- Result of parsing a Lua numeric literal — either an integer or a float (Lua 5.1 collapses everything to float at this layer).
Functions§
- dec_
literal - Decimal numeral (no sign, no surrounding space).
int_ok = falseforces float results (Lua 5.1: numbers are doubles).negis whether a leading ‘-’ was stripped by the caller: it widens the integer range by one unit (PUC l_str2int’s+ neg) so that the magnitude 2^63 parses as an integer — lettingtonumber("-9223372036854775808")recover minint. The caller still applies the actual negation. - hex_
digit - Decode a single ASCII hex digit (
0-9,a-f,A-F) into its numeric value, or returnNonefor a non-hex byte. - hex_
literal - Hex numeral after the
0xprefix (no sign, no surrounding space). - num_
to_ string - Lua number → text. Integers print as integers. Floats print with
shortest round-trip digits (the 5.5 “read back correctly” rule) in
C
%g-style presentation: scientific form when the decimal exponent falls outside [-4, 14), two-digit signed exponent, and.0appended to integral-looking decimals (PUC lua_number2str). Exact boundary alignment against PUC 5.5 output is rechecked by the P04 gate (strings/math suites). - num_
to_ string_ for - Render a number per the dialect’s float flavor. Integers are flavor-independent.
- str2num
- luaO_str2num: optional surrounding whitespace and sign, decimal or hex.
Used by VM string→number coercion and
tonumber. - write_
i64_ dec - Write i64 decimal into a stack buffer; returns the slice of valid
bytes inside
buf. 20 chars covers i64::MIN..=i64::MAX (the longest is “-9223372036854775808” at 20 bytes). Hot in tostring(int) on numeric-heavy workloads (string_concat builds 5000 of these): skips the String allocation thati.to_string()does.