Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

Bitwise

9 functions

Bit operations on an Int, read as a 64-bit two's-complement word. There are no bit operators: and, or, xor and not combine words, and the shifts and rotations move bits. None of them allocates or traps.

Bitwise.and(Bitwise.shl(1, 4), 255)
Returns
16

At a glance

  • and

    Bitwise and.

  • or

    Bitwise or.

  • xor

    Bitwise exclusive or.

  • not

    Every bit flipped: not(n) is -n - 1, so not(0) is -1.

  • shl

    Shift left, filling with zeros.

  • shr

    Arithmetic shift right, filling with copies of the sign bit, so a negative number stays negative: shr(-8, 1) is -4, and shr(-1, n) is -1.

  • shrU

    Logical shift right, filling with zeros, so a negative number turns positive: shrU(-1, 1) is the largest Int.

  • rotl

    Rotate left: the bits shifted out of the top come back in at the bottom.

  • rotr

    Rotate right: the bits shifted out of the bottom come back in at the top.

Functions

and

(Int, Int) -> Intpure

Bitwise and. It reads its Int arguments as 64-bit two's-complement words and answers the word it computes, read the same way.

or

(Int, Int) -> Intpure

Bitwise or. It reads its Int arguments as 64-bit two's-complement words and answers the word it computes, read the same way.

xor

(Int, Int) -> Intpure

Bitwise exclusive or. It reads its Int arguments as 64-bit two's-complement words and answers the word it computes, read the same way.

not

(Int) -> Intpure

Every bit flipped: not(n) is -n - 1, so not(0) is -1.

shl

(Int, Int) -> Intpure

Shift left, filling with zeros. The bits shifted past the top are lost. The amount, the second argument, is taken modulo 64: shl(n, 64) is n, shl(n, 65) is shl(n, 1), and a negative amount counts back from 64, so shl(n, -1) is shl(n, 63). No amount traps.

shr

(Int, Int) -> Intpure

Arithmetic shift right, filling with copies of the sign bit, so a negative number stays negative: shr(-8, 1) is -4, and shr(-1, n) is -1. The amount is taken modulo 64, as shl takes it. No amount traps.

shrU

(Int, Int) -> Intpure

Logical shift right, filling with zeros, so a negative number turns positive: shrU(-1, 1) is the largest Int. The amount is taken modulo 64, as shl takes it. No amount traps.

rotl

(Int, Int) -> Intpure

Rotate left: the bits shifted out of the top come back in at the bottom. The amount is taken modulo 64, as shl takes it. No amount traps.

rotr

(Int, Int) -> Intpure

Rotate right: the bits shifted out of the bottom come back in at the top. The amount is taken modulo 64, as shl takes it. No amount traps.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.