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

#include "_mpint.h"

/* mp[digit] = value */ 

mp_digit_t mp_digitAtPut(mp_t *mp, mp_size_t index, mp_digit_t value)
{									assert(_mp_ok(mp));
  if (index >= mp->width) {					
    if (!value) return value;
    mp->bits= _mp_realloc(mp->bits, index + 1);
    while (mp->width <= index) mp->bits[mp->width++]= 0;
  }
  mp->bits[index]= value;
  if (value == 0 && index == mp->width - 1) mp_normalise(mp);
  return value;
}

