lua-users home
lua-l archive

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

Olivier Hamel wrote:
> Roberto Ierusalimschy wrote:
>>> Roberto said they (inner Lua dev group) weren't happy with any known 
>>> implementation of bitwise operators, it would be helpful to know
>>> what  they are not pleased with so we may propose alternate 
>>> solutions/implementations.
>> My dream was bitwise operators that make sense for floating numbers,
>> like shifts and negation do. But I gave up.
>> -- Roberto
> Oh. Well. Yah, you won't be getting very far with bitwise ops on float,
> I suggest that floats be cast to ints (or whatever) and then the ops
> performed on them. It's common knowledge you won't be getting bitwise
> ops on floats natively/naturally unless you add some (a lot) of magic
> powder to the mix with a slice of lemon. But even there, I don't thing
> the idea of bitwise ops can ever EVER apply to floats, since their
> internal representation does not match that of a 'simpler' number like
> char/short/int/etc... That said, I had in mind to use bitwise ops on
> whole numbers anyways...
> Have we considered adding fixed point precision numbers?
> Olivier

My 2nd favorite language (awk as implemented in gawk), which also uses a
double as the numeric type, takes the following tack when doing bitwise ops:

"For all of these functions, first the double-precision floating-point
value is converted to the widest C unsigned integer type, then the
bitwise operation is performed. If the result cannot be represented
exactly as a C double, leading nonzero bits are removed one by one until
it can be represented exactly. The result is then converted back into a
C double. (If you don't understand this paragraph, don't worry about it.)"


Jim Mellander
Incident Response Manager
Computer Protection Program
Lawrence Berkeley National Laboratory
(510) 486-7204

The reason you are having computer problems is:

Daemon escaped from pentagram