Skip to content

Fix #1: Implement Median function#8

Open
tannadevp wants to merge 2 commits into
bsoc-bitbyte:mainfrom
tannadevp:add-median
Open

Fix #1: Implement Median function#8
tannadevp wants to merge 2 commits into
bsoc-bitbyte:mainfrom
tannadevp:add-median

Conversation

@tannadevp

@tannadevp tannadevp commented Jun 8, 2026

Copy link
Copy Markdown

Overview

  1. This PR fixes or fixes part of Implement median #1 .
  2. This PR implements the median function for f64 slices in the primary module.

Completed issue requirements:

  • Created a new file : src/primary/median.rs
  • Declared and re-exported median in src/primary/mod.rs
  • Implemented the median function
  • Added documentation comments
  • Included usage examples in the documentation comments

Implementation:

  • Returns None for empty input
  • Returns the middle value for odd-length inputs
  • Returns the average of the two middle values for even-length inputs
  • Creates a sorted copy of the input so that the original slice remains unchanged
  • Uses partial_cmp for ordering f64 values and rejects NaN values

The issue mentions primary/lib.rs, but this repository uses src/primary/mod.rs for the primary module, so median has been declared and re-exported there.

Essential Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • "Allow edits from maintainers" is checked. (See here for instructions on how to enable it.)
  • The PR is made from a branch that's not called "main/master".

Proof that changes are correct

Verified locally with:

  1. cargo test --test median : passes for all the 11 median-specific tests
  2. cargo test : attempts to compile for variance and std_devation as well, which are unimplemented functions/issues
  3. cargo check : successfully executed
  4. cargo fmt

Looking forward to your feedback. Please let me know if any changes are required. Thank you for reviewing!

@tannadevp tannadevp changed the title Add median Fix #1: Implement Median function Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant