[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Comparing numerical objects for equality (patch)**
**From**: Tomás Guisasola <tomasguisasola@...>
**Date**: Thu, 9 Jun 2022 12:24:54 -0300

Hi Andrew
> I think you are saying that if a number fits in a Lua integer then the
> mpi module should simply return an integer.
Yes.
> But now what happens when we multiply two numbers which both fit in a
> Lua integer but the product does not.
>
> mpi(1000000000000000) * mpi(1000000000000000) -> ?
>
> If the two operands were converted to Lua integers then the result would
> just overflow, because Lua doesn't know that they are supposed to be big
> integers! That would defeat the whole object of the mpi module.
Sure.
> Of course my example of mpi(1) == 1 is trivial. In general we might have
> a complex big integer calculation which we are comparing with an integer
> constant, eg:
>
> local a = <some mpi calculation>
> if (a == 137)
> ...
>
> So the numbers have to stay in mpi format even if they would fit into a
> Lua integer.
Thanks for the explanation. But now I think that _all_ numbers would
have to stay in mpi format to ensure everything works. Since an
operation between two numbers could overflow, it would be wise to use
every number as an mpi-number. In other words, the ability to add
small integers like 1 or 137 without "converting" them could lead to
miscalculation, don't you think?
Regards,
Tomás