---
id: math-abs
name: Math.abs
category: math
kind: namespace-method
tokens: Math.abs
sig: Math.abs(x) -> int
tip: The magnitude of a value, dropping its sign.
order: 2
ns: Math
member: abs
---
Returns the absolute value of x — its distance from zero, always non-negative. It preserves the type of its argument, so Math.abs of a fixed stays fixed. Reach for it when you care about how far apart two things are regardless of direction, such as the gap between a target and current position, or the speed behind a signed velocity. The bare form abs(x) is kept as a convenience alias.
Parameters:
- `x` — the value whose magnitude you want
```ludic
program ChaseDistance {
let target: int = 40
let here: int = 12
handler Report phase Update {
let gap = Math.abs(target - here) # 28, regardless of which is larger
}
}
```