abs

Calculates the absolute value of a number.

  1. Unqual!T abs(T x)
    abs
    (
    T
    )
    (
    T x
    )
  2. Unqual!T abs(T x)

Parameters

T

Argument type.

x T

Argument.

Return Value

Type: Unqual!T

Absolute value of x.

Examples

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));
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));

Meta