Skip to content

test: migrate constants/float64/half-ln-two to ULP-based assertions - #16098

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

kgryte merged 1 commit into
developfrom
kgryte/ulp-constants-float64-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/assert/is-almost-same-value import and removes the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps imports.
  • removes the delta/tol computations (and the corresponding var delta;/var tol; declarations) from the export equals 0.5*ln(2) test case.
  • replaces t.ok( delta <= tol, ... ) with t.strictEqual( isAlmostSameValue( v, 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 constants/float32/half-ln-two migration (e08b3f7 / #16071), which is the single-precision counterpart of this exact constant and therefore serves as direct prior art for every change here. The one deliberate difference is the import: because the value under test is a double-precision constant, this pull request uses the double-precision @stdlib/assert/is-almost-same-value prescribed by #11352, rather than the single-precision @stdlib/number/float32/base/assert/is-almost-same-value used by the float32 package. This also matches the already-merged constants/float64/ln-two-pi migration (#15855).

ULP bound

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

0.5 * ln( 2.0 ) and 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 constants/float32/half-ln-two, and is tighter than the relative tolerance it replaces (EPS * HALF_LN2, i.e. 1 ULP).

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/float64/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 double-precision ULP (via to-words/from-words) is rejected at maxULP === 0 and accepted at maxULP === 1.
  • make eslint-tests TESTS_FILTER=".*/constants/float64/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/ln-two-pi 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

Replace the relative tolerance assertion in the `export equals
0.5*ln(2)` test case with an ULP difference assertion using
`@stdlib/assert/is-almost-same-value`. The `delta`/`tol`
computations and the now-unused `@stdlib/math/base/special/abs`
and `@stdlib/constants/float64/eps` imports are removed.

`0.5 * ln( 2.0 )` is bit-identical to the exported constant, so
the measured ULP difference is 0, which is also the tightest
possible bound.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CV9AEfa7wkGtWEebxsa3M

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: skipped
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@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/float64/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 10:31
@kgryte
kgryte requested a review from a team October 13, 2026 10:31
@kgryte
kgryte merged commit 30ad8ec into develop Oct 13, 2026
50 checks passed
@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Oct 13, 2026
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