Elliot.Lockerman.info


Pebbles

Pebbles is a cli/repl programmer's calculator featuring

Examples

Wrapping arithmetic:

$ pebbles --type=u8 '2 * 0x83'
6₁₀
        6₁₆
0000 0110₂

Octal, bitwise operators:

$ pebbles --type=u8 --base=oct '1 << (2 | 1)'
8₁₀
     1   0₈
00 001 000₂

Signed types, repl:

$ pebbles --type=i32                         
> 0o12 + -2 * 6
-2₁₀
   F    F    F    F    F    F    F    E₁₆
1111 1111 1111 1111 1111 1111 1111 1110₂

Usage

Literals can be decimal (no prefix), hexadecimal (0x prefix), or octal (0o prefix). A unary - gives the two's complement for both signed and unsigned types.

Pebbles operations generally tries to emulate machine primitives. For example, rather than being undefined behavior, shifts are mod the machine width:

$ pebbles --type=u8
 2 << 3
16₁₀
   1    0₁₆
0001 0000₂
> 2 << 11
16₁₀
   1    0₁₆
0001 0000₂

However, for practical reasons, full multiply/full divide (with double width product/dividend, respectively) are not currently provided. Divide and mod follow the C-style truncating (i.e., round-to-zero) convention, with mod having the same sign and the left-hand side.

Operators generally follow the traditional C model, although either ~ or ! are allowed for bitwise negation. Boolean and comparison operators are not available.

Operator precedence (greatest to least):

Github