Function abs
Calculates the absolute value of a number.
Unqual!T abs(T)
(
T x
)
if (isIntegral!T);
Unqual!T abs(T)
(
T x
)
if (isFloatingPoint!T);
Parameters
Name | Description |
---|---|
T | Argument type. |
x | Argument. |
Returns
Absolute value of x.
Example
int i = -1;
assert(i .abs == 1);
static assert(is(typeof(i .abs) == int));
uint u = 1;
assert(u .abs == 1);
static assert(is(typeof(u .abs) == uint));
Example
float f = -1.64;
assert(f .abs == 1.64F);
static assert(is(typeof(f .abs) == float));
double d = -1.64;
assert(d .abs == 1.64);
static assert(is(typeof(d .abs) == double));
real r = -1.64;
assert(r .abs == 1.64L);
static assert(is(typeof(r .abs) == real));