Skip to content

Arithmetic

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 ops use integers). Needs server 5.6.0+ for these ops unless noted otherwise in each operation.

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.

Ops

abs

abs(value)
Description

Creates an absolute-value operator that returns the absolute value of a number. The argument must be either an ‘integer_expr’ or a ‘float_expr’.

Arguments
NameType
value number_expr
Returns
number_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.abs(Exp.sub(
Exp.intBin("x1"), Exp.intBin("x2"))),
Exp.val(1)));

add

add(arg0, arg1, ...)
Description

Creates an addition (+) operator that applies to a variable number of expression arguments. Arguments must all be either ‘float_expr’ or ‘integer_expr’.

Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.add(
Exp.intBin("apples"),
Exp.intBin("bananas")),
Exp.val(10)));

ceil

ceil(value)
Description

Creates an expression that rounds a floating-point number up to the closest integer value. The argument must be a ‘float_expr’.

Arguments
NameType
value float_expr
Returns
float_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.eq(
Exp.ceil(Exp.floatBin("value")),
Exp.val(2.0)));

div

div(arg0, arg1, ...)
Description

Creates a division operator (/) that applies to a variable number of expression arguments. Divides arguments from left to right, such that div(10,5) equals (10/5) and div(10,5,2) equals (10 / (5 * 2)), or, in alternate notation, ((10 / 5) / 2). If only one argument is supplied, returns the reciprocal (1/x) for that argument or, if the single argument is an integer type, returns 0 to avoid type incompatibility (as the reciprocal of an integer is a fraction). Arguments must all be either ‘float_expr’ or ‘integer_expr’.

Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.lt(
Exp.div(
Exp.toFloat(Exp.intBin("candy")),
Exp.toFloat(Exp.intBin("kids"))),
Exp.val(1.0)));

floor

floor(value)
Description

Creates an expression that rounds a floating-point number down to the closest integer value. The argument must be a ‘float_expr’.

Arguments
NameType
value float_expr
Returns
float_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.eq(
Exp.floor(Exp.floatBin("value")),
Exp.val(2.0)));

int_and

int_and(arg0, arg1, ...)
Description

Creates an “and” operator (&) that is applied to two or more integers. All arguments must resolve to integers.

Arguments
NameType
arg0 integer_expr
arg1 integer_expr
... integer_expr
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.ne(
Exp.intAnd(Exp.intBin("flags"), Exp.val(0xF)),
Exp.val(0)));

int_arshift

int_arshift(value, by_numbits)
Description

Creates an arithmetic right-shift operator (>>) for use with integers.

Arguments
NameType
value integer_expr
by_numbits integer_value
Returns
integer_value
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.

Expression exp = Exp.build(
Exp.lt(
Exp.arshift(Exp.intBin("value"), Exp.val(3)),
Exp.val(1000)));

int_count

int_count(value)
Description

Creates an expression that returns a count of integer bits that are set to 1.

Arguments
NameType
value integer_expr
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.count(Exp.intBin("visits")),
Exp.val(15)));

int_lscan

int_lscan(value, search)
Description

Creates an expression that scans integer bits from the left (the most significant bit) to the right (the least significant bit), looking for a bit value. When the value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan searches for the bit value 1. If “search” is false, it searches for the bit value 0.

Arguments
NameType
value integer_expr
search boolean_expr
Returns
integer_value
Introduced
5.6.0
Example

Find records where a left-scan for bit 0 in integer bin value reports an index greater than 30 (leading bits mostly clear).

Expression exp = Exp.build(
Exp.gt(
Exp.lscan(Exp.intBin("value"), Exp.val(false)),
Exp.val(30)));

int_lshift

int_lshift(value, by_numbits)
Description

Creates a left-shift operator (<<) for use with integers.

Arguments
NameType
value integer_expr
by_numbits integer_value
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.lshift(Exp.intBin("visits"), Exp.val(1)),
Exp.val(100)));

int_not

int_not(value)
Description

Creates a “not” operator (~) that is applied to an integer.

Arguments
NameType
value integer_expr
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.ne(
Exp.intNot(Exp.intBin("flags")),
Exp.val(0)));

int_or

int_or(arg0, arg1, ...)
Description

Creates an “or” operator (|) that is applied to two or more integers. All arguments must resolve to integers.

Arguments
NameType
arg0 integer_expr
arg1 integer_expr
... integer_expr
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.intOr(
Exp.intBin("read_mask"),
Exp.intBin("write_mask")),
Exp.val(0)));

int_rscan

int_rscan(value, search)
Description

Create expression that scans integer bits from right (the least significant bit) to left (the most significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0.

Arguments
NameType
value integer_expr
search boolean_expr
Returns
integer_value
Introduced
5.6.0
Example

Find records where a right-scan for bit 1 in integer bin visits reports an index greater than 56 (recent activity in high bits of a 64-bit field).

Expression exp = Exp.build(
Exp.gt(
Exp.rscan(Exp.intBin("visits"), Exp.val(true)),
Exp.val(56)));

int_rshift

int_rshift(value, by_numbits)
Description

Creates a logical right-shift operator (>>>) for use with integers.

Arguments
NameType
value integer_expr
by_numbits integer_value
Returns
integer_value
Introduced
5.6.0
Example

Determine whether the 6th bit from the left is set in integer bin flags (logical right shift then mask).

Expression exp = Exp.build(
Exp.eq(
Exp.intAnd(
Exp.rshift(Exp.intBin("flags"), Exp.val(6)),
Exp.val(1)),
Exp.val(1)));

int_xor

int_xor(arg0, arg1, ...)
Description

Creates an “xor” operator (^) that is applied to two or more integers. All arguments must resolve to integers.

Arguments
NameType
arg0 integer_expr
arg1 integer_expr
... integer_expr
Returns
integer_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.intXor(
Exp.intBin("a"),
Exp.intBin("b")),
Exp.val(0)));

log

log(num, base)
Description

Creates a “log” operator for the logarithm of the number “num” with base “base”. Arguments must all be ‘float_expr’.

Arguments
NameType
num float_expr
base float_expr
Returns
float_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.gt(
Exp.log(Exp.floatBin("branches"), Exp.val(8.0)),
Exp.val(2.0)));

max

max(arg0, arg1, ...)
Description

Creates an expression that returns the maximum value in a variable number of expressions. Arguments must all be either ‘float_expr’ or ‘integer_expr’.

Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

Find records where the maximum of integer bins value0value3 is greater than 100.

Expression exp = Exp.build(
Exp.gt(
Exp.max(
Exp.intBin("value0"),
Exp.intBin("value1"),
Exp.intBin("value2"),
Exp.intBin("value3")),
Exp.val(100)));

min

min(arg0, arg1, ...)
Description

Creates an expression that returns the minimum value in a variable number of expressions. Arguments must all be either ‘float_expr’ or ‘integer_expr’.

Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

Find records where the minimum of integer bins value0value3 is less than 10.

Expression exp = Exp.build(
Exp.lt(
Exp.min(
Exp.intBin("value0"),
Exp.intBin("value1"),
Exp.intBin("value2"),
Exp.intBin("value3")),
Exp.val(10)));

mod

mod(numerator, denominator)
Description

Creates a modulo operator (%) that determines the remainder of “numerator” divided by “denominator”. Arguments must all be ‘integer_expr’.

Arguments
NameType
numerator integer_expr
denominator integer_expr
Returns
integer_value
Introduced
5.6.0
Example

Find records where integer bin value modulo 2 equals 0.

Expression exp = Exp.build(
Exp.eq(
Exp.mod(Exp.intBin("value"), Exp.val(2)),
Exp.val(0)));

mul

mul(arg0, arg1, ...)
Description

Creates a multiplication operator (*) that applies to a variable number of expression arguments. If only one argument is supplied, returns that argument. Arguments must all be either ‘float_expr’ or ‘integer_expr’.

Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.lt(
Exp.mul(
Exp.intBin("height"),
Exp.intBin("width")),
Exp.val(100)));

pow

pow(base, exponent)
Description

Creates a “pow” operator that raises the base “base” to the power of “exponent”. Arguments must all be ‘float_expr’.

Arguments
NameType
base float_expr
exponent float_expr
Returns
float_value
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.

Expression exp = Exp.build(
Exp.lt(
Exp.pow(
Exp.floatBin("p"),
Exp.toFloat(Exp.intBin("events"))),
Exp.val(0.5)));

sub

sub(arg0, arg1, ...)
Description

Creates a subtract operator (-) that applies to a variable number of expression arguments. Arguments must all be either ‘float_expr’ or ‘integer_expr’. Subtracts arguments from left to right:

  • sub(10,5) = (10-5) = 4
  • sub(10,5,1) = (10 - (5 + 1)) = 1 or, in alternate notation, ((10 - 5) - 1).
  • Negates single arguments: sub(-1) = 1 and sub(1) = -1.
Arguments
NameType
arg0 number_expr
arg1 number_expr
... number_expr
Returns
number_value
Introduced
5.6.0
Example

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

Expression exp = Exp.build(
Exp.lt(
Exp.sub(
Exp.intBin("assets"),
Exp.intBin("debts")),
Exp.val(1000000)));

to_float

to_float(value)
Description

Creates an expression that converts an integer value to a floating-point value. The argument must be a ‘float_expr’.

Arguments
NameType
value integer_expr
Returns
float_value
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).

Expression exp = Exp.build(
Exp.ge(
Exp.toFloat(Exp.intBin("quantity")),
Exp.val(1.0)));

to_int

to_int(value)
Description

Creates an expression that converts a floating-point value to an integer value. The argument must be a float_expr.

Arguments
NameType
value float_expr
Returns
integer_value
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).

Expression exp = Exp.build(
Exp.eq(
Exp.toInt(Exp.floatBin("list_price")),
Exp.val(12)));
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?