PROPOSAL: Unsigned Integer Widening Operator
Bruce Chapman
brucechapman at paradise.net.nz
Thu Mar 26 02:15:25 PDT 2009
Noel Grandin wrote:
> I would think that a utility class that performed widening operations,
> and maybe some other useful stuff would be preferable to extending the
> language/
>
> Perhaps a BinaryMath class to live alongside java.lang.Math?
>
> Regards, Noel.
>
>
There is some truth to that. BUT on the other side of the ledger there
are two operators that add extra bits to the left of a value. Right
shift has two forms, one to sign extend and one to zero extend, whereas
widening only has a sign extend form of the operator (which is the unary
+ operator if you are wondering). Adding a zero extend widening makes
the language consistent.
Also it is worth considering that the zero extend widening operator is
(hopefully) sufficiently succinct, and gives the impression of being
sufficiently cheap that the perceived wisdom for effective unsigned byte
manipulation might become to always apply the operator to variable and
array accesses. This would reduce bugs. I don't think a method call
would have that same subconscious effect. You'd tend to only use the
method where it was actually needed, and you'd sometimes get that
decision wrong.
Bruce
> Bruce Chapman wrote:
>
>> Title
>> Unsigned Integer Widening Operator
>>
>> latest html version at http://docs.google.com/Doc?id=dcvp3mkv_2k39wt5gf&hl
>>
>> AUTHOR(S): Bruce Chapman
>>
>> OVERVIEW
>>
>>
>>
>> FEATURE SUMMARY:
>> Add an unsigned widening operator to convert bytes (in particular),
>> shorts, and chars (for completeness) to int while avoiding sign extension.
>>
>>
SNIP
More information about the coin-dev
mailing list