Skip to content

test: migrate constants/float16/half-ln-two to ULP-based assertions - #16120

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-constants-float16-half-ln-two
Oct 13, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-constants-float16-half-ln-two

Conversation

@kgryte

@kgryte kgryte commented Oct 13, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Specifically, this pull request:

  • adds the @stdlib/number/float16/base/assert/is-almost-same-value import and removes the now-unused @stdlib/math/base/special/absf and @stdlib/constants/float16/eps imports.
  • removes the delta/tol computations (and the corresponding var delta;/var tol; declarations) from the export equals 0.5*lnf(2) test case.
  • replaces t.ok( delta <= tol, ... ) with t.strictEqual( isAlmostSameValue( v, FLOAT16_HALF_LN2, 0 ), true, 'returns expected value' );.

Only test/test.js is modified; the package has no test/test.native.js. No other test cases were touched, and the existing exact comparisons (t.strictEqual on the typeof check and on the literal constant value) were left as-is.

The conversion mirrors, line for line, the already-merged migrations of the two sibling packages for this exact same constant: constants/float32/half-ln-two (#16071) and constants/float64/half-ln-two (#16098). The import follows the existing precision convention established by those packages: the float32 package uses the single-precision @stdlib/number/float32/base/assert/is-almost-same-value, the float64 package uses the double-precision @stdlib/assert/is-almost-same-value, and so this pull request uses the half-precision @stdlib/number/float16/base/assert/is-almost-same-value, since the value under test is a half-precision constant and ULP distance must therefore be measured in half-precision space.

ULP bound

Test case Measured ULP difference Final ULP bound
export equals 0.5*lnf(2) 0 0

float64ToFloat16( 0.5 * lnf( 2.0 ) ) and FLOAT16_HALF_LN2 are bit-identical, so the measured ULP difference is 0, which is also the floor (isAlmostSameValue with maxULP === 0 reduces to isSameValue). The bound therefore cannot be tightened further. This matches the 0 bound accepted for the corresponding test case in both constants/float32/half-ln-two and constants/float64/half-ln-two, and is strictly tighter than the relative tolerance it replaces: the old tol = EPS * FLOAT16_HALF_LN2 evaluated to ≈3.386e-4, whereas one half-precision ULP at this magnitude is 2^-2 * EPS16 ≈ 2.441e-4, so the previous assertion admitted more than 1 ULP of error.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

  • make test TESTS_FILTER=".*/constants/float16/half-ln-two/.*" passes 4/4. The suite was run three times at the final bound with identical results, confirming determinism (no FMA/arch-dependent variation in this environment). The test suite uses no PRNG, so the fixture values are fixed by construction.
  • The assertion was separately confirmed to be live: perturbing the constant by a single half-precision ULP is rejected at maxULP === 0 and accepted at maxULP === 1.
  • make eslint-tests TESTS_FILTER=".*/constants/float16/half-ln-two/.*" passes cleanly, as does make lint-license-headers-files for the changed file.
  • The lint-editorconfig-files target was not run in this environment, as it downloads the editorconfig-checker binary from a host that was not reachable from the sandbox. The file was instead verified programmatically against .editorconfig: LF line endings, valid UTF-8, tab indentation (no space-indented lines), no trailing whitespace, and a single final newline.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of 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

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was authored by Claude Code running as an unattended scheduled task. It selected the package at random from the remaining unconverted candidates, studied the already-merged constants/float32/half-ln-two and constants/float64/half-ln-two migrations as prior art, performed the test conversion, and determined the minimum ULP bound empirically by measuring the observed ULP difference and confirming that the bound is both minimal and the hard floor.


@stdlib-js/reviewers


Generated by Claude Code

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Oct 13, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
constants/float16/half-ln-two $\\color{green}50/50$
$\\color{green}+100.00\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{green}0/0$
$\\color{green}+100.00\\%$
$\\color{green}50/50$
$\\color{green}+100.00\\%$

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

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Oct 13, 2026
@kgryte
kgryte marked this pull request as ready for review October 13, 2026 16:09
@kgryte
kgryte requested a review from a team October 13, 2026 16:09
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 13, 2026
@kgryte
kgryte merged commit 770dfe9 into develop Oct 13, 2026
66 checks passed
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 13, 2026
@kgryte
kgryte deleted the kgryte/ulp-constants-float16-half-ln-two branch October 13, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants