Skip to content

Arithmetic

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Arithmetic expressions compute numeric results—integers or floats—from bins, constants, and nested expressions. Use them in read/write operation expressions (for example projection or computed writes), inside comparison expressions when you need a derived value on the left or right, and anywhere the client API accepts a numeric expression.

Operators include add, sub, mul, div, pow, log, mod, abs, floor, ceil, min, max, to_int, to_float, and integer bitwise helpers (int_and, int_or, int_xor, int_not, shifts, int_count, int_lscan, int_rscan). Operand types must match the operator (for example, pow and log use floats; bitwise operations use integers). These operations require Database 5.6.0 or later unless noted otherwise.

Numeric operations typically act on children of the same type only. For example, Exp.add(Exp.val(1), Exp.val(2.0)) is an error as float cannot be added to an integer. Exp.toFloat(...) and Exp.toInt(...) can be used to convert numeric types.

For boolean filters on records (true/false/unknown), wrap numeric results in a comparison or combine with logic expressions. Nested document scenarios often compose arithmetic with path or map/list expressions.

The Developer SDK’s AEL text syntax expresses the same arithmetic inline, for example ($.price * $.qty) > 1000.

Each operation’s Example shows the code in nine tabs: Aerospike Expression Language (AEL) text on the Java SDK and Python SDK tabs, and the Exp builder on the other seven. See the AEL reference for AEL grammar.

Ops

abs

abs(value)
Description

Returns the absolute value of value. The result keeps the type it was given: an integer operand yields an integer, a float operand yields a float.

Arguments
NameTypeDescription
valueinteger or float

Number to take the absolute value of. Any expression that evaluates to an integer or a float.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the absolute value of the difference between integer bins x1 and x2 is greater than 1.

String exp = "abs($.x1 - $.x2) > 1";

add

add(arg0, arg1, ...)
Description

Returns the sum of its arguments. Every argument must be the same numeric type — all integers or all floats. Mixing them is rejected.

Arguments
NameTypeDescription
arg0integer or float

First number to add.

arg1integer or float

Second number to add.

...integer or float

Any further numbers to add.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the sum of integer bins apples and bananas is greater than 10.

String exp = "$.apples + $.bananas > 10";

ceil

ceil(value)
Description

Returns value rounded up to the nearest whole number, as a float.

Arguments
NameTypeDescription
valuefloat

Float to round up.

Returns
float
Introduced
5.6.0
Example

Find records where the ceiling of float bin value equals 2.0.

String exp = "ceil($.value) == 2.0";

div

div(arg0, arg1, ...)
Description

Returns its arguments divided from left to right, so div(10, 5, 2) is (10 / 5) / 2. Integer operands divide as integers, so div(10, 4) is 2 rather than 2.5. Dividing by zero fails the expression. Every argument must be the same numeric type — all integers or all floats. Mixing them is rejected.

Arguments
NameTypeDescription
arg0integer or float

Number to divide.

arg1integer or float

Number to divide by.

...integer or float

Any further divisors, applied left to right.

Returns
integer or float
Introduced
5.6.0
Example

Find records where candy divided by kids (as floats) is less than 1.0.

String exp = "$.candy:INT.toFloat() / $.kids:INT.toFloat() < 1.0";

floor

floor(value)
Description

Returns value rounded down to the nearest whole number, as a float.

Arguments
NameTypeDescription
valuefloat

Float to round down.

Returns
float
Introduced
5.6.0
Example

Find records where the floor of float bin value equals 2.0.

String exp = "floor($.value) == 2.0";

int_and

int_and(arg0, arg1, ...)
Description

Returns the bitwise AND of two or more integers.

Arguments
NameTypeDescription
arg0integer

First integer.

arg1integer

Second integer.

...integer

Any further integers.

Returns
integer
Introduced
5.6.0
Example

Find records where integer bin flags bitwise-AND mask 0xF is non-zero.

String exp = "($.flags & 0xF) != 0";

int_arshift

int_arshift(value, by_numbits)
Description

Returns value shifted right by by_numbits bits, preserving the sign, so int_arshift(-8, 1) is -4.

Arguments
NameTypeDescription
valueinteger

Integer to shift.

by_numbitsinteger

Number of bit positions to shift by.

Returns
integer
Introduced
5.6.0
Example

Find records where arithmetic right-shift of integer bin value by 3 bits (divide by 8) is less than 1000.

String exp = "($.value >> 3) < 1000";

int_count

int_count(value)
Description

Returns the number of bits set to 1 in value.

Arguments
NameTypeDescription
valueinteger

Integer whose bits set to 1 are counted.

Returns
integer
Introduced
5.6.0
Example

Find records where the population count of integer bin visits is greater than 15.

String exp = "countOneBits($.visits) > 15";

int_lscan

int_lscan(value, search)
Description

Returns the index of the first bit in value that matches search, scanning from the most significant bit, which is index 0. When search is true the scan looks for a bit set to 1; when false, for a bit set to 0.

Arguments
NameTypeDescription
valueinteger

Integer to scan.

searchboolean

Bit value to look for: true finds a bit set to 1, false finds a bit set to 0.

Returns
integer
Introduced
5.6.0
Example

Find records where a left-scan for a 0 bit in integer bin value returns an index greater than 30, so its 31 most significant bits are all 1, as in a small negative number.

String exp = "findBitLeft(x: $.value, value: false) > 30";

int_lshift

int_lshift(value, by_numbits)
Description

Returns value shifted left by by_numbits bits.

Arguments
NameTypeDescription
valueinteger

Integer to shift.

by_numbitsinteger

Number of bit positions to shift by.

Returns
integer
Introduced
5.6.0
Example

Find records where integer bin visits left-shifted by 1 bit is greater than 100.

String exp = "($.visits << 1) > 100";

int_not

int_not(value)
Description

Returns the bitwise complement of value, so int_not(0) is -1.

Arguments
NameTypeDescription
valueinteger

Integer to complement.

Returns
integer
Introduced
5.6.0
Example

Find records where bitwise NOT of integer bin flags is not zero.

String exp = "~$.flags != 0";

int_or

int_or(arg0, arg1, ...)
Description

Returns the bitwise OR of two or more integers.

Arguments
NameTypeDescription
arg0integer

First integer.

arg1integer

Second integer.

...integer

Any further integers.

Returns
integer
Introduced
5.6.0
Example

Find records where the bitwise OR of integer bins read_mask and write_mask is non-zero.

String exp = "($.read_mask | $.write_mask) > 0";

int_rscan

int_rscan(value, search)
Description

Returns the index of the last bit in value that matches search, scanning from the least significant bit. Indexes are counted from the most significant bit, which is index 0, so on a 64-bit integer the least significant bit is index 63.

Arguments
NameTypeDescription
valueinteger

Integer to scan.

searchboolean

Bit value to look for: true finds a bit set to 1, false finds a bit set to 0.

Returns
integer
Introduced
5.6.0
Example

Find records where a right-scan for a 1 bit in integer bin visits returns an index greater than 56, so at least one of its 7 least significant bits is set.

String exp = "findBitRight(x: $.visits, value: true) > 56";

int_rshift

int_rshift(value, by_numbits)
Description

Returns value shifted right by by_numbits bits, filling from the left with zeros. The value is treated as unsigned, so int_rshift(-8, 1) is a large positive number rather than -4. Use int_arshift to preserve the sign.

Arguments
NameTypeDescription
valueinteger

Integer to shift.

by_numbitsinteger

Number of bit positions to shift by.

Returns
integer
Introduced
5.6.0
Example

Determine whether bit 6 of integer bin flags, counting from 0 at the least significant bit (the 64 bit), is set: a logical right shift by 6, then a mask of 1.

String exp = "(($.flags >>> 6) & 1) == 1";

int_xor

int_xor(arg0, arg1, ...)
Description

Returns the bitwise XOR of two or more integers.

Arguments
NameTypeDescription
arg0integer

First integer.

arg1integer

Second integer.

...integer

Any further integers.

Returns
integer
Introduced
5.6.0
Example

Find records where the bitwise XOR of integer bins a and b is non-zero.

String exp = "($.a ^ $.b) > 0";

log

log(num, base)
Description

Returns the logarithm of num in base base. Both operands must be floats; integers are rejected.

Arguments
NameTypeDescription
numfloat

Number to take the logarithm of.

basefloat

Base of the logarithm.

Returns
float
Introduced
5.6.0
Example

Find records where the base-8 logarithm of float bin branches is greater than 2.

String exp = "log(value: $.branches, base: 8.0) > 2.0";

max

max(arg0, arg1, ...)
Description

Returns the largest of its arguments. All arguments must be the same numeric type: either all integers or all floats.

Arguments
NameTypeDescription
arg0integer or float

First number to compare.

arg1integer or float

Second number to compare.

...integer or float

Any further numbers to compare.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the maximum of integer bins value0–value3 is greater than 100.

String exp = "max($.value0, $.value1, $.value2, $.value3) > 100";

min

min(arg0, arg1, ...)
Description

Returns the smallest of its arguments. All arguments must be the same numeric type: either all integers or all floats.

Arguments
NameTypeDescription
arg0integer or float

First number to compare.

arg1integer or float

Second number to compare.

...integer or float

Any further numbers to compare.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the minimum of integer bins value0–value3 is less than 10.

String exp = "min($.value0, $.value1, $.value2, $.value3) < 10";

mod

mod(numerator, denominator)
Description

Returns the remainder of numerator divided by denominator. The remainder takes the sign of the numerator, so mod(-7, 3) is -1. A denominator of zero fails the expression.

Arguments
NameTypeDescription
numeratorinteger

Number to divide.

denominatorinteger

Number to divide by. Zero fails the expression.

Returns
integer
Introduced
5.6.0
Example

Find records where integer bin value modulo 2 equals 0.

String exp = "$.value % 2 == 0";

mul

mul(arg0, arg1, ...)
Description

Returns the product of its arguments, or the argument itself when only one is given. Every argument must be the same numeric type — all integers or all floats. Mixing them is rejected.

Arguments
NameTypeDescription
arg0integer or float

First number to multiply.

arg1integer or float

Second number to multiply.

...integer or float

Any further numbers to multiply.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the product of integer bins height and width is less than 100.

String exp = "$.height * $.width < 100";

pow

pow(base, exponent)
Description

Returns base raised to the power of exponent. Both operands must be floats; integers are rejected.

Arguments
NameTypeDescription
basefloat

Number to raise.

exponentfloat

Power to raise base to.

Returns
float
Introduced
5.6.0
Example

Find records where float bin p raised to the power of integer bin events (converted to float) is less than 0.5.

String exp = "pow(base: $.p, exponent: $.events:INT.toFloat()) < 0.5";

sub

sub(arg0, arg1, ...)
Description

Returns its arguments subtracted from left to right, so sub(10, 5, 2) is (10 - 5) - 2. Every argument must be the same numeric type — all integers or all floats. Mixing them is rejected.

Arguments
NameTypeDescription
arg0integer or float

Number to subtract from.

arg1integer or float

Number to subtract.

...integer or float

Any further numbers to subtract, applied left to right.

Returns
integer or float
Introduced
5.6.0
Example

Find records where the difference between integer bin assets and debts is less than 1000000.

String exp = "$.assets - $.debts < 1000000";

to_float

to_float(value)
Description

Returns value, an integer, converted to a float.

Arguments
NameTypeDescription
valueinteger

Integer to convert.

Returns
float
Introduced
5.6.0
Example

Find records where to_float of integer bin quantity is at least 1.0 (for float comparisons without changing stored bin types).

String exp = "$.quantity:INT.toFloat() >= 1.0";

to_int

to_int(value)
Description

Returns value, a float, converted to an integer by truncating toward zero, so 2.5 becomes 2.

Arguments
NameTypeDescription
valuefloat

Float to convert.

Returns
integer
Introduced
5.6.0
Example

Find records where to_int of float bin list_price equals 12 (aligned with whole-dollar list prices in path docs).

String exp = "$.list_price:FLOAT.toInt() == 12";