lua-users home
lua-l archive

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

Wow, thanks for pointing that out.  I notice that there was a "lua ordered keys" patch offered by Dave Rodgers a couple of years ago, which seems like it would result in deterministic traversal.

The link to the patch is dead, though, and I can't seem to find an extant copy of that patch (even tried  Anyone have a copy they could send me?  It's OK if it doesn't merge with the current source, I can fix it up, or at least get a good sense from it of what needs to change.


On 12/14/2011 at 6:53 PM, Peter Cawley <> wrote:
My concerns would arise from hash table traversal, due to many objects
being hashed based on their memory address rather than their contents.
As a silly example, the following code snippet is non-deterministic:
t = {}
t[{}] = 1
t[{}] = 2
k, v = next(t)
print(v) --> Sometimes 1, sometimes 2.

A slightly more realistic example is the following, which is
non-deterministic due to addition of IEEE doubles not being
obj1, obj2, obj3 = {}, {}, {}
xs[obj1] = 1
xs[obj2] = 1
xs[obj3] = 2^53
for obj,x in pairs(xs) do
sum = sum + x
print(("%.0f"):format(sum)) --> Sometimes 9007199254740992, sometimes

On Wed, Dec 14, 2011 at 3:46 AM, <> wrote:
> I would like to make a version of lua with perfectly reproducible results on
> all machines which run it.  I think the main difficulty is reproducibility
> of floating-point calculations, but if there are other possible snags, I
> would be happy to learn of them.  My plan is to replace the arithmetic
> macros in luaconf.h and the function calls lmathlib.c with calls to the
> relevant functions in the MPFR library, which should make atomic
> floating-point operations reproducible.  I am also concerned about ensuring
> reproducible order of execution.  If I compile with gcc using -O0, will that
> suffice?
> Holly