Skip to content

All numbers in gab are IEEE 754 64-bit floating point values. There is no distinct integer type.

gab\number

Numbers literals may have leading -, or even be written with exponents, or in hex.

1
-42
1.2e4
0.2

3.14?   #  gab\number

Numbers less than one require a leading zero: 0.5, not .5. A bare . is the empty message send in gab.

Arithmetic

The standard arithmetic operators are all message sends:

10 + 3   #  13
10 - 3   #  7
10 * 3   #  30
10 / 3   #  3.33333
10 % 3   #  1

Bitwise operations and 53-bit integers

For bitwise operations, gab uses 53-bit integers. This is because 64-bit floats can only represent integers losslessly up to 2^52. Limiting integers to 52 bits guarantees that gab can convert freely between its float representation and integer operations without loss.

1 << 52   #  -4.5036e+15
1 << 53   #  0

The standard bitwise operators:

4 & 6    #  4   (AND)
4 | 2    #  6   (OR)
4 << 1   #  8   (left shift)
4 >> 1   #  2   (right shift)

Bit-shifting edge cases

gab defines behaviour for several cases that are undefined or implementation-defined in C.

Shifting by a negative amount is treated as a shift in the opposite direction:

4 >> -1   #  8
4 << -1   #  2

Shifting by more than 52 returns zero:

4 >> 65   #  0
4 << 65   #  0

Shifting negative integers follows Lua’s semantics: the shift is performed on the unsigned bit representation, then converted back. This means right-shifting a negative number does not preserve the sign bit — it produces a large positive number:

-4 >> 1   #  9223372036854775806
-4 << 1   #  -8

This is asymmetric but is the most efficient implementation, and shifting negative integers is uncommon enough that the trade-off is worthwhile.