apache/cassandra · error · ArithmeticException

Log10 of number zero or less

Error message

Log10 of number zero or less

What it means

Fired in DecimalType.log10 when the input Number converts to a BigDecimal that is zero or negative; logarithm is undefined there, so an ArithmeticException is thrown. Reached via log10() for CQL native functions on numeric arguments.

Solutions

  1. Add WHERE col > 0 filtering before applying log10()
  2. Wrap in CASE or a UDF returning null for non-positive input
  3. Validate/clean data at write time to keep the column strictly positive

Example fix

// before
SELECT log10(count_col) FROM metrics;
// after
SELECT log10(count_col) FROM metrics WHERE count_col > 0;
Defensive patterns

Strategy: validation

Validate before calling

if (input == null || input.signum() <= 0) throw new IllegalArgumentException("log10 requires a strictly positive value");

Type guard

boolean isPositive(BigDecimal v) { return v != null && v.signum() > 0; }

Try / catch

try { result = DecimalType.instance.log10(value); } catch (ArithmeticException e) { /* map non-positive input to null/default */ }

Prevention

When it happens

Trigger: Executing a CQL expression like log10(col) reaching log10(Number) with input <= 0.

Common situations: Log-scaling metrics that can be zero (counts) or negative (differences); unfiltered user-supplied values.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/1d12cfc8e3939cb6. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/db/marshal/DecimalType.java:453

    protected BigDecimal log(BigDecimal input)
    {
        if (input.compareTo(BigDecimal.ZERO) <= 0) throw new ArithmeticException("Natural log of number zero or less");
        int precision = input.precision();
        precision = Math.max(MIN_SIGNIFICANT_DIGITS, precision);
        precision = Math.min(MAX_PRECISION.getPrecision(), precision);
        return BigDecimalMath.log(input, new MathContext(precision, RoundingMode.HALF_EVEN));
    }

    @Override
    public ByteBuffer log10(Number input)
    {
        return decompose(log10(toBigDecimal(input)));
    }

    protected BigDecimal log10(BigDecimal input)
    {
        if (input.compareTo(BigDecimal.ZERO) <= 0) throw new ArithmeticException("Log10 of number zero or less");
        int precision = input.precision();
        precision = Math.max(MIN_SIGNIFICANT_DIGITS, precision);
        precision = Math.min(MAX_PRECISION.getPrecision(), precision);
        return BigDecimalMath.log10(input, new MathContext(precision, RoundingMode.HALF_EVEN));
    }

    @Override
    public ByteBuffer round(Number input)
    {
        return DecimalType.instance.decompose(
        toBigDecimal(input).setScale(0, RoundingMode.HALF_UP));
    }

    @Override
    public ByteBuffer getMaskedValue()
    {
        return MASKED_VALUE;
    }

View on GitHub (pinned to 88fd0f6a0e)