Arithmetic¶
Bit Shifts¶
- shift_left(string $value, int $shift) string ¶
$value << $shift
- shift_right(string $value, int $shift) string ¶
$value >> $shift
Addition and Subtraction¶
- add(string $a, string $b) string ¶
$a + $b
- add_int(string $a, int $b) string ¶
$a + $b
optimized for small integers
- sub(string $a, string $b) string ¶
$a - $b
- sub_int(string $a, int $b) string ¶
$a - $b
optimized for small subtrahends
- sub_int_rev(int $a, string $b) string ¶
$a - $b
optimized for small minuends
Multiplication¶
- mul(string $a, string $b) string ¶
$a * $b
- mul_int(string $a, int $b) string ¶
$a * $b
optimized for small integers
Division¶
- div_mod(string $a, string $b) [string, string] ¶
$a /% $b
- Returns:
[quotient, remainder]
- div_mod_int(string $a, int $b) [string, int] ¶
$a /% $b
optimized for small divisors- Returns:
[quotient, remainder]
- div(string $a, string $b) string ¶
$a / $b
- div_int(string $a, int $b) string ¶
$a / $b
optimized for small divisors
- mod(string $a, string $b) string ¶
$a % $b
- mod_int(string $a, int $b) int ¶
$a % $b
optimized for small divisors- Returns:
Result is integer because if $b can be represented as native integer, remainder can be too
Comparison¶
- compare(string $a, compare $b) int ¶
$a <=> $b
- Returns:
Same values as the spaceship operator
Bit manipulation¶
- is_bit_set(string $a, int $bit) bool ¶
- Parameters:
$bit (
int
) – Bit number, 0 is the least significant bit
- Returns:
If
$bit
’th bit is set
- set_bit(string $a, int $bit) string ¶
Set
$bit
’th bit to 1- Parameters:
$bit (
int
) – Bit number, 0 is the least significant bit
- unset_bit(string $a, int $bit) string ¶
Set
$bit
’th bit to 0- Parameters:
$bit (
int
) – Bit number, 0 is the least significant bit