node math - blossommerz/locus-hub GitHub Wiki
< Previous: Bounding Box | Next: Vector Math >
Combine two numbers with an arithmetic operation, chosen from an inline pulldown; guards divide-by-zero and non-finite results. List-aware.
Category: Data | Add menu: Data > Math
- A (number, editable): the first operand.
- B (number, editable): the second operand.
Note
Any operand that stands for a length is in millimeters, like every other number on the node side. To read a result out in another unit, multiply by one of the conversion constants: value x mmtoin gives inches, area x sqmmtosqin gives square inches. See Constants & unit conversions.
- Result (number): A and B combined by the chosen operation.
Pick one from the pulldown on the node body. Add, Subtract, Multiply, Divide, Modulo, Power, Min and Max use both operands. Round, Floor, Ceiling, Square Root, Sine, Cosine and Absolute Value read A and ignore B, so they fit the same two-input node with no socket changes.
-
Add (
+), Subtract (-), Multiply (x), Divide (/): the four you would expect. Divide guards against a zero or near-zero divisor, giving 0 rather than blowing up to a huge value. -
Modulo (
%): the remainder of A divided by B, always wrapping positive unlike the raw%of most languages, so it is safe for wrapping an index or a negative offset back into range. A value just below 0 comes out just below B, not negative. A zero or near-zero B gives 0, the same guard Divide has. -
Power (
^): A raised to B. A negative A with a fractional B has no real answer, so that case gives 0. - Round, Floor, Ceiling: round A to a whole number, to nearest, down, or up.
- Min, Max: the smaller or larger of A and B.
-
Square Root: the square root of A. This is the same value as
A ^ 0.5, which is how the Phyllotaxis recipe grew its radius before there was a dedicated operation; either works. A negative A has no real square root, so that gives 0. -
Absolute Value (
abs): the size of A without its sign, so -4 and 4 both come out as 4. Useful when a distance or an offset has come out the wrong way round and you only care how far, not which way. - Sine, Cosine: the sine or cosine of A, with A in degrees, matching every other angle field in the interface.
A and B don't have to be single numbers. Feed a list into either and Math maps the operation over it: a list against a scalar broadcasts (the scalar applies to every element), and two lists pair index-for-index (to the shorter one). That's what turns a Series of indices into a whole list of angles or radii in one node. See Lists & collections.
< Previous: Bounding Box | Next: Vector Math >
