lua-users home
lua-l archive

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


On Thu, Jun 27, 2019 at 10:47 AM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
excellent ! (note that your did not include the function header "function f(x)" and trailer "end" and the code "=x" to print the result on the Lua console).

Oh right, I meant to write print(x) instead of return x, that way it doesn't have to be a function. I just forgot that was my plan when I started writing it.

It works because the range from 0 to 395 is small enough and it assumes that math.random() will return an exact value.

This can create an infinite loop if this condition x*x=C is never reached exactly, because:
- random() will not explore all the possible bits, as random() does not return all the possible values for the 52 bits of numbers in (0,1).
- even if you have the best approximation possible of x, x^x=C may still be wrong (and there's no upper bound of the relative error on the value of x).

I knew it was terrible when I submitted it. :P

/s/ Adam