Clojure

Cannot cast 0xFF to a byte (fails range check)

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

Prompted by a thread on the clojure group.

The recently added range checking to casts/coercions adversely affects a common usage of the byte cast to pull the 8 LSBs of an integer. Since the numerical representation of a byte is signed in java, the Byte.MIN_VALUE</code> and <code>Byte.MAX_VALUE</code> used in the range check of <code>clojure.lang.RT.byteCast() do not allow for integer values up to 0xFF.

Activity

Hide
Assembla Importer added a comment -

ataggart said: [file:b_MyyAn4mr34xSeJe5avMc]: Adds a ubyte coercion when the resulting byte should be considered unsigned, thus inputs of 0-255 are acceptable

Show
Assembla Importer added a comment - ataggart said: [file:b_MyyAn4mr34xSeJe5avMc]: Adds a ubyte coercion when the resulting byte should be considered unsigned, thus inputs of 0-255 are acceptable
Hide
Assembla Importer added a comment -

ataggart said: Patch provided to add a ubyte coercion:

<pre>user=> 0xFF
255
user=> (Integer/toBinaryString 0xFF)
"11111111"
user=> (byte 0xFF)
java.lang.IllegalArgumentException: Value out of range for byte: 255 (NO_SOURCE_FILE:0)
user=> (ubyte 0xFF)
-1
user=> (ubyte 256)
java.lang.IllegalArgumentException: Value out of range for unsigned byte: 256 (NO_SOURCE_FILE:0)
</pre>

Show
Assembla Importer added a comment - ataggart said: Patch provided to add a ubyte coercion: <pre>user=> 0xFF 255 user=> (Integer/toBinaryString 0xFF) "11111111" user=> (byte 0xFF) java.lang.IllegalArgumentException: Value out of range for byte: 255 (NO_SOURCE_FILE:0) user=> (ubyte 0xFF) -1 user=> (ubyte 256) java.lang.IllegalArgumentException: Value out of range for unsigned byte: 256 (NO_SOURCE_FILE:0) </pre>
Hide
Assembla Importer added a comment -

richhickey said: This is really a subset of #441

Show
Assembla Importer added a comment - richhickey said: This is really a subset of #441
Hide
Assembla Importer added a comment -

ataggart said: Agreed.

Show
Assembla Importer added a comment - ataggart said: Agreed.

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: