ecma_bigint_div_mod (ecma_value_t left_value, /**< left BigInt value */
                     ecma_value_t right_value, /**< right BigInt value */
                     bool is_mod) /**< true if return with remainder */
{
  JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value));

  if (right_value == ECMA_BIGINT_ZERO)
  {
    return ecma_raise_range_error (ECMA_ERR_MSG ("BigInt division by zero"));
  }

  if (left_value == ECMA_BIGINT_ZERO)
  {
    return left_value;
  }

  ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value);
  ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value);

  int compare_result = ecma_big_uint_compare (left_p, right_p);
  ecma_extended_primitive_t *result_p;

  if (compare_result < 0)
  {
    if (!is_mod)
    {
      return ECMA_BIGINT_ZERO;
    }

    ecma_ref_extended_primitive (left_p);
    return left_value;
  }
  else if (compare_result == 0)
  {
    if (is_mod)
    {
      return ECMA_BIGINT_ZERO;
    }

    result_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t));

    if (result_p != NULL)
    {
      *ECMA_BIGINT_GET_DIGITS (result_p, 0) = 1;
    }
  }
  else
  {
    result_p = ecma_big_uint_div_mod (left_p, right_p, is_mod);

    if (result_p == ECMA_BIGINT_POINTER_TO_ZERO)
    {
      return ECMA_BIGINT_ZERO;
    }
  }

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

  if (is_mod)
  {
    result_p->u.bigint_sign_and_size |= left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN;
  }
  else
  {
    uint32_t sign = (left_p->u.bigint_sign_and_size ^ right_p->u.bigint_sign_and_size) & ECMA_BIGINT_SIGN;
    result_p->u.bigint_sign_and_size |= sign;
  }

  return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT);
} /* ecma_bigint_div_mod */
ecma_bigint_div_mod (ecma_value_t left_value,  
                     ecma_value_t right_value,  
                     bool is_mod)  
{
  JERRY_ASSERT (ecma_is_value_bigint (left_value) && ecma_is_value_bigint (right_value));

  if (right_value == ECMA_BIGINT_ZERO)
  {
    return ecma_raise_range_error (ECMA_ERR_MSG ("BigInt division by zero"));
  }

  if (left_value == ECMA_BIGINT_ZERO)
  {
    return left_value;
  }

  ecma_extended_primitive_t *left_p = ecma_get_extended_primitive_from_value (left_value);
  ecma_extended_primitive_t *right_p = ecma_get_extended_primitive_from_value (right_value);

  int compare_result = ecma_big_uint_compare (left_p, right_p);
  ecma_extended_primitive_t *result_p;

  if (compare_result < 0)
  {
    if (!is_mod)
    {
      return ECMA_BIGINT_ZERO;
    }

    ecma_ref_extended_primitive (left_p);
    return left_value;
  }
  else if (compare_result == 0)
  {
    if (is_mod)
    {
      return ECMA_BIGINT_ZERO;
    }

    result_p = ecma_bigint_create (sizeof (ecma_bigint_digit_t));

    if (result_p != NULL)
    {
      *ECMA_BIGINT_GET_DIGITS (result_p, 0) = 1;
    }
  }
  else
  {
    result_p = ecma_big_uint_div_mod (left_p, right_p, is_mod);

    if (result_p == ECMA_BIGINT_POINTER_TO_ZERO)
    {
      return ECMA_BIGINT_ZERO;
    }
  }

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

  if (is_mod)
  {
    result_p->u.bigint_sign_and_size |= left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN;
  }
  else
  {
    uint32_t sign = (left_p->u.bigint_sign_and_size ^ right_p->u.bigint_sign_and_size) & ECMA_BIGINT_SIGN;
    result_p->u.bigint_sign_and_size |= sign;
  }

  return ecma_make_extended_primitive_value (result_p, ECMA_TYPE_BIGINT);
}  