lua-users home
lua-l archive

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


On Tue, Aug 9, 2011 at 01:33, David Kastrup <dak@gnu.org> wrote:
> Leo Razoumov <slonik.az@gmail.com> writes:
>
>> Actually, making lua_Numbers complex is a bad idea. Complex numbers do
>> not have a natural ordering relationship like real numbers do.
>> With integers or real numbers you can assert that for any x,y
>>
>> assert((not (x<y) and not (y<x)) == (x==y))
>>
>> For complex numbers such an ordering operator does not exist.
>
> Lexicographical ordering works just fine and fulfills that condition.
> You could also just order the bit patterns.  Lots of other
> possibilities.
>

When ordering by bit-patterns you don't really care whether underlying
entities  are Complex Numbers or not. For example, such ordering would
not preserve arithmetic operations. For example, for real numbers
statements x>y and 3*x>3*y are equivalent. But I doubt that you can
achieve the same equivalence for lexicographical order (for any
positive constant in place of 3).

To bring this discussion back to Lua I think that sensible approach
would be to keep lua_Number double while providing complex numbers by
means of userdata which is what is normally done anyway.

--Leo--