Math Functions

Topics:

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 (iSM).

Note: By default, math operations are performed in floating point, which can generate problematic results when a value is provided below the radix (for example, 12 in 10.12). Decimal numbers when operated on by the iFL functions _ddiv() and _dmul(), while slightly slower, operate upon decimal digits as entered. This means that a decimal type is not more precise than a binary floating point or fixed point type in a general sense (for example, it cannot store 1/3 without loss of precision), but it is more accurate for numbers provided with a finite number of decimal digits, as is often the case for monetary calculations. Users are responsible for understanding the use to which numeric values are specified, and the scale and precision required for the final result.

_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.

_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.

_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.

_mul(): Multiply a Number

The _mul() function returns the product of the first factor multiplied by the second factor. Note that multiplication is commutative and therefore there is nothing implied by the order of the factors. The result is computed as a floating point value.

The _mul() function uses the following format:

_mul(multiplicand, multiplier)

multiplicand

number

Number to be operated upon.

multiplier

number

The multiplier for the function.

_div(): Divide a Number

The _div() function returns the quotient of the first factor divided by the second factor. The result is computed as a floating point value.

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.

_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.

_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 Timefor 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.

_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 _imul() function uses the following format:

_imul(multiplicand, multiplier)

multiplicand

number

Number to be operated upon.

multiplier

number

The multiplier for the function.

_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.

_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.

_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 characters 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.

_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.

_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.

_random(): Generate a Random Number

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

The _random() function uses the following format:

_random([upperbound] [,width])

upperbound

integer

Specified upper bounds to be used.

width

integer

The number of digits in the result. Leading zeros may be added.

This function is especially useful as a seed for a cryptographic algorithm. It is also useful for simulating server response time distributions using the Delay parameter of the Document Copy service (com.ibi.agents.XDCopyAgent).

The width parameter specifies the formatted width of the result. For example, to generate a random telephone number, you might configure the _random() function as follows:

212-555-_random(9999,4)

The following is a sample result that is generated:

212-555-1786

_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:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NAN (not a number) or an infinity or positive zero or negative zero, then the result is the same as the argument.

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.

_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:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NAN or an infinity or positive zero or negative zero, then the result is the same as the argument.
  • If the argument value is less than zero but greater than -1.0, then the result is negative zero.

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.

_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 ½, 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.