negs

Negate an integer.

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

Parameters

x cent

operand

overflow bool

set if x cannot be negated, is not affected otherwise

Return Value

Type: cent

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