On 03.10.2016 15:22, Andrew Schorr wrote:
> On Sunday, October 2, 2016 at 9:55:41 PM UTC-4, Janis Papanagnou wrote:
>> Here I disagree with you; the fact how the external value representation
>> is (invisible to the user) _internally_ stored *should* not be of
>> concern, specifically in such a (conceptually) strange case where a
>> floating point encoding is used and/or conversions take place implicitly.
>> The language user should get a well defined "Bit-Manipulation" concept at
>> the interface without being bothered with conceptually irrelevant
>> floating point issues.
>
> But in what way is this "well-defined"?
By "well defined" I was referring to specifying the supported width of
the bit array, or by supporting bit arrays with unrestricted length.
> I just don't follow what the OP
> expects to happen here with negative values.
It's actually a standard behaviour in Bit-Manipulation libraries. Why do
you think there are terms like "logical" and "arithmetical" bit-shifts
existing? (See Wikipedia, for example, or a 101 computer science course.)
> It's very dependent on the
> internal representation, so it seems to me to be rather uninteresting and
> not useful.
Conceptual behaviour shouldn't be dependent of the internal representation.
Only the length should be the primary factor, and the shift semantic the
secondary factor, you don't need more.
I suspect you seem to view it from the Awk implementation side; starting
from the given Awk specific fact that "everything" is a floating point
number, and some logic defined on top of that container data type, as
opposed to the view of bit-manipulation working on bit-strings or integral
data types (where any [in awk differing] underlying container data type
should be hidden from the user if necessary).
>
> Try running with -M, and it goes into an infinite loop!
Don't know what you are refering to by "it". (If you mean the OP's code
I won't comment on it, with or without -M, since it's anyway Bad Code.)
>
>> It is (seemingly) documented, but as so many other delegated functions
>> in GNU Awk it's not clearly defined where it says "widest C unsigned
>> integer type". (While for many applications it's probably sufficient,
>> it's not suited for applications who have to rely on well defined
>> conditions; those folks, though, would probably use Ada and not use Awk
>> for such purposes.) Usually bit operations in computer languages are done
>> on an integral data type, and usually a two's complement representation
>> is used for negative values. It's at least obvious to assume shifts (with
>> a semantic of being either a logical or an arithmetic shift) also with
>> negative values. GNU Awk's bit manipulation features are, IMO, anyway not
>> very sophisticated (it's size restricted, most functions can be done with
>> arithmetic as well, there's no I/O capabilities (as the OP needed to
>> implement that himself), and basic bit-functions are missing). Probably
>> yet another area for GNU Awk's extension library.
>
> I don't think "usual" behavior is a good basis for writing a robust
> program.
A robust behaviour is well documented. Shifting negative values is standard
since the introduction of [signed] integer registers and shift functions.
If lacking documentation (or even if documented) one can expect that "usual"
behaviour is supported, presuming that usual behaviour is reflecting state
of the art since at least the mid of the last century.
> I still question what the OP wants to achieve.
Two-fold answer; a) he wanted to shift negative numbers - a valid request,
b) he does some strange padding (and whatnot) - which makes not much sense
in this Awk context.
(I wouldn't be astonished if it's only a test program to see how GNU Awk
behaves, before the OP would use these functions in his "production code".)
> This is simply not
> well-defined with respect to the awk language. Note that these functions
> are gawk extensions, so we're really in uncharted territory with this.
Since Bit-Manipulation is an GNU Awk extension to standard Awk the developer
was free to define it sensibly. (I already commented upthread what I think
about the state of that implementation.)
Why "uncharted territory"? (The functions are listed in the documentation.)
Janis
>
> Regards, Andy
>
>