convert signed int to complex number

Can anyone advise hoe I can go from a signed 16 bit int to a complex number ?

eg. -32000 to complex number equivalent ? [import]uid: 97524 topic_id: 18933 reply_id: 318933[/import]

http://lua-users.org/wiki/ComplexNumbers

To get a complex number you have to call the function complex.to( num )

Haven’t used it though… you will have to try it out! [import]uid: 64174 topic_id: 18933 reply_id: 72934[/import]

thanks man! [import]uid: 97524 topic_id: 18933 reply_id: 72941[/import]

The function (via Satheesh’s link) wont work “as is”. It might be possible to make it work, (loadstring isn’t supported in Corona). let us know how you get on however [import]uid: 84637 topic_id: 18933 reply_id: 73227[/import]

I’m finding corona’s limitations sooo frustrating. This is my first time using it and it keeps throwing obstacles back at me!!

Danny
Q1 is there any other way to convert a 16bit signed int to a complex number in Corona?

Q2 Is there a list of other stuff Corona doesn’t support like loadString?

[import]uid: 97524 topic_id: 18933 reply_id: 73282[/import]

In the complex numbers module,something like
[lua]local temp = tonumber(imag)
if temp then
return setmetatable( { 0,temp }, complex_meta )
end[/lua]
instead of
[lua]imag = loadstring(“return tonumber(”…imag…")")
if imag then
return setmetatable( { 0,imag() }, complex_meta )
end[/lua]
should work no? I am no Lua expert… just asking…
[import]uid: 64174 topic_id: 18933 reply_id: 73290[/import]

I appreciate your attempt Satheesh, but I’m no good at complex numbers. I’m afraid I can’t comment on your ‘mod’ =)

Anyone know if Numeric Lua works with Corona ?
http://numlua.luaforge.net/
[import]uid: 97524 topic_id: 18933 reply_id: 73326[/import]

satheesh, I’m going to give your code a try

there’s only 4 or 5 instances of loadstring in complex.lua so it might work!

what about this line?

loadstring(“return tonumber(”…sign…imag…")")

is it possible to message you direct? I’d really like to get this working. [import]uid: 97524 topic_id: 18933 reply_id: 73487[/import]

[lua]local temp = tonumber(sign…imag)[/lua]
should do…

P.S I really have no idea whether this would work or not…So don’t blame me if it doesn’t :slight_smile: [import]uid: 64174 topic_id: 18933 reply_id: 73488[/import]

I’m happy to try!
sorry I mean what is…

imag = loadstring(“return tonumber(”…sign…imag…")")
[import]uid: 97524 topic_id: 18933 reply_id: 73490[/import]

@Dax
I suggested the modification to that complex numbers in github and the author himself did a modification to eliminate loadstring…
https://github.com/davidm/lua-matrix/commit/8dd7aa293fdaaf5808736214a06ff121121300d5
Wonderful guy! :smiley:
Hope that works! [import]uid: 64174 topic_id: 18933 reply_id: 73731[/import]

brilliant - well done mate! [import]uid: 97524 topic_id: 18933 reply_id: 73732[/import]