bottom

Arithmetic Functions

Arithmetic functions are intended to perform some basic calculation on generated values and parameters. Since GEDIS Studio expression's language is not typed, each parameter of a function is a string that will be parsed into a numerical value (mostly a floating number). The intended calculation is then performed by the function and the result is reverted back into a string.

For example, if you have a field with UID GEN-000 that generates a number and you want that a second field with UID GEN-001 contains twice of the value of GEN-000 then you can use the expression MULT(2,FIELD(GEN-000)) to generate the values of GEN-000.

Another usage could be to accumulate the successive values of the field with UID GEN-000 into a parameter named TOTAL. For example, if the GEN-000 generates the prices of each item for a shoping cart, the parameter TOTAL will contains the total amount of the cart. To do so, you can use the expression SET(TOTAL,SUM(GET(TOTAL,0),FIELD(GEN-000))).

The Functions

SUM(n1,n2,...) or ADD(n1,n2,...): sum of a sequence of numbers

This function takes a variable number of numerical parameters (at least one) and computes the sum of these parameters (n1 + n2 + ...)

Example: SUM(1,2.3,RANGE(1,10),SUM(2,WORD(2,0123456789))) evaluates into 1 + 2.3 + random number between 1 and 10 + ( 2 + a two-digit random number)

MULT(n1,n2,...): products of a sequence of numbers

This function computes the product of its operands : n1 x n2 ...

DIV(n1,n2): division

This function divides number n1 by n2. Note that n2 must be non-nul

Examples:

  • DIV(1,2) returns "0.5"
  • DIV(4,2) returns "2"
  • DIV(a,2) returns "0" ("a" is evaluated to 0)
  • DIV(2,0) raises an error, generation may stops depending on where the error occurs.

MOD(n1,n2) : remainder

This function returns the remainder of the integer division of n1 by n2. Note that n2 must be non-null.

Example:

  • MOD(5,2) returns "1" (5 = 2*2 + 1).

FLOOR(n) : nearest smaller integer

This function returns the integer immediatly below n (or equal to n).

Example:

  • FLOOR(1.9) returns "1"
  • FLOOR(1) returns "1"

CEIL(n) : nearest bigger integer

This function returns the integer immediatly above n (or equal to n).

Example:

  • CEIL(1.9) returns "2"
  • CEIL(2) returns "2"

PRECISION(val,n) : Trunc the decimal part

This function returns float number with a decimal part made of n digits. If the source value doesn't have enought digits, zeroes are used to complete up to n digits.

Examples:

  • PRECISION(2,2) returns "2.00"
  • PRECISION(3.3454,3) returns "3.345".

MIN(v1,v2,...,vn) : Minimum value of vi

This function returns the minimum of the vi. To compute the result each value is converted into a double.

Examples:

  • MIN(2,2) returns "2"
  • MIN(3.3,1,2) returns "1,200000"
  • MIN(23,Hello) returns "0" since "Hello" is converted into 0

MAX(v1,v2,...,vn) : Maximum value of vi

This function returns the maximum of the vi. To compute the result each value is converted into a double.

Examples:

  • MAX(2,2) returns "2"
  • MAX(3.3,1,2) returns "3,300000"
  • MIN(23,Hello) returns "23" since "Hello" is converted into 0

Add comment


Security code
Refresh