lua-users home
lua-l archive

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


On 09.01.2010, at 14:07, Mike Pall wrote:

>> Actually your bitop lib has very strange rounding
>> characteristics due to the exotic number conversion:
> 
> Passing fractional numbers to a bit function is UNDEFINED. Look up
> the meaning of UNDEFINED in the computer literature, if necessary.

Well, with doubles being the default in Lua you get fractional numbers pretty easy. E.g. when you code up packing some numbers in some string for a network packet, file format, etc . by just dividing by the 2^8 etc. amount.  Coding everything as bit.* is neither more readable nor faster. I would expect a reasonable bitlib library to not leave this as undefined.

> And funny enough, Lua 5.2 on x86 has the exact same behavior you
> complain about! :-)

??? Where are you looking at? Have you actually gave it a try?

I see it truncating by casting. It uses lua_tonumber, so it truncates I tested before my mail on x86-64, and now double checked with i386.

> Next time better check the facts for your straw-man arguments.
> 
>> I expect a bitlib to truncate for sanity and compatibly. Like in C:
>> 
>>  double d = 1000.9;
>>  printf("%d\n", (int)d);
>> 
>> 1000
> 
> You actually write C code that mixes doubles and bit operations?!?
> Please come up with a more realistic argument.

No. But given that Lua (reasonably) defaults to double I expect to be able to use them reasonably. And not to trap into a surprising result in every line:

-- your bitlib
=  bit.band(0xffff / 256, 0xff)
0

-- lua-5.2(work1)
= bit.band(0xffff / 256, 0xff)
255

>> The strange rounding of your lib made me use my own that just
>> casts. Works on all the platforms I care about (x86, x64-64,
>> ppc, ppc64, sparc64 and I do not see where it should fail), and
>> is actually some 20% or so faster than your strange game that is
>> the fiddling with the union.
> 
> Ah, I see. So you didn't read the page on semantics. Nor have you
> understood the rationale for the implementation. And obviously the
> platforms *you* care about must be the only platforms everyone
> should care about? Fail.

Oh, I care about even more, I forgot ARM. Anyway, this was just a hint that I test and work with more than the usual i386. I could also care less about the semantics you artificially define. I care about readable code and stuff working in ways of the least surprise.

-- 
  René Rebe, ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin
  http://exactcode.com | http://t2-project.org | http://rene.rebe.name