ecma_bigint_compare_to_number (ecma_value_t left_value, /**< left BigInt value */
                               ecma_number_t right_value) /**< right number value */
{
  JERRY_ASSERT (ecma_is_value_bigint (left_value));
  JERRY_ASSERT (!ecma_number_is_nan (right_value));

  int right_invert_sign = ECMA_BIGINT_TO_SIGN (right_value > 0);

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

    return right_invert_sign;
  }

  ecma_extended_primitive_t *left_value_p = ecma_get_extended_primitive_from_value (left_value);
  int left_sign = ECMA_BIGINT_TO_SIGN (left_value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN);

  if (right_value == 0 || left_sign == right_invert_sign)
  {
    /* Second condition: a positive BigInt is always greater than any negative number, and the opposite is true. */
    return left_sign;
  }

  if (ecma_number_is_infinity (right_value))
  {
    /* Infinity is always bigger than any BigInt number. */
    return right_invert_sign;
  }

  ecma_bigint_digit_t digits[3];
  uint32_t result = ecma_bigint_number_to_digits (right_value, digits);

  JERRY_ASSERT (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) == 0
                || digits[ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) - 1] > 0);

  uint32_t digits_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE (result);

  if (digits_size == 0)
  {
    JERRY_ASSERT (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION);
    /* The number is between [-1 .. 1] exclusive. */
    return left_sign;
  }

  uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p);
  uint32_t right_size = digits_size + ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE (result);

  if (left_size != right_size)
  {
    return left_size > right_size ? left_sign : -left_sign;
  }

  ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, right_size);
  ecma_bigint_digit_t *left_end_p = (ecma_bigint_digit_t *) (((uint8_t *) left_p) - digits_size);
  ecma_bigint_digit_t *digits_p = (ecma_bigint_digit_t *) (((uint8_t *) digits) + digits_size);

  do
  {
    ecma_bigint_digit_t left = *(--left_p);
    ecma_bigint_digit_t right = *(--digits_p);

    if (left != right)
    {
      return left > right ? left_sign : -left_sign;
    }
  }
  while (left_p > left_end_p);

  left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0);

  while (left_p > left_end_p)
  {
    if (*(--left_p) != 0)
    {
      return left_sign;
    }
  }

  return (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION) ? -left_sign : 0;
} /* ecma_bigint_compare_to_number */
ecma_bigint_compare_to_number (ecma_value_t left_value,  
                               ecma_number_t right_value)  
{
  JERRY_ASSERT (ecma_is_value_bigint (left_value));
  JERRY_ASSERT (!ecma_number_is_nan (right_value));

  int right_invert_sign = ECMA_BIGINT_TO_SIGN (right_value > 0);

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

    return right_invert_sign;
  }

  ecma_extended_primitive_t *left_value_p = ecma_get_extended_primitive_from_value (left_value);
  int left_sign = ECMA_BIGINT_TO_SIGN (left_value_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN);

  if (right_value == 0 || left_sign == right_invert_sign)
  {
     
    return left_sign;
  }

  if (ecma_number_is_infinity (right_value))
  {
     
    return right_invert_sign;
  }

  ecma_bigint_digit_t digits[3];
  uint32_t result = ecma_bigint_number_to_digits (right_value, digits);

  JERRY_ASSERT (ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) == 0
                || digits[ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS (result) - 1] > 0);

  uint32_t digits_size = ECMA_BIGINT_NUMBER_TO_DIGITS_GET_DIGITS_SIZE (result);

  if (digits_size == 0)
  {
    JERRY_ASSERT (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION);
     
    return left_sign;
  }

  uint32_t left_size = ECMA_BIGINT_GET_SIZE (left_value_p);
  uint32_t right_size = digits_size + ECMA_BIGINT_NUMBER_TO_DIGITS_GET_ZERO_SIZE (result);

  if (left_size != right_size)
  {
    return left_size > right_size ? left_sign : -left_sign;
  }

  ecma_bigint_digit_t *left_p = ECMA_BIGINT_GET_DIGITS (left_value_p, right_size);
  ecma_bigint_digit_t *left_end_p = (ecma_bigint_digit_t *) (((uint8_t *) left_p) - digits_size);
  ecma_bigint_digit_t *digits_p = (ecma_bigint_digit_t *) (((uint8_t *) digits) + digits_size);

  do
  {
    ecma_bigint_digit_t left = *(--left_p);
    ecma_bigint_digit_t right = *(--digits_p);

    if (left != right)
    {
      return left > right ? left_sign : -left_sign;
    }
  }
  while (left_p > left_end_p);

  left_end_p = ECMA_BIGINT_GET_DIGITS (left_value_p, 0);

  while (left_p > left_end_p)
  {
    if (*(--left_p) != 0)
    {
      return left_sign;
    }
  }

  return (result & ECMA_BIGINT_NUMBER_TO_DIGITS_HAS_FRACTION) ? -left_sign : 0;
}  