This part allows application users to enter a mathematical expression for calculation. In contrast to the calculation part, the calculation-1-1 part support large numbers (digits > 16).
The calculation part is used by entering the requested mathematical expression in the part. The system stores the calculated result in the defined data object.
|Dataobject||This is the data object in which the system will store the result of the calculation.||Data Object||Mandatory|
|This is the number of decimals the system should display in the result.||Integer||Mandatory|
|Round||This specifies whether the system should round the result to the number of decimals specified above. If the end user selects "No" the system will truncate the result to the number of decimals specified above.||Yes | No||Optional|
|Calculation||This is the mathematical expression the system should use to perform the calculation.||Text||Mandatory|
Mathematical expressions can consist of the following elements:
- numbers (whole and floating using ‘.’ as decimal point)
- standard operators, such as +, -, /, *
- parentheses to control the precedence of the operators
- mathematical functions: abs, ceil, floor, avg, min, max, exp, log, log10, log2, sin, cos, tan, asin, acos, atan, pow, deg, rad, sqrt, mod, PI, comp
With v7.4, LogicNets added a new function called 'comp'. The syntax for comp(<number 1>, <number 2>), returns the following:
1 : when number 1 is larger than number 2
0 : when number 1 and number 2 are equal
-1 : when number 1 is smaller than number 2
The min- and max- functions take a comma separated list of numbers to return the largest, smallest out of the list. E.g. min(2, -7, 3) ==> -7
The pow-function takes two arguments e.g. pow(a, b) to perform ab
PI is the constant π and can for example be used in the gonometric functions like: cos(PI/4) ==> 0.70710678118655
The mod-function takes two arguments e.g. mod(3, 2) ==> 1
Using Data Variables and Default Values
Mathematical expressions can also include interpolated text , such as $(my_var)
In support of interpolation, a default value can be defined in case of the variable being undefined. This should be used in most situations to prevent a calculation error and warning message during runtime. Default values are specified inside the () and after a colon as follows.
$(my_var:0) gives a result of 0 if my_var is NULL
$(my_var:1) gives a result of 1 if my_var is NULL
The inclusion of variables for default values is also possible as follows
$(my_var: $(my_default)) gives a result of $(my_default) if my_var is NULL
Sample Mathematical Expressions (decimals = 2, round = yes)
(400000000000000000000000000 - 8) * 3 ==> 1199999999999999999999999976.00
(400000000000000000000000000 - 8.2562321) ==> 399999999999999999999999991.74
For an example form in which you can enter a mathematical expression the system will pass to the calculation part, download and import the following sample project in your workspace.