lua-users home
lua-l archive

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


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.
I.e.

  band(1,1) != bor(1,0)		-- gives 1 and -9007199254740991

or 

  bnot(0) != bxor(bnot(0),0)	-- gives -1 and 0

IMHO, it would be better to implement these functions in the C mathlib ;-)

Ciao, ET.