Skip to content

Math.Add

Name Mandatory Description Default Type
⬅️ Input The value or the sequence of values to add the value specified in the Operand parameter to. IntInt2Int3Int4Int8Int16FloatFloat2Float3Float4Color[Any]
Output ➡️ This shard outputs the result of the addition. IntInt2Int3Int4Int8Int16FloatFloat2Float3Float4Color[Any]
Operand No The value or sequence of values to add to the input. 0 IntVar(Int)Int2Var(Int2)Int3Var(Int3)Int4Var(Int4)Int8Var(Int8)Int16Var(Int16)FloatVar(Float)Float2Var(Float2)Float3Var(Float3)Float4Var(Float4)ColorVar(Color)[Any]Var([Any])

This shard adds the input value to the value provided in the Operand parameter.

Details

This shard can take an integer or a sequence of integers as input. However, depending on the type of input, the appropriate Operand needs to be provided:

For non-sequence inputs: The Operand must match the input type exactly (e.g., Int2 with Int2, Color with Color).

For sequence inputs: The Operand can be either: - A matching non-sequence type (e.g., sequence of Int2 with a single Int2 Operand). Each element of the input sequence is operated on by the Operand. - Another sequence of elements with the same types. Each element of the Operand sequence is applied to the corresponding element of the input sequence. If the input sequence is longer, the Operand sequence will loop over till all elements of the input sequence are operated on. If the Operand sequence is longer, the extra elements of the Operand sequence are ignored.

Examples

1
2
3
4
5
6
7
8
; Add unequal-sized sequences (input size < operand size)
[4.0] ; Input
Log ; prints input => [4.0]
Math.Add([3.0 4.0 2.2]) ; Operand
; input seq elements compute with corresponding operand seq elements
; since input size < operand size, remaining operand seq elements ignored
Log ; prints input + operand => [7.0]
Assert.Is([7.0] true)


 

1
2
3
4
5
6
7
8
; Add unequal-sized sequences (input size > operand size)
[4 2 1 5 8] ; Input
Log ; prints input => [4 2 1 5 8]
Math.Add([6 4]) ; Operand
; input seq elements compute with corresponding operand seq elements
; for (input size > operand size): remaining input seq elements continually loop over operand seq elements
Log ; prints input + operand => [10 6 7 9 14]
Assert.Is([10 6 7 9 14] true)


 

1
2
3
4
5
6
; Add floats
5.3 ; Input
Log ; prints input => 5.3
Math.Add(2.1) ; Operand
Log ; prints input + operand => 7.4
Assert.Is(7.4 true) ; expect: (5.3 + 2.1) => 7.4


 

1
2
3
4
5
6
7
; Add equal-sized sequences
[4 5.1 6.4] ; Input
Log ; prints input => [4 5.1 6.4]
Math.Add([3 4.0 2.2]) ; Operand
; input seq elements compute with corresponding operand seq elements
Log ; prints input + operand => [7 9.1 8.6]
Assert.IsAlmost([7 9.1 8.6] true)


 

1
2
3
4
5
6
; Add integers
5
Log ; prints input => 5
Math.Add(2) ; Operand
Log ; prints input + operand => 7
Assert.Is(7 true) ; expect: (5 + 2) => 7