ludic/docs/language/math/math-abs.md

906 B

id name category kind tokens sig tip order ns member
math-abs Math.abs math namespace-method Math.abs Math.abs(x) -> int The magnitude of a value, dropping its sign. 2 Math 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
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
  }
}