lua-users home
lua-l archive

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


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
associative:
xs={}
obj1, obj2, obj3 = {}, {}, {}
xs[obj1] = 1
xs[obj2] = 1
xs[obj3] = 2^53
sum=0
for obj,x in pairs(xs) do
  sum = sum + x
end
print(("%.0f"):format(sum)) --> Sometimes 9007199254740992, sometimes
9007199254740994.

On Wed, Dec 14, 2011 at 3:46 AM,  <hollyrosella@hushmail.com> 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
>