Math module

length

procedure · 3 overloadsSource

The Euclidean length of a vector or quaternion. The sum of squares is scaled by the largest component first, so a vector of huge or tiny components does not overflow or underflow in the middle: length(xy(FLOAT32_MAX, FLOAT32_MAX)) is about 4.8e38, which does not fit a float, so it is infinity. Any NaN component gives NaN, and an infinite one infinity (unless there is a NaN as well).

ExampleOpen in playground ↗
assert(length(xy(3, 4)) == 5);
assert(length(xyzw(1, 1, 1, 1)) == 2);
assert(length(xyz(0, 0, 0)) == 0);
assert(isinf(length(xy(FLOAT32_INFINITY, 1))));
length :: (a: Vector2) -> float

The length of a. Computed in float64 and scaled so huge or tiny components don't overflow. A NaN component gives NaN.

Parameters

a: Vector2
the vector to measure.

Returns

float
length :: (a: Vector3) -> float

The length of a. Computed in float64 and scaled so huge or tiny components don't overflow. A NaN component gives NaN.

Parameters

a: Vector3
the vector to measure.

Returns

float
length :: (a: Vector4) -> float

The length of a. Computed in float64 and scaled so huge or tiny components don't overflow. A NaN component gives NaN.

Parameters

a: Vector4
the vector to measure.

Returns

float

See also