Math

Arithmetic on data values, with the same operations as signal Math. Numbers in, numbers out; lists are worked element by element.

  • Data
  • Since 0.2.0
  • math
  • add
  • multiply
  • divide
  • numbers
  • list
  • data

Open in TuneToys

Math as the Patch draws it, at default values: inlets on the left, outlets on the right.

Data Math does arithmetic on data values: single numbers, or every element of a list.

What it does#

Operation chooses the arithmetic, in the same order and with the same names as signal Math: Add, Subtract, Multiply, Divide, Modulo, Power, Minimum, Maximum, Average, Absolute difference, then the one-operand operations Negate, Absolute, Floor, Ceiling, Round, Square root and Sign.

Both inputs are read as numbers: true is 1, false is 0 and text such as " 42 " becomes 42. When B is not connected it is B when unconnected. If either input is a list, the operation runs on every element: a list and a number applies the number to each element, and two lists pair their elements up to the shorter length.

Results that have no number send no value (null) instead of infinity: dividing by 0, Modulo by 0, the square root of a negative number and text that does not read as a number. The inspector says which input caused it. Math runs whenever an input receives a value and sends one result.

When to use it#

Use it for arithmetic on values that do not need to run at audio or control rate: scale a setting, convert units, offset every note in a list or average two readings. For audio and control signals use signal Math.

Ports#

PortDirectionSignalLanes
aInputData (any)1
bInputData (any)1
valueOutputData (any)1

Parameters#

ParameterLabelRangeDefaultUnitScaleNotes
opOperation0 to 160linearOperation applied to a and b; operations after Absolute difference use a only. Choices: 0 Add, 1 Subtract, 2 Multiply, 3 Divide, 4 Modulo, 5 Power, 6 Minimum, 7 Maximum, 8 Average, 9 Absolute difference, 10 Negate, 11 Absolute, 12 Floor, 13 Ceiling, 14 Round, 15 Square root, 16 Sign.
b_defaultB when unconnected-1000000000 to 10000000000linearValue of b while its port is unconnected. Shown when op is 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9.

Operation (op)#

Which arithmetic to apply, a discrete choice shared with signal Math. Divide and Modulo by 0, and Square root of a negative number, send no value rather than 0.

B when unconnected (b_default)#

The number used for B when nothing is connected to B, from -1 000 000 000 to 1 000 000 000. Hidden for the one-operand operations.

Tips#

  • Feed a JSON list from Value and Add 12 to transpose every note by an octave.
  • Two lists of different lengths give a list as long as the shorter one.
  • Chain two Math nodes to offset and then scale, as in the help patch.

See also#

Value, Compare, List, Math (signal).

Help patches

Each help patch is an ordinary Toy that teaches one idea. The diagram shows the Patch; the preview shows its Frame. Open it in TuneToys to play and edit it.

1. Add and scale numbers

beginner Teaches: op, b_default

A number goes through two Math nodes: one you control, then a fixed scale by 10.

Patch: Oscillator audio output connected to Patch outputs audio input. Value value output connected to Math “first” a input. Math “first” value output connected to Math “scale” a input.
Connections as text
  • Oscillator audio output connected to Patch outputs audio input
  • Value value output connected to Math “first” a input
  • Math “first” value output connected to Math “scale” a input
  • Value sends 3. B is unconnected, so the first Math uses B when unconnected (4): Add gives 7.
  • The second Math multiplies by 10, so the end of the chain reads 70.
  • Divide by 0 gives no value (null) instead of infinity, and the inspector says why.
  • Data cables carry values, not sound. Select a data node to see its newest value in the inspector; the tone only keeps the Toy audible.
Frame preview: Add and scale numbersFrame “Add and scale numbers” with 2 elements: text heading, text hint.ADD AND SCALE NUMBERSData nodes are set in the inspector: select one on the Patch to change Operatio…
Frame preview (static). Controls show their default values.

Open in TuneToys

  • Value A literal source, the data domain's number box and message box.
  • Compare Compare two data values as numbers, text or lists and send true or false: ordering, equality, contains, starts or ends with, pattern match, empty, in list.
  • Math Arithmetic on any signal, lane by lane: add, multiply, divide, power and more on audio or control operands. The output runs at the rate of its fastest input.

Edit this page on GitHub

esc

↑ ↓ move↩ open⌘↩ new tabesc close