[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: question on Lua 5.2 release
- From: Francesco Abbate <gslshell@...>
- Date: Sun, 17 Jan 2010 12:34:00 +0100
2010/1/17 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> Talking about the 'simple modification in luaconf.h' I'm wondering if
>> you can really add support for complex number so easily.
>
> It was not too hard, but I did not test it very much:
Hi Luiz,
first of all thank you very much for the time you took to make the adaptation.
If I understood correctly you have basically changed luaconf.h to
configure the default lua number to be 'complex double' instead of
'double'. Then you've seen that a number of adaptations were needed in
many places:
- the complex number does not have a strict order relation like real number
- you have to adapt the input/output to manage complex number correctly
- you have to modify math functions to make them handle complex numbers
- you have to define the imaginary unit I in lua => but still lua does
not accept natively complex number but you have to build them with +,
* operations and I.
So, your approach is interesting because it is the 'least minimum
effort' implementation but it does have some shortcomings like:
- no native complex number notation: 2+3i should be accepted as a
complex number natively
- the C library code asks a lua_tonumber we should cast to a double to
keep C API compatibility. Then for complex aware function you can use
lua_tocomplex/lua_iscomplex. Every number will be stored as a complex
number and lua_tonumber will just check that the imaginary part is 0
- all the functions in the math library should be adapted to accept
and manage complex number correctly.
If you integrate all these 'improvements' I'm talking about you obtain
the LNUM patch of Asko.
So I believe I was correct when I said that 'you cannot have complex
number with a simple change in luaconf.h'. In my point of view what
should be done in Lua to support complex number is to adopt, as an
option at compile time, the LNUM patch. Just fix the bugs and support
if officially. The only sensible point about this: is there enough
motivation in your team to officially support a complex number option
for Lua ?
To be constructive I can propose to implement and bug fix the LNUM
patch for complex number to be integrated in main stream Lua. I will
just need some hints from you from time to time since I'm not familiar
with lua internals. Are you willing to accept this kind of
contribution of the official Lua distribution ?
Francesco