ecma_bigint_create_from_digits (const uint64_t *digits_p, /**< BigInt digits */
                                uint32_t size, /**< number of BigInt digits */
                                bool sign) /**< sign bit, true if the result should be negative */
{
  const uint64_t *digits_end_p = digits_p + size;

  while (digits_end_p > digits_p && digits_end_p[-1] == 0)
  {
    digits_end_p--;
  }

  if (digits_p == digits_end_p)
  {
    return ECMA_BIGINT_ZERO;
  }

  size = (uint32_t) (digits_end_p - digits_p);

  if (size < ECMA_BIGINT_MAX_SIZE)
  {
    size *= (uint32_t) sizeof (uint64_t);
  }

  if ((digits_end_p[-1] >> (8 * sizeof (ecma_bigint_digit_t))) == 0)
  {
    size -= (uint32_t) sizeof (ecma_bigint_digit_t);
  }

  ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size);

  if (JERRY_UNLIKELY (result_value_p == NULL))
  {
    return ecma_bigint_raise_memory_error ();
  }

  if (sign)
  {
    result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN;
  }

  ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0);

  while (digits_p < digits_end_p)
  {
    uint64_t digit = *digits_p++;

    result_p[0] = (ecma_bigint_digit_t) digit;
    result_p[1] = (ecma_bigint_digit_t) (digit >> (8 * sizeof (ecma_bigint_digit_t)));
    result_p+= 2;
  }

  return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT);
} /* ecma_bigint_create_from_digits */
ecma_bigint_create_from_digits (const uint64_t *digits_p,  
                                uint32_t size,  
                                bool sign)  
{
  const uint64_t *digits_end_p = digits_p + size;

  while (digits_end_p > digits_p && digits_end_p[-1] == 0)
  {
    digits_end_p--;
  }

  if (digits_p == digits_end_p)
  {
    return ECMA_BIGINT_ZERO;
  }

  size = (uint32_t) (digits_end_p - digits_p);

  if (size < ECMA_BIGINT_MAX_SIZE)
  {
    size *= (uint32_t) sizeof (uint64_t);
  }

  if ((digits_end_p[-1] >> (8 * sizeof (ecma_bigint_digit_t))) == 0)
  {
    size -= (uint32_t) sizeof (ecma_bigint_digit_t);
  }

  ecma_extended_primitive_t *result_value_p = ecma_bigint_create (size);

  if (JERRY_UNLIKELY (result_value_p == NULL))
  {
    return ecma_bigint_raise_memory_error ();
  }

  if (sign)
  {
    result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN;
  }

  ecma_bigint_digit_t *result_p = ECMA_BIGINT_GET_DIGITS (result_value_p, 0);

  while (digits_p < digits_end_p)
  {
    uint64_t digit = *digits_p++;

    result_p[0] = (ecma_bigint_digit_t) digit;
    result_p[1] = (ecma_bigint_digit_t) (digit >> (8 * sizeof (ecma_bigint_digit_t)));
    result_p+= 2;
  }

  return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT);
}  