[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A pure-lua complex math library with some new design choices
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 28 Nov 2016 07:46:33 -0200
> I wrote a new pure-lua implementation of complex numbers.
I suggest you include a sample program such as mandelbrot.lua attached below
to show the library in action and to test performance.
However, complex arithmetic (or any arithmetic for that matter) is not to
be taken lightly. Care is needed to avoid unnecessary loss of precision or
overflow. For instance, your code for cabs may overflow:
local abs = applyOldOrNew(
function(c) return luamath.sqrt(re(c)*re(c) + im(c)*im(c)) end,
See http://www.netlib.org/fdlibm/e_hypot.c for a robust implementation of hypot.
For a reference implementation of complex arithmetic, see the cephes library at
> Second, I did download a few other complex libraries for lua and tried them. None clicked exactly with what I was looking for, so decided to have a go at rolling my own.
I'd like feedback on what you found lacking in my lcomplex library.
Send it off-list if you prefer. Thanks.
local function level(x,y)
until abs(z)>2 or l>255
local xmax= 1
local ymax= 1.5
print("# mandelbrot set",xmin,xmax,ymin,ymax,N)
for i=1,N do
for j=1,N do