/* Copyright (c) 2009 Ian Piumarta
 * All rights reserved.
 * See the file COPYING for details.
 */

#include "_mpint.h"

/* r = -r */

mp_t *mp_neg(mp_t *r)
{
  if (mp_zerop(r)) return r;
  size_t w= r->width, i= 0;
  mp_digit_t c= 1;
  while (i < w) {
    mp_digit2_t s= (mp_digit2_t)0 + (mp_digit2_t)~_mp_digitAt(r, i) + c;
    _mp_digitAtPut(r, i++, s);
    c= (s >> MP_BITS) & 1;
  }
  return r;
}

