Qu

abs

Builtin index · Core maths

result = abs(x)

Input: x · Output: result

What it is

Absolute value on a real scalar/Vec/Mat; magnitude (sqrt(re^2 + im^2)) on a Complex scalar, CVec, or CMat. x is the value(s) to measure.

Overloads

x can be number, Vec, or Complex.

3 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = abs(x)
x numbernot documented yet
result Num
Returns a Num, the standard real absolute value.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

print(abs(-5))   # 5

output
5
CodeInputOutputDescription
result = abs(x)
x Vecnot documented yet
result Vec
Returns a Vec of the same length, abs applied elementwise.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

print(abs([-2, -0.5, 0.5, 2]))   # [2, 0.5, 0.5, 2]

output
[2, 0.5, 0.5, 2]
CodeInputOutputDescription
result = abs(x)
x Complexnot documented yet
result Num
Returns a real Num — the magnitude sqrt(re^2 + im^2), not either component alone — the case that most often surprises newcomers.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

print(abs(3 + 4j))   # 5 — magnitude, not the real part

output
5

How it works

abs/angle/real/imag/conj are complex-aware.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.