Skip to content

bug: Median() truncates integers #19536

Closed

Description

@petern48

Great catch. I looked into it, and it seems like it's wrapping around due to integer overflow while taking the average of the middle two values (since the count is even).

low: [-85], high: -56, median: 57 datatype: Int8

-85 + -56 = -141 -> wraparound to 115
Then 115 / 2 -> 57.5 -> 57 (truncated due to integer type)

What's our desired behavior in this case? We could promote to a larger datatype to perform the calculation. Also is it intentional to return the value as a truncated integer instead of a float?

Originally posted by @petern48 in #19278 (comment)

The overflow part was fixed in #19322, but the truncation issue remains. Other databases seem to return a float: #19322 (comment)

Activity

  1. changed the title [-]Median() truncates integers[/-] [+]bug: Median() truncates integers[/+] on Dec 29, 2025
  2. Yuvraj-cyborg commented on Dec 29, 2025

    @Yuvraj-cyborg
    Contributor

    take

  3. CuteChuanChuan commented on Apr 18, 2026

    @CuteChuanChuan
    Contributor

    Hi @Yuvraj-cyborg ,
    just checking in — are you still working on this issue?
    If you're busy or no longer planning to continue, I'd be happy to pick it up. Thanks!

  4. Yuvraj-cyborg commented on Apr 21, 2026

    @Yuvraj-cyborg
    Contributor

    @CuteChuanChuan feel free to pick it, got busy lately

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions