Obtains the result of adding multiple values together.
The add tag can sum all the values in a list, or sum a list of values against a single value, or sum two lists of values (such as two equal-sized vectors) pairwise against each other.
<add 1,1>
produces 2
.
<add 1 with=1>
produces 2
.
<add 1,10,-2 with=2>
produces 3,12,0
.
<add 2 with=1,10>
produces 3,12
.
<add 2,1 with=100,200>
produces 102,201
.
<add 2,1 with=1,10,20>
produces invalid
.
The tag's primary field takes a list of one or more values. When the (optional) with field is not used, the result produced by the tag is the sum of all values in the primary field.
When the tag is complete, it produces out a value for one or more results of addition. The tag's lifetime then ends.
Depending on usage, the add
tag can be used to perform simple addition (summing two or more values together), distributive addition (adding one value to a set of values), or vector addition (adding two sets of values).
The mode of operation depends on whether the with
field is specified, and whether one value or multiple values are present in the primary and with
fields.
The following describes this behaviour in detail. But simply refer to the sample usage examples above for examples.
with
field is not used (simplest case), all values in the primary field are summed together from left to right.
null
are treated similar to zero when added to numbers.inf
always produce a resulting value of inf
.true
, false
or invalid
are invalid in addition and produce a result of invalid.with
field is specified with exactly one value element,
the value in the with
field is added to the first element in the primary field
to produce the first result, then the with
field value is added to each subsequent element
in the primary field to produce each subsequent result in the same way.
with
field is specified with multiple value elements,
the first value in the with
field is added to the primary field value
to produce the first value in the result, then each subsequent value in the with
field is added to
the primary field value to produce each subsequent result in the same way.
with
fields contain multiple values, and both fields contain an equal number of elements,
the two fields are added according to vector addition: the first element of the with
field is added to the first element of the primary field to produce the first value in the result,
then the second element in the primary field is paired with the second element in the with
field, and so on.
with
fields contain multiple values but the number of elements
in each field is different, the tag produces invalid
.
The following code, when output to an ioL console, presents the user with a simple on-screen calculator.
<a:input 0> + <b:input 0> = <result:box 0></p> <button {Evaluate} onClick= <result|add <num a>, <num b>> >The following non-interactive illustration shows what would be presented to the user in the console. When run in a real console, the user would be able to change the two initial values of 0 to any number and click the "Evaluate" button to add them together and see the result.