Skip to content

refactor: add explicit NaN guard to stats/base/dists/arcsine/median native source#12896

Closed
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-stats-arcsine-2026-06-15
Closed

refactor: add explicit NaN guard to stats/base/dists/arcsine/median native source#12896
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-stats-arcsine-2026-06-15

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

This pull request:

  • Aligns the native stats/base/dists/arcsine/median implementation with the validation prologue used by 6 of 8 sibling 2-argument distribution functions in the same namespace and by 23 of 25 (92%) */median/src/main.c files across stats/base/dists.

Namespace summary

  • Namespace: @stdlib/stats/base/dists/arcsine (14 members)
  • Features analyzed: file tree, package.json / manifest.json keys, README structure, JS validation prologue and JSDoc shape, presence of native/Julia/factory artifacts
  • Features with a clear majority (≥75% conformance): native implementation suite (12/14), Julia fixture suite (12/14), README skeleton [Usage, Examples, C APIs, Usage, Examples] (11/14), stdlib_base_is_nan guard in 2-arg C sources (6/8)
  • Features excluded for lack of majority: JS validation prologue isnan guard (4/8 for 2-arg, 9/13 across non-ctor), lib/factory.js presence (5/14)

stats/base/dists/arcsine/median

median/src/main.c previously guarded with if ( a >= b ) only, where the sibling C sources mean, stdev, entropy, kurtosis, mode, and skewness all open with if ( stdlib_base_is_nan( a ) || stdlib_base_is_nan( b ) || a >= b ). Behavior is unchanged — NaN inputs already propagate to a NaN return via the arithmetic path; this only makes the early-return explicit and matches the namespace convention. Adds the corresponding #include "stdlib/math/base/assert/is_nan.h" and registers @stdlib/math/base/assert/is-nan under build, benchmark, and examples in manifest.json so the native build resolves the header.

Related Issues

None.

Questions

No.

Other

Validation

Structural features were extracted by reading the file tree and package.json / manifest.json / README.md of each of the 14 namespace members. Semantic features (JS public signature, validation prologue, JSDoc shape) were extracted directly from lib/main.js of every member; native-source content was inspected manually as a follow-on once structural analysis showed near-uniform native-file presence (12/14). Each surviving outlier was put through three independent validation agents (semantic review, cross-reference, structural review) before any patch was applied — the cross-reference agent caught that the original patch sketch was incomplete (manifest.json also needed the is-nan dependency or the build would break), and the patch was extended before commit.

Deliberately excluded from this PR:

  • Missing C implementation for stats/base/dists/arcsine/logcdf — open-PR collision with feat: add C implementation for stats/base/dists/arcsine/logcdf #3389 and feat: add C implementation for stats/base/dists/arcsine/logcdf #10739
  • Missing C implementation for stats/base/dists/arcsine/ctorctor is a constructor class, not a scalar function; the native skeleton is not applicable
  • Missing Julia fixtures for kurtosis and skewness — both return mathematical constants (-1.5 and 0.0 respectively), so reference values would be uninformative
  • Missing JS isnan guard in mean, median, stdev, variance — 4-of-8 split in the 2-arg JS sources, below the 75% threshold for declaring a majority pattern
  • stats/base/dists/arcsine/variance/src/main.c NaN guard — ecosystem-wide presence for */variance/src/main.c is 78%, below the 90% threshold for treating absence as drift

Checklist

AI Assistance

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was authored by Claude Code as part of the automated cross-package drift detection routine. Candidate-outlier enumeration and within-namespace majority computation ran locally; each surviving candidate was validated by three independent agents (semantic review, cross-reference against tests / docs / consumers, structural review including manifest implications) before the patch was applied. A human maintainer should verify the patch before promoting this PR out of draft.


@stdlib-js/reviewers


Generated by Claude Code

…g packages

Adds the explicit `stdlib_base_is_nan` guard (and corresponding
`is_nan.h` include + manifest dependency) so the native median
implementation matches the validation prologue used by 6/8 sibling
2-arg distribution functions in `stats/base/dists/arcsine`
(`mean`, `stdev`, `entropy`, `kurtosis`, `mode`, `skewness`) and by
23/25 (92%) sibling `*/median/src/main.c` files across
`stats/base/dists`. Behavior is unchanged: NaN inputs continue to
propagate to a NaN return via the arithmetic path; this only makes
the early-return explicit.
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Jun 15, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/arcsine/median $\\color{green}177/177$
$\\color{green}+100.00\\%$
$\\color{green}7/7$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}177/177$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

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

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants