Skip to content

percentile_cont overflows while interpolating finite Float64 values #25267

Description

@aoto-tech

Describe the bug

I found that percentile_cont can return infinity for finite Float64 inputs even when the interpolated result is finite.

To Reproduce

I reproduced this on 55.1.0 and main at 9082d6b10.

SELECT percentile_cont(x, CAST(0.5 AS DOUBLE))
FROM (VALUES
  (CAST(-1.7976931348623157e308 AS DOUBLE)),
  (CAST( 1.7976931348623157e308 AS DOUBLE))
) AS t(x);
actual:   Infinity
expected: 0.0

### Expected behavior

The median of `-DBL_MAX` and `DBL_MAX` should be `0.0`.

### Additional context

The Float64 interpolation path evaluates [`lower + (upper - lower) * weight`](https://github.com/apache/datafusion/blob/9082d6b10c29b72d56bede3d8e353d9d61fde542/datafusion/functions-aggregate/src/percentile_cont.rs#L943-L945). `upper - lower` overflows before multiplication by `0.5`.

This is separate from #18945: that issue fixed Float16 interpolation by widening it to Float64, while this reproducer overflows in Float64 itself. I couldn't find an existing issue for this behavior.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions