unsigned-bit-shift-right

Description

Add a clojure equivalent of >>>.

The patch implements a new unsigned-bit-shift-right function that has the semantics of Java long >>>. This differs in particular in the handling of the shift distance which uses the least significant 6 bits of the shift distance (thus always in the range 0-63 inclusive). A Java method Numbers.unsignedShiftRightInt is included but not used by the surfaced function.

Patch: clj-827-unsigned-bit-shift-right-with-tests.patch

Screened by: Alex Miller

Related ticket: Ticket CLJS-514 has been created to track the future work of making ClojureScript's name for this operation the same as the one used in Clojure, after this ticket is completed. David Nolen is agreeable to making this change, even though it would rename an already-defined public function.

Environment

None

Attachments

3

Activity

Show:

Alex Miller October 11, 2013 at 6:54 PM

For reference, notes on how Java does >>> for ints and longs is here:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19

I found that section particularly helpful wrt understanding the behavior of the shift distance parameter. Namely, that for longs the shift distance uses only the least significant 6 bits (bit-and with 0x3f) which explains some of the added tests using large or negative shift distances.

Andy Fingerhut August 23, 2013 at 5:52 PM

I made some additions to the description on the one patch that I think should be considered, and why, and comments on what appears to be the current state of the ClojureScript question. Feel free to edit further if it needs it.

Michał Marczyk August 23, 2013 at 3:02 PM

AFAICT the newest two patches are relevant (Gabriel's patch – the latest one – applies on top of Tim's patch – second latest); the first one must have been left around as per the usual Clojure JIRA custom to leave historical patches in place.

As for ClojureScript, Gabriel's comment indicates that Rich expressed a preference for the name unsigned-bit-shift-right. ClojureScript can adjust to that no problem, in fact I think we should just switch the name ahead of time. There is no open question on the ClojureScript side except if Clojure actually merged the patches we'd be able to make any final adjustments and close the CLJS ticket.

NB. the adjustments to make there are only about the name of the function anyway, as explained in the comments above.

I'll also note that the present couple of patches (1) touch no existing behaviour, (2) add in a missing basic and useful operation which we cannot just simulate in Clojure if performance is a concern at all. Hence my long-standing +1 on this issue.

Alex Miller August 23, 2013 at 2:24 PM

It's unclear to me what patches are in play and whether the Clojurescript question is resolved in this ticket. Can someone clean it up? Moving to Incomplete.

Michał Marczyk June 10, 2013 at 7:57 AM

@Gabriel: I mean it's not marked private in ClojureScript, so ClojureScript already exports the ...-zero-fill name, technically speaking. As per David Nolen's comment on CLJS-514, this is probably not a big deal.

Completed

Details

Assignee

Reporter

Labels

Approval

Ok

Patch

Code and Test

Priority

Fix versions

Created August 9, 2011 at 5:42 PM
Updated November 23, 2013 at 1:06 AM
Resolved November 23, 2013 at 1:06 AM