Math module

abs

procedure · 3 overloadsSource

The absolute value. For s8, s16, s32 and s64 it asserts on the most negative value, which has no positive counterpart. For float and float64 it clears the sign bit, so abs(-0.0) is +0.0, abs(-infinity) is infinity and a NaN keeps its payload. Vectors take the absolute value of each component.

ExampleOpen in playground ↗
assert(abs(-5) == 5 && abs(7) == 7);
assert(abs(-2.5) == 2.5);
assert(abs(xyz(-1, 2, -3)) == xyz(1, 2, 3));
abs :: (x: $T/ .[s64, s32, s16, s8]) -> T

Absolute value. Asserts on the most negative number, which has no positive twin.

Parameters

x: $T/ .[s64, s32, s16, s8]
the value.

Returns

T
abs :: (x: float64) -> float64

Absolute value.

Parameters

x: float64
the value.

Returns

float64
abs :: (x: float32) -> float32

Absolute value.

Parameters

x: float32
the value.

Returns

float32

See also