All Products
Search
Document Center

Server Load Balancer:Numeric functions

Last Updated:Dec 23, 2024

This topic describes the syntax, feature, parameters, and return values of numeric functions. This topic also provides examples of numeric functions.

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

add

Item

Description

Syntax

add(n1, n2)

Feature

Calculates the sum of two addends.

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

Item

Description

Syntax

sub(n1, n2)

Feature

Calculates the difference between two numbers.

Parameters

  • n1: the (minuend) number to be subtracted from.

  • n2: the (subtrahend) number to be subtracted.

Return value

The difference of n1-n2.

Example

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

Output:

n1=-10

mul

Item

Description

Syntax

mul(n1, n2)

Feature

Calculates the product of two numbers.

Parameters

  • n1: the multiplicand.

  • n2: the other multiplicand.

Return value

The product of n1×n2.

Example

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

Output:

n1=200

div

Item

Description

Syntax

div(n1, n2)

Feature

Calculates the quotient of two numbers.

Parameters

  • n1: the dividend.

  • n2: the divisor.

Return value

The quotient of n1/n2.

Example

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

Output:

n1=0.5

mod

Item

Description

Syntax

mod(n1, n2)

Feature

Calculates the remainder after division of one number by another.

Parameters

  • n1: the dividend.

  • n2: the divisor.

Return value

The remainder of n1%n2.

Example

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

Output:

n1=15

gt

Item

Description

Syntax

gt(n1, n2)

Feature

Determines whether a number is greater than another number.

Parameters

  • n1: the number to be compared.

  • n2: the other number to be compared.

Return values

If n1 > n2, true is returned. Otherwise, false is returned.

Example

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

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

Response:

num > 10

ge

Item

Description

Syntax

ge(n1, n2)

Feature

Determines whether a number is greater than or equal to another number.

Parameters

  • n1: the number to be compared.

  • n2: the other number to be compared.

Return values

If n1 >= n2, true is returned. Otherwise, false is returned.

Example

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

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

Response:

num >= 10

lt

Item

Description

Syntax

lt(n1, n2)

Feature

Determines whether a number is smaller than another number.

Parameters

  • n1: the number to be compared.

  • n2: the other number to be compared.

Return values

If n1 < n2, true is returned. Otherwise, false is returned.

Example

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

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

Response:

num < 10

le

Item

Description

Syntax

le(n1, n2)

Feature

Determines whether a number is smaller than or equal to another number.

Parameters

  • n1: the number to be compared.

  • n2: the other number to be compared.

Return values

If n1 <= n2, true is returned. Otherwise, false is returned.

Example

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

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

Response:

num <= 10

floor

Item

Description

Syntax

floor(n)

Feature

Rounds down to the greatest integer that is smaller than or equal to a number.

Parameter

n: the number to be rounded down.

Return value

The greatest integer that is smaller than or equal to the number specified by 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.

Response:

floor: 9

ceil

Item

Description

Syntax

ceil(n)

Feature

Rounds up to the smallest integer that is greater than or equal to a number.

Parameter

n: the number to be rounded up.

Return value

The smallest integer that is greater than or equal to the number specified by 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.

Response:

ceil: 10