subtract

x - y

subtract(x, y)

Try it yourself:

See also:
add

subtract(): calculate a difference

subtract(a, b) returns a minus b. It works with ordinary numbers and, where shapes and units are compatible, with matrices and quantities.

Examples and order

subtract(10, 3) is 7, while reversing the inputs gives −7. This order matters: subtraction is not commutative.

Related operations

Use add() for accumulation, unaryMinus() to negate a value, and abs() for an unsigned difference. compare() answers ordering directly; multiply() supports scaling.

Caveat

Match units and matrix dimensions before subtracting. Close floating-point results may need a tolerance rather than exact zero testing.

All functions