[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Bitwise XOR in Lua?
- From: Edgar Toernig <froese@...>
- Date: Tue, 10 Sep 2002 17:47:18 +0200
Reuben Thomas wrote:
> > One problem though: -A := not(A)+1 is for 2-complement.
> > Floating point numbers (normally) do not use 2-complement
> > arithmetic.
> ? It works for integers, and normally you just want to use the mantissa to
> store the bit-string, i.e. you're treating floats as ints.
But you do not invert the mantissa by -A-1. Sure, when converting the
result to (2-complement) int you will get the right result. Now, you
have two representatins for bit-strings (mantissa only and 2-complement
version of complete value) and the operators do not work the same on both.
band(1,1) != bor(1,0) -- gives 1 and -9007199254740991
bnot(0) != bxor(bnot(0),0) -- gives -1 and 0
IMHO, it would be better to implement these functions in the C mathlib ;-)