# llVecMag

*LSL function*

```lsl
float float llVecMag(vector vec);
```

- `vector vec`: Vector to evaluate.

- Returns: `float`
- Energy: 10

Returns a [float](https://wiki.secondlife.com/wiki/float) that is the magnitude of the vector (the undirected non-negative distance from **vec** to `<0.0, 0.0, 0.0>`).

```lsl title="How to use" frame="terminal"
float result = llVecMag(ZERO_VECTOR);
```

## Examples

<details open>
<summary>Example 1</summary>

```lsl
default {
    state_entry()
    {
        vector input = <1.0,2.0,3.0>;
        llSay(0,"The magnitude of "+(string)input+" is "+(string)llVecMag(input) + ".");
    }
}
```

</details>

## Notes

- Mathematically the formula for vector magnitude is
- `llSqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z)`
- Knowing this, there are ways to circumvent `llVecMag` for more efficient code.
- **vec**\***vec** &lt; 16.0 is over twice as fast as `llVecMag(vec)` &lt; 4.0.
- **vec**\***vec** &lt; (dist\*dist) is about twice as fast as `llVecMag(vec)` &lt; dist.
- This can work in many other ways, too, with other comparisons.

## See also

### Functions

- [llVecNorm](/functions/llVecNorm/) — The vector normal
- [llVecDist](/functions/llVecDist/) — The distance between two vectors

---

*Source: [LlVecMag](https://wiki.secondlife.com/wiki/LlVecMag) on the Second Life Wiki. Content from the Second Life Wiki article LlVecMag (revision 1194326, 2015-01-22), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llVecMag/
