API Reference › Math › Math.sqrt
method

Math.sqrt

Math.sqrt(x) -> fixed

Returns the non-negative square root of x, computed in Q16.16 by a deterministic integer algorithm — so it is bit-identical on every platform, the same guarantee the rest of the runtime gives. Negative inputs return 0. Use it for lengths and distances; when you have two legs of a right triangle reach for Math.hypot, and when you only need to compare magnitudes prefer the cheaper squared distance Math.dist2.

Example

program Demo {
  handler Step phase Update {
    let speed = Math.sqrt(vx * vx + vy * vy)
  }
}
← All symbols