Math Functions

In this section:

 

Math functions enable you to generate configuration parameters and to assist with tests. This section lists and describes the various math functions that you can use in iWay Service Manager.


Top of page

x
_add(): Add a List of Terms

The _add() function is used to add a list of terms. It uses the following format:

_add(term, term*)

term

number

Number to be added.

This function returns the sum of the terms. There is nothing implied by the order of the terms.



x
_sub(): Subtract

The _sub() function is used to return the difference. It uses the following format:

_sub(minuend, subtrahend)

minuend

number

Number to be subtracted from.

subtrahend

number

Number to be subtracted from the minuend.



x
_mod(): Returns the Modulus

The _mod() function produces the remainder of dividing the first term by the second. For example: mod(22,6) = 4 because 22 / 6 = 3 with a remainder of 4. This is often written 22%6 in common arithmetic.

The _mod() function uses the following format:

_mod(term, modulus)

term

integer

Number to be divided.

modulus

integer

Number to be used for testing.



x
_mul(): Multiply a Number

The _mul() function returns the product of the first factor multiplied by the second factor. Recall that multiplication is commutative and therefore there is nothing implied by the order of the factors.

The _mul() function uses the following format:

_mul(multiplicand, multiplier)

multiplicand

number

Number to be operated upon.

multiplier

number

The multiplier for the function.



x
_div(): Divide a Number

The _div() function returns the quotient of the first factor divided by the second factor. This is a floating point number.

The _div() function uses the following format:

_div(dividend, divisor)

dividend

number

Number to be operated upon.

divisor

number

The divisor for the function. Must be != 0.



x
_iadd(): Add a list of terms, Integer

The _iadd() function returns the sum of the terms. There is nothing implied by the order of the terms. Any term can be an XPATH() function; if the XPATH() returns multiple results all are added into the sum. All values are assumed to be integers, and the result is an integer. The iadd() function is suitable for date manipulation, as the addition is computed with sufficient precision to maintain the field integrity. See _dateof(): Return the time stamp for a passed time for examples.

The _iadd() function uses the following format:

_iadd(term, term*)

term

number

Number to be added.



x
_isub(): Subtract, Integer

The _isub() function returns the difference with integer arithmetic. The isub() function is suitable for date manipulation, as the subtraction is computed with sufficient precision to maintain the field integrity. See _dateof(): Return the time stamp for a passed time for examples.

The _isub() function uses the following format:

_isub(minuend, subtrahend)

minuend

number

Number to be subtracted from.

subtrahend

number

Number to be subtracted from the minuend.



x
_imul(): Multiply a Number, Integer

The _imul() function returns the product of the first factor multiplied by the second factor. Recall that multiplication is commutative and therefore there is nothing implied by the order of the factors. The quotient is an integer, with the fractional part disregarded.

The _imul() function uses the following format:

_imul(multiplicand, multiplier)

multiplicand

number

Number to be operated upon.

multiplier

number

The multiplier for the function.



x
_idiv(): Divide a Number

The _idiv() function returns the quotient of the first factor divided by the second factor. The quotient is an integer, with the fractional part disregarded.

The _idiv() function uses the following format:

_idiv(dividend, divisor)

dividend

number

Number to be operated upon.

divisor

number

The divisor for the function. Must be != 0.



x
_int(): Cast to Integer

The _int() function casts a value to an integer. This is done by ignoring the fractional part, as is the standard case for computer languages. To avoid loss of information, the _round() performs a similar operation with half-adjust rounding.

The _int() function uses the following format:

_int(value)

value

number

Number to be cast.



x
_intmask(): Inserts a Number Into a Character Mask

The _intmask() function inserts a number into a character mask. It uses the following format:

_intmask(pattern,input)

pattern

string

Mask into which the number is inserted. All char acters but # appear as-is, but # characters (one set) are replaced by the value.

input

integer

Math value to be inserted. Must be present, if not, it will cause an error.



x
_max(): Maximum of a list of terms
_max(term, term*)

term

number

Number to be evaluated.

Returns the maximum value of the terms. There is nothing implied by the order of the terms. Any term can be an XPATH() function; if the XPATH() returns multiple results all are evaluated.



x
_min(): Minimum of a list of terms
_min(term, term*)

term

number

Number to be evaluated.

Returns the minimum value of the terms. There is nothing implied by the order of the terms. Any term can be an XPATH() function; if the XPATH() returns multiple results all are evaluated.



x
_random(): Generate a Random Number

The _random() function returns a pseudo-random integer between zero and the upper bound (with default 232-1). All possible values are produced with equal probability.

This function is especially useful as a seed for a cryptographic algorithm. It is also useful for simulating server response time distributions using the copy agent’s delay parameter. For example, to simulate a random execution time between 300 and 340 ms, specify a delay time of 300 +_random(40).

The _random() function uses the following format:

_random(upperbound)

upperbound

integer

Upper bounds



x
_floor(): Obtain the Floor of a Number

The _floor() function returns the largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer. Special cases include:

For example, the floor of -7.5 is -8. The floor of 7.5 is 7.

The _floor() function uses the following format:

_floor(number)

number

value

Number to be operated upon.



x
_ceil(): Obtain the Ceil of a Number

The _ceil() function returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer. Special cases include:

Note: The value of ceil(x) is exactly the value of -floor(-x).

For example, the ceil of -7.5 is -7. The ceil of 7.5 is 8.

The _ceil() function uses the following format:

_ceil(number)

number

value

Number to be operated upon.



x
_round(): Round a Number to an Integer

The _round() function returns the closest integer to the argument value. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type integer. In other words, the result is equal to the value of the following expression:

(int)Math.floor(a + 0.5f)

The _round() function uses the following format:

_round(number)

number

value

Number to be operated upon.


iWay Software