Skip to content

test: migrate constants/float32/ln-two to ULP-based assertions - #16104

Merged
kgryte merged 2 commits into
developfrom
kgryte/ulp-constants-float32-ln-two
Oct 13, 2026
Merged

kgryte merged 2 commits into
developfrom
kgryte/ulp-constants-float32-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:

  • migrates the test suite for constants/float32/ln-two from a relative tolerance assertion to a ULP difference assertion.

The export equals lnf(2) test previously computed delta = absf( float64ToFloat32( v - FLOAT32_LN2 ) ) and tol = EPS * FLOAT32_LN2 and asserted with t.ok( delta <= tol, ... ). It now delegates to @stdlib/number/float32/base/assert/is-almost-same-value:

tape( 'export equals `lnf(2)`', function test( t ) {
	var v;

	v = lnf( 2.0 );

	t.strictEqual( isAlmostSameValue( v, FLOAT32_LN2, 0 ), true, 'returns expected value' );

	t.end();
});

Final ULP constant: 0.

File Call sites ULP bound
test/test.js 1 0

Notes on how the bound was measured:

  • The bound was tightened empirically, starting from n = 64 and stepping down (64, 32, 16, 8, 4, 2, 1, 0). Every probe passes, so 0 is the measured minimum and no smaller non-negative bound exists.
  • lnf( 2.0 ) returns 0.6931471824645996, which is bit-identical to the exported constant 0.6931471824645996; @stdlib/number/float32/base/ulp-difference reports a difference of exactly 0 ULP. The single-precision variant of the assertion is used here (matching the already-converted constants/float32/ln-two-pi, constants/float32/ln-ten, and constants/float32/half-ln-two) so that the gap is measured in single-precision units.
  • The suite was run twice at the final bound to confirm determinism; all 4 assertions pass both times.
  • This package has no test.native.js, so there is no JS/C divergence to account for.
  • The two pre-existing exact assertions (typeof and the exact float64ToFloat32( 0.6931471805599453 ) value check) are intentionally left unchanged, as exact comparisons remain correct there.
  • Only the one test file is modified; no source, documentation, or fixture changes.

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.

The bound is reproducible across architectures: the comparison is between two compile-time-fixed single-precision values and is not subject to FMA-contraction differences.

Note that the local make pre-commit EditorConfig check could not run in this environment (the editorconfig-checker binary download is network-blocked), so the changed file was verified manually for tabs-only indentation, no trailing whitespace, LF endings, and a final newline. make eslint-tests and make test for this package both pass.

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. It studied the already-converted packages in the same family (notably constants/float32/ln-two-pi and constants/float32/half-ln-two) to match the established idiom, then measured the minimum ULP bound empirically and verified determinism as described above.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01J5v9ZJHAL6HBquWwB9FWTL


Generated by Claude Code

Replace the relative tolerance assertion in the test suite with a ULP
difference assertion via
`@stdlib/number/float32/base/assert/is-almost-same-value`.

The measured minimum ULP bound is `0`.

Ref: #11352

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

---
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: passed
  - 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

stdlib-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
constants/float32/ln-two $\\color{green}51/51$
$\\color{green}+0.00\\%$
$\\color{green}1/1$
$\\color{green}+0.00\\%$
$\\color{green}0/0$
$\\color{green}+0.00\\%$
$\\color{green}51/51$
$\\color{green}+0.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:54
@kgryte
kgryte requested a review from a team October 13, 2026 10:54
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte
kgryte merged commit 0ed340c into develop Oct 13, 2026
12 checks passed
@kgryte
kgryte deleted the kgryte/ulp-constants-float32-ln-two branch October 13, 2026 11:18
@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.

3 participants