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.

Note

Such sequence operations are useful in transforming and translating 2D/3D grid values (a frequent requirement in graphics rendering). This is done by passing the transform inputs as an Input sequence (to be applied to every row/line for a 2D grid or to every 2D-matrix/plane for a 3D grid) of the 2D matrix and the Operand sequence as the set of 2D/3D coordinates (represented linearly) that is to be transformed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
; Add integers
5 | Log ; prints input => 5
  | Math.Add(2) | Log ; prints input + operand => 7
  | Assert.Is(7 Break: true) ; expect: (5 + 2) => 7

; Add floats
5.3 | Log ; prints input => 5.3
    | Math.Add(2.1) | Log ; prints input + operand => 7.4
    | Assert.Is(7.4 Break: true) ; expect: (5.3 + 2.1) => 7.4

; Add equal-sized sequences
[4 5.1 6.4] | Log ; prints input => [4 5.1 6.4]
            | Math.Add([3 4.0 2.2]) ; 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] Break: true) ; expect: [(4 + 3) (5.1 + 4.0) (6.4 + 2.2)] => [7 9.1 8.6]

; Add unequal-sized sequences (input size < operand size)
[4.0] | Log ; prints input => [4.0]
      | Math.Add([3.0 4.0 2.2]) ; input seq elements compute with corresponding operand seq elements
      | Log ; prints input + operand => [7.0]
      | Assert.Is([7.0] Break: true) ; expect: [(4.0 + 3.0) ... ... ] => [7.0]

; Add unequal-sized sequences (input size > operand size)
[4 2 1 5 8] | Log ; prints input => [4 2 1 5 8]
            | Math.Add([6 4]) ; input seq elements compute with corresponding operand seq elements
            | Log ; prints input + operand => [10 6 7 9 14]
            | Assert.Is([10 6 7 9 14] Break: true) ; expect: [(4 + 6) (2 + 4) (1 + 6) (5 + 4) (8 + 6)] => [10 6 7 9 14]

[info] [sample-wire] 5
[info] [sample-wire] 7
[info] [sample-wire] 5.3
[info] [sample-wire] 7.4
[info] [sample-wire] [4 5.1 6.4]
[info] [sample-wire] [7 9.1 8.6]
[info] [sample-wire] [4]
[info] [sample-wire] [7]
[info] [sample-wire] [4 2 1 5 8]
[info] [sample-wire] [10 6 7 9 14]
 

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

[info] [sample-wire] 5.3
[info] [sample-wire] 7.4
 

1
2
3
4
5
; Add equal-sized sequences
[4 5.1 6.4] | Log ; prints input => [4 5.1 6.4]
            | Math.Add([3 4.0 2.2]) ; 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] Break: true) ; expect: [(4 + 3) (5.1 + 4.0) (6.4 + 2.2)] => [7 9.1 8.6]

[info] [sample-wire] [4 5.1 6.4]
[info] [sample-wire] [7 9.1 8.6]
 

1
2
3
4
5
; Add unequal-sized sequences (input size < operand size)
[4.0] | Log ; prints input => [4.0]
      | Math.Add([3.0 4.0 2.2]) ; input seq elements compute with corresponding operand seq elements
      | Log ; prints input + operand => [7.0]
      | Assert.Is([7.0] Break: true) ; expect: [(4.0 + 3.0) ... ... ] => [7.0]

[info] [sample-wire] [4]
[info] [sample-wire] [7]
 

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

[info] [sample-wire] [4 2 1 5 8]
[info] [sample-wire] [10 6 7 9 14]