///|
/// Parse a non-empty unsigned decimal into Int64 with pre-multiplication overflow checks.
pub fn parse_decimal_int64(input : String) -> Result[Int64, RangeError] {
  parse_decimal_int64_at(input, 0, Limits::default())
}

///|
fn parse_decimal_int64_at(
  input : String,
  base_offset : Int,
  limits : Limits,
) -> Result[Int64, RangeError] {
  let chars = input.to_array()
  if chars.is_empty() {
    return Err(
      range_error(Number, MissingNumber, base_offset, "decimal number is empty"),
    )
  }
  if chars.length() > limits.max_digits_per_number() {
    return Err(
      range_error(
        Limit,
        LimitExceeded,
        base_offset,
        "decimal digit count exceeds limit",
      ),
    )
  }
  let mut value = 0L
  for i = 0; i < chars.length(); i = i + 1 {
    let c = chars[i]
    if !is_digit(c) {
      return Err(
        range_error(
          Number,
          InvalidNumber,
          base_offset + i,
          "decimal contains a non-digit",
        ),
      )
    }
    let digit = (c.to_int() - 48).to_int64()
    if value > (@int64.MAX_VALUE - digit) / 10L {
      return Err(
        range_error(
          Number,
          IntegerOverflow,
          base_offset + i,
          "decimal exceeds Int64 maximum",
        ),
      )
    }
    value = value * 10L + digit
  }
  Ok(value)
}