The OpenD Programming Language

abs

Calculates the absolute value of a number.

@nogc nothrow pure
abs
(
Num
)
(
Num x
)
if (
isIntegral!Num ||
(
is(typeof(Num.init >= 0)) &&
is(typeof(-Num.init))
)
)

Parameters

Num

(template parameter) type of number

x Num

real number value

Return Value

Type: auto

The absolute value of the number. If floating-point or integral, the return type will be the same as the input.

Limitations: When x is a signed integral equal to Num.min the value of x will be returned instead. Note for 2's complement; -Num.min (= Num.max + 1) is not representable due to overflow.

Examples

import std.math.traits : isIdentical, isNaN;

assert(isIdentical(abs(-0.0L), 0.0L));
assert(isNaN(abs(real.nan)));
assert(abs(-real.infinity) == real.infinity);
assert(abs(-56) == 56);
assert(abs(2321312L)  == 2321312L);
assert(abs(23u) == 23u);

Meta