Skip to content

Math.Multiply

Name - Description Default Type
<input> Any valid integer(s), floating point number(s), or a sequence of such entities supported by this operation. IntInt2Int3Int4Int8Int16FloatFloat2Float3Float4Color[Any]
<output> The result of the operation, usually in the same type as the input value. IntInt2Int3Int4Int8Int16FloatFloat2Float3Float4Color[Any]
Operand The operand for this operation. 0 Int&IntInt2&Int2Int3&Int3Int4&Int4Int8&Int8Int16&Int16Float&FloatFloat2&Float2Float3&Float3Float4&Float4Color&Color[Any]&[Any]

Applies the binary operation on the input value and the operand and returns the result (or a sequence of results if the input and the operand are sequences).

Details

Multiplication is a binary operation, i.e., it needs two arguments to give a result.

The Math.Multiply shard takes in the Input and the parameter :Operand to produce the Output.

Both Input and :Operand can be an integer, a float, or a sequence of such entities (but both value types should match for a given operation). The Output is generally of the same type as the Input provided to the shard.

See also

Binary operations on sequences

Examples

1
2
3
4
5
6
7
;; Multiply integers
(int 5) ;; :Input
(Log) ;; prints input => 5
(Math.Multiply
 2) ;; :Operand
(Log) ;; prints input * operand => 10
(Assert.Is 10 true) ;; expect: (5 * 2) => 10
[info] [shards/Math/Multiply/1.edn] 5
[info] [shards/Math/Multiply/1.edn] 10

 

1
2
3
4
5
6
7
;; Multiply floats
(float 5.3) ;; :Input
(Log) ;; prints input => 5.3
(Math.Multiply
 2.1) ;; :Operand
 (Log) ;; prints input * operand => 11.13
(Assert.Is 11.13 true) ;; expect: (5.3 * 2.1) => 11.13
[info] [shards/Math/Multiply/2.edn] 5.3
[info] [shards/Math/Multiply/2.edn] 11.13

 

1
2
3
4
5
6
7
8
;; Multiply equal-sized sequences
[4 5.1 6.4] ;; :Input
(Log) ;; prints input => [4 5.1 6.4]
(Math.Multiply
 [3 4.0 2.2]) ;; :Operand
;; input seq elements compute with corresponding operand seq elements
(Log) ;; prints input * operand => [12 20.4 14.08]
(Assert.IsAlmost [12 20.4 14.08]) ;; expect: [(4 * 3) (5.1 * 4.0) (6.4 * 2.2)] => [12 20.4 14.08]
[info] [shards/Math/Multiply/3.edn] [4 5.1 6.4]
[info] [shards/Math/Multiply/3.edn] [12 20.4 14.08]

 

1
2
3
4
5
6
7
8
9
;; Multiply unequal-sized sequences (input size < operand size)
[4.0] ;; :Input
(Log) ;; prints input => [4.0]
(Math.Multiply
 [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 => [12.0]
(Assert.Is [12.0] true) ;; expect: [(4.0 * 3.0) ... ...] => [12.0]
[info] [shards/Math/Multiply/4.edn] [4]
[info] [shards/Math/Multiply/4.edn] [12]

 

1
2
3
4
5
6
7
8
9
;; Multiply unequal-sized sequences (input size > operand size)
[4 2 1 5 8] ;; :Input
(Log) ;; prints input => [4 2 1 5 8]
(Math.Multiply
 [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 => [24 8 6 20 48]
(Assert.Is [24 8 6 20 48] true) ;; expect: [(4 * 6) (2 * 4) (1 * 6) (5 * 4) (8 * 6)] => [24 8 6 20 48]
[info] [shards/Math/Multiply/5.edn] [4 2 1 5 8]
[info] [shards/Math/Multiply/5.edn] [24 8 6 20 48]