All Products
Search
Document Center

Server Load Balancer:Numeric functions

Last Updated:Apr 01, 2026

Numeric functions for ALB forwarding rule scripts support arithmetic operations and numeric comparisons.

add | sub | mul | div | mod | gt | ge | lt | le | floor | ceil

add

Calculates the sum of two numbers.

Syntax: add(n1, n2)

Parameters:

  • n1: the addend.

  • n2: the other addend.

Return value: The sum of n1 + n2.

Example:

n1 = add(10, 20)
say(concat('n1=', n1))

Output:

n1=30

sub

Calculates the difference between two numbers.

Syntax: sub(n1, n2)

Parameters:

  • n1: the minuend (the number to subtract from).

  • n2: the subtrahend (the number to subtract).

Return value: The difference of n1 - n2.

Example:

n1 = sub(10, 20)
say(concat('n1=', n1))

Output:

n1=-10

mul

Calculates the product of two numbers.

Syntax: mul(n1, n2)

Parameters:

  • n1: the multiplicand.

  • n2: the other multiplicand.

Return value: The product of n1 × n2.

Example:

n1 = mul(10, 20)
say(concat('n1=', n1))

Output:

n1=200

div

Calculates the quotient of two numbers.

Syntax: div(n1, n2)

Parameters:

  • n1: the dividend.

  • n2: the divisor.

Return value: The quotient of n1 / n2.

Example:

n1 = div(10, 20)
say(concat('n1=', n1))

Output:

n1=0.5

mod

Calculates the remainder after dividing one number by another.

Syntax: mod(n1, n2)

Parameters:

  • n1: the dividend.

  • n2: the divisor.

Return value: The remainder of n1 % n2.

Example:

n1 = mod(35, 20)
say(concat('n1=', n1))

Output:

n1=15

Comparison functions

gt, ge, lt, and le compare two numeric values and return a boolean. All four functions take the same parameters.

Parameters:

  • n1: the first number to compare.

  • n2: the second number to compare.

FunctionSyntaxConditionReturns true when
gtgt(n1, n2)greater thann1 > n2
gege(n1, n2)greater than or equal ton1 >= n2
ltlt(n1, n2)less thann1 < n2
lele(n1, n2)less than or equal ton1 <= n2

Returns false otherwise.

Query string variables such as $arg_num are strings. Use tonumber() to convert them to numbers before passing to a comparison function.

Examples:

Check whether num is greater than 10:

if and($arg_num, gt(tonumber($arg_num), 10)) {
    say('num > 10')
}

Request: /path1/path2/file?num=11. Output:

num > 10

Check whether num is greater than or equal to 10:

if and($arg_num, ge(tonumber($arg_num), 10)) {
    say('num >= 10')
}

Request: /path1/path2/file?num=10. Output:

num >= 10

Check whether num is less than 10:

if and($arg_num, lt(tonumber($arg_num), 10)) {
    say('num < 10')
}

Request: /path1/path2/file?num=9. Output:

num < 10

Check whether num is less than or equal to 10:

if and($arg_num, le(tonumber($arg_num), 10)) {
    say('num <= 10')
}

Request: /path1/path2/file?num=10. Output:

num <= 10

floor

Rounds a number down to the nearest integer.

Syntax: floor(n)

Parameter: n: the number to round down.

Return value: The largest integer less than or equal to n.

Example:

if $arg_num {
    #The tonumber function converts a string to a number.
    say(concat('floor: ', floor(tonumber($arg_num))))
}

Request: /path1/path2/file?num=9.3. Output:

floor: 9

ceil

Rounds a number up to the nearest integer.

Syntax: ceil(n)

Parameter: n: the number to round up.

Return value: The smallest integer greater than or equal to n.

Example:

if $arg_num {
    #The tonumber function converts a string to a number.
    say(concat('ceil: ', ceil(tonumber($arg_num))))
}

Request: /path1/path2/file?num=9.3. Output:

ceil: 10