calculateMathAddOnBlock

calculateContainerBlock

This Block accepts source VC as input and generates output as new VC document.

Input Parameters:

inputSchema : source VC schema

inputFields : array of variables which would be taken from the source VC.

VariableDefinitionExample of Input

name

Refer to the specified field value

field0

title

Title of the operation

Summary

value

Variable to store the value of the field

E0

"inputFields": [
                    {
                      "name": "field0",
                      "title": "Summary",
                      "value": "E0"
                    },
                ]

New variable "E0" would be created with a value set to one from the "field0" in the VC document.

"title" is not a mandatory parameter. The value is set automatically as per the user convenience.

Output Parameters

outputSchema : output VC schema

outputFields : array of variables of output VC, which will be the field with the values from the variables.

VariableDefinitionExample of Input

name

Variable that refers to specified field

field0

title

Title of the operation

Summary

value

Points to the value of specified variable

E1

outputFields: [
                    {
                      "name": "field0",
                      "title": "Summary",
                      "value": "E1"
                    }
                ]

The output variable "field0" will contain the value from the variable "E1".

"title" is not a mandatory parameter. The value is set automatically as per the user convenience.

calculateMathAddonBlock

This Block performs mathematical calculations sequentially.

equations : array of formulas.

"equations": [
                    {
                      "variable": "E1",
                      "formula": "E0*10"
                    }
                ]

When above code is executed, a new variable, "E1" will be created which would contain the value of the calculation "E0*10".

Note: All the expressions available in Math.js are supported by calculateMathAddOnBlock.

OperatorNameSyntaxAssociativityExampleResult

(, )

Grouping

(x)

None

2 * (3 + 4)

14

[, ]

Matrix, Index

[...]

None

[[1,2],[3,4]]

[[1,2],[3,4]]

{, }

Object

{...}

None

{a: 1, b: 2}

{a: 1, b: 2}

,

Parameter separator

x, y

Left to right

max(2, 1, 5)

5

.

Property accessor

obj.prop

Left to right

obj={a: 12}; obj.a

12

;

Statement separator

x; y

Left to right

a=2; b=3; a*b

[6]

;

Row separator

[x; y]

Left to right

[1,2;3,4]

[[1,2],[3,4]]

Statement separator

x \n y

Left to right

a=2 \n b=3 \n a*b

[2,3,6]

+

Add

x + y

Left to right

4 + 5

9

+

Unary plus

+y

Right to left

+4

4

-

Subtract

x - y

Left to right

7 - 3

4

-

Unary minus

-y

Right to left

-4

-4

*

Multiply

x * y

Left to right

2 * 3

6

.*

Element-wise multiply

x .* y

Left to right

[1,2,3] .* [1,2,3]

[1,4,9]

/

Divide

x / y

Left to right

6 / 2

3

./

Element-wise divide

x ./ y

Left to right

[9,6,4] ./ [3,2,2]

[3,3,2]

%

Percentage

x%

None

8%

0.08

%

Addition with Percentage

x + y%

Left to right

100 + 3%

103

%

Subtraction with Percentage

x - y%

Left to right

100 - 3%

97

% mod

Modulus

x % y

Left to right

8 % 3

2

^

Power

x ^ y

Right to left

2 ^ 3

8

.^

Element-wise power

x .^ y

Right to left

[2,3] .^ [3,3]

[8,27]

'

Transpose

y'

Left to right

[[1,2],[3,4]]'

[[1,3],[2,4]]

!

Factorial

y!

Left to right

5!

120

&

Bitwise and

x & y

Left to right

5 & 3

1

~

Bitwise not

~x

Right to left

~2

-3

|

Bitwise or

x | y

Left to right

5 | 3

7

^|

Bitwise xor

x ^| y

Left to right

5 ^| 2

7

<<

Left shift

x << y

Left to right

4 << 1

8

>>

Right arithmetic shift

x >> y

Left to right

8 >> 1

4

>>>

Right logical shift

x >>> y

Left to right

-8 >>> 1

2147483644

and

Logical and

x and y

Left to right

true and false

false

not

Logical not

not y

Right to left

not true

false

or

Logical or

x or y

Left to right

true or false

true

xor

Logical xor

x xor y

Left to right

true xor true

false

=

Assignment

x = y

Right to left

a = 5

5

? :

Conditional expression

x ? y : z

Right to left

15 > 100 ? 1 : -1

-1

:

Range

x : y

Right to left

1:4

[1,2,3,4]

to, in

Unit conversion

x to y

Left to right

2 inch to cm

5.08 cm

==

Equal

x == y

Left to right

2 == 4 - 2

true

!=

Unequal

x != y

Left to right

2 != 3

true

<

Smaller

x < y

Left to right

2 < 3

true

>

Larger

x > y

Left to right

2 > 3

false

<=

Smallereq

x <= y

Left to right

4 <= 3

false

>=

Largereq

x >= y

Left to right

2 + 4 >= 6

true

Example

In the input VC is { "field0" : 5 }

		calculateContainerBlock:
			"inputFields": [
				{
				  "name": "field0",
				  "value": "E0"
				}
			]
			"outputFields": [
				{
				  "name": "field0",
				  "value": "E1"
				}
			]
		calculateMathAddon
			"equations": [
				{
				  "variable": "E1",
				  "formula": "E0*10"
				}
			]

Then

  1. input VC variable "E0" will contain 5 (eg. "E0" = 5)

  2. When executed a new variable "E1" will be created with the value "E1" = E0*10 = 5 * 10 = 50

  3. In the output VC there will be "E1" variable

  4. The result will be VC = { "field0" : 50 }

Last updated