negs

Negate an integer.

  1. int negs(int x, bool overflow)
    nothrow @safe @nogc pure pragma(inline, true)
    int
    negs
    ()
    (
    int x
    ,
    ref bool overflow
    )
  2. long negs(long x, bool overflow)
  3. cent negs(cent x, bool overflow)

Parameters

x int

operand

overflow bool

set if x cannot be negated, is not affected otherwise

Return Value

Type: int

the negation of x

Examples

bool overflow;
assert(negs(0, overflow) == -0);
assert(!overflow);

assert(negs(1234, overflow) == -1234);
assert(!overflow);

assert(negs(-5678, overflow) == 5678);
assert(!overflow);

assert(negs(int.min, overflow) == -int.min);
assert(overflow);

assert(negs(0, overflow) == -0);
assert(overflow);                   // sticky
bool overflow;
assert(negs(0L, overflow) == -0);
assert(!overflow);

assert(negs(1234L, overflow) == -1234);
assert(!overflow);

assert(negs(-5678L, overflow) == 5678);
assert(!overflow);

assert(negs(long.min, overflow) == -long.min);
assert(overflow);

assert(negs(0L, overflow) == -0);
assert(overflow);                   // sticky

Meta