- All Implemented Interfaces:
- WarpScriptStackFunction
public class NumericalBinaryFunction
extends NamedWarpScriptFunction
implements WarpScriptStackFunction
Apply a double or long binary operator to two values.
If only the long operator is defined, all numbers are converted to long.
If only the double operator is defined, all numbers are converted to double.
If both long and double operators are defined, all numbers are converted to long until a Double or BigDecimal is found,
then they are all converted to double.
The operator can also be applied to a list of values and a single operand, on top.
The result is a copy of the list with values being the result of the operator applied on the initial value and the single operand.
If the function is given a list on top, its behavior depends on applyOnSingleList:
- if true the result is op(...op(op(op(v[0], v[1]), v[2]), v[3]), ... v[n])
- if false, the function expects a single value under the list and behave the same as described in the paragraph before, operands being switched.
Whether applyOnSingleList should be set to true of false depends on the commutativity of the operator:
- max, sum, multiplication, for instance, do have meaning for a single list. Moreover, being commutative,
the single operand can be put on top to apply the operator on a list and a single operand.
- copysign, power, nextafter, for instance, are not really useful when applied on a single list.
The exact same logic can be applied to a GTS, considering it as a list of values.