lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Coda Highland once stated:
> On Tue, Aug 31, 2021 at 1:44 PM Egor Skriptunoff <egor.skriptunoff@gmail.com>
> wrote:
> 
> > On Sun, Aug 29, 2021 at 6:54 PM Soni "They/Them" L. wrote:
> >
> >> would it still be in spec to have 63-bit integers, or even "big integers"
> >
> > In other words, you have a C compiler supporting non-standard datatype
> > Int63 and ask if you can build Lua by simply `#define LUA_INTEGER
> > Int63`?
> 
> I read the question more as "would it still be standards-compliant Lua"
> (regardless of how much of a change to the code it would take to support
> it) than "will this work the way I think it will?"

  From that angle, the current Lua manual (for Lua 5.4) states:

	Standard Lua uses 64-bit integers and double-precision (64-bit)
	floats, but you can also compile Lua so that it uses 32-bit integers
	and/or single-precision (32-bit) floats.

			-- section 2.1

and for the definition of lua_Integer:

	By default this type is long long, (usually a 64-bit two-complement
	integer), but that can be changed to long or int (usually a 32-bit
	two-complement integer). (See LUA_INT_TYPE in luaconf.h.)

			-- section 4.6

The only other place where 64-bits is mentioned is when describing
math.random():

	This function uses the xoshiro256** algorithm to produce
	pseudo-random 64-bit integers, ...

			-- section 6.7

  That's it.  Those are the only sections where 64-bits are mentioned.

  As far as C is concerned, a 63-bit value is fine, but at best you are
talking about a long value.  C89 does NOT have long long types, and C99
defines the minimum size of a long long value as 64 bits (section 5.2.4.2.1
of the C99 standard).  A hypothetical 63-bit CPU would have to use two
63-bit words to define a long long type on such a CPU in order to comply
with C99.

  Given that Lua can use C89, and that you can compile Lua to use only
32-bit integers, I would think a hypothetical 63-bit CPU could support Lua
just fine, as well as "big integers", although you will probably run into
issues with code assuming 64-bit integers.  But that's my opinion---others
may disagree.

  -spc