Repository navigation
[RFC]: Migrate math/base/special packages from relative tolerance testing to ULP difference testing (tracking issue) #11352
Copy link
Copy link
Labels
AcceptedRFC feature request which has been accepted.RFC feature request which has been accepted.Good First IssueA good first issue for new contributors!A good first issue for new contributors!JavaScriptIssue involves or relates to JavaScript.Issue involves or relates to JavaScript.MathIssue or pull request specific to math functionality.Issue or pull request specific to math functionality.ModernizationIssue or pull request which modernizes stdlib according to the project's most recent conventions.Issue or pull request which modernizes stdlib according to the project's most recent conventions.TestsPull requests specifically adding tests.Pull requests specifically adding tests.difficulty: 1Low degree of difficulty. Should be straightforward to implement and/or resolve.Low degree of difficulty. Should be straightforward to implement and/or resolve.priority: NormalNormal priority concern or feature request.Normal priority concern or feature request.
Description
Instructions
- Read the issue description below.
- Read the issue comment which follows the description.
- Search for a package in
math/base/specialhaving relative tolerance tests which needs updating according to the description below. - Follow any additional guidance specified in this issue.
Description
This RFC proposes migrating from Relative Tolerance testing to ULP Difference testing for math/base/special functions.
In short, this RFC seeks to refactor testing from, for example
var abs = require( '@stdlib/math/base/special/abs' );
var delta = abs( y - expected[ i ] );
var tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y );to
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );The migration is demonstrated in commit 121f2c0
In particular, notice three things:
- We add the import
@stdlib/assert/is-almost-same-value. See the documentation for@stdlib/assert/is-almost-same-valuefor supported parameters. - We remove
var delta = abs( y - expected[ i ] );andvar tol = EPS * abs( expected[ i ] ); - We replace
t.ok( ... );witht.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' );with the returned output, expected value and the minimum required ulp value. Also, make sure the message is'returns expected value'for every test case.
By performing this refactoring, we facilitate
- Measuring error in units of the representable gap at that magnitude, which is the natural accuracy unit for floating-point.
- Enables a uniform accuracy budget
- Easier to test both real and complex functions, across single-precision and double-precision, with consistent and trustworthy rules.
Note: In certain functions, we may encounter different return values in the JavaScript and C implementation for the same implementation. In that case, refer to this commit 69e1068. This was discussed here in detail FAQ.
Steps
Given the relatively widespread practice of using relative tolerance in testing, this RFC aims to be an open call for any contributor wanting to contribute to the project to do the following:
- Study the changes made in commit 121f2c0, as this commit contains the sorts of changes that we are looking for.
- Ensure you have setup your local development environment by following the contributing guide, including
make install-node-modulesandmake init. - Study the documentation for
@stdlib/assert/is-almost-same-value. - Find a package containing relative tolerance test cases.
- Update the test cases for that package, and only that package, to migrate to use ULP difference testing. Make sure that you put the minimum required ULP value possible. Tests can be found in the
test/folder of a package (if it exists). - Run tests locally using the command
make test TESTS_FILTER=".*/math/base/special/<package-name>/.*". For example,make test TESTS_FILTER=".*/math/base/special/hyp2f1/.*". - Verify that the updated ULP values pass all the test cases.
- Commit your changes.
- Submit a PR updating the test for that package (and only that package).
- For the PR title, use the following template "test: migrate
<package-name>to ULP-based testing" where<package_name>is the name of the package you updated (e.g.,math/base/special/hyp2f1). - In the PR body/description, use the phrase "Resolves a part of ", and not "Resolves " or "Closes ", this issue, as this is a tracking issue and your PR only addresses one package of many needing updating.
Related Issues
None
Questions
None.
Other
- If you are interested in working on this RFC, for each pull request, please only update the tests for a single package.
- As mentioned above, please do NOT make extraneous changes to test cases. We are not interested in changing tests wholesale. Nor are we interested in new "creative" changes. We are only interested in migrating from relative tolerance testing to ULP diff based testing Failure to match the behavior of the existing tests and to respect this guidance will result in your PRs being automatically closed without review.
- As this is a "Good First Issue", you are strongly encouraged to avoid using AI when authoring your contribution. One of the primary intents of Good First Issues is to help introduce you to stdlib, its development environment, and the contribution process, as documented in the contributing guide. Most new contributors are unfamiliar with stdlib and its conventions, and thus fail to appropriately use LLMs and AI when authoring contributions, most often generating AI slop and leading to wasted time. Don't be one of those people. :) Take the time to manually author your first several PRs, and, once you are intimately familiar with project conventions, you can consider leveraging AI to augment your dev tasks.
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
AcceptedRFC feature request which has been accepted.RFC feature request which has been accepted.Good First IssueA good first issue for new contributors!A good first issue for new contributors!JavaScriptIssue involves or relates to JavaScript.Issue involves or relates to JavaScript.MathIssue or pull request specific to math functionality.Issue or pull request specific to math functionality.ModernizationIssue or pull request which modernizes stdlib according to the project's most recent conventions.Issue or pull request which modernizes stdlib according to the project's most recent conventions.TestsPull requests specifically adding tests.Pull requests specifically adding tests.difficulty: 1Low degree of difficulty. Should be straightforward to implement and/or resolve.Low degree of difficulty. Should be straightforward to implement and/or resolve.priority: NormalNormal priority concern or feature request.Normal priority concern or feature request.
Activity
stdlib-bot commentedon Apr 10, 2026
stdlib-bot commentedon Apr 11, 2026
👋 Important: PLEASE READ 👋
This issue has been labeled as a good first issue and is available for anyone to work on.
If this is your first time contributing to an open source project, some aspects of the development process may seem unusual, arcane, or some combination of both.
Before working on this issue and opening a pull request, please read the project's contributing guidelines. These guidelines and the associated development guide provide important information, including links to stdlib's Code of Conduct, license policy, and steps for setting up your local development environment.
To reiterate, we strongly encourage you to refer to our contributing guides before beginning work on this issue. Failure to follow our guidelines significantly decreases the likelihood that you'll successfully contribute to stdlib and may result in automatic closure of a pull request without review.
Setting up your local development environment is a critical first step, as doing so ensures that automated development processes for linting, license verification, and unit testing can run prior to authoring commits and pushing changes. If you would prefer to avoid manual setup, we provide pre-configured development containers for use locally or in GitHub Codespaces.
We place a high value on consistency throughout the stdlib codebase. We encourage you to closely examine other packages in stdlib and attempt to emulate the practices and conventions found therein.
In short, the more effort you put in to ensure that your contribution looks and feels like stdlib—including variables names, bracket spacing, line breaks, etc—the more likely that your contribution will be reviewed and ultimately accepted. We encourage you to closely study the codebase before beginning work on this issue.
✨ Thank you again for your interest in stdlib, and we look forward to reviewing your future contributions. ✨
test: migrate `math/base/special/acosh` to ULP-based testing
test: migrate `math/base/special/acos` to ULP-based testing
test: migrate `math/base/special/gamma-delta-ratio` to ulp based testing
test: migrate `math/base/special/acosd` to ULP-based testing
test: migrate `math/base/special/asinh` to ULP-based testing
281 remaining items
test: migrate `stats/base/dists/uniform/mean` to ULP-based assertions
test: migrate `stats/base/dists/binomial/entropy` to ULP-based assert…
test: migrate `stats/base/dists/bradford/median` to ULP-based assertions
test: migrate `stats/base/dists/betaprime/variance` to ULP-based asse…
test: migrate `stats/base/dists/t/pdf` to ULP-based assertions
test: migrate `stats/base/dists/invgamma/skewness` to ULP-based asser…
test: migrate `math/base/special/binomcoeff` to ULP-based assertions
test: migrate `stats/incr/nancovariance` to ULP-based assertions
test: migrate `stats/base/dists/logistic/cdf` to ULP-based assertions
test: migrate `stats/base/dists/halfnormal/entropy` to ULP-based asse…
test: migrate `math/base/tools/hermitepoly` to ULP-based assertions
test: migrate `simulate/iter/bartlett-hann-pulse` to ULP-based assert…
test: migrate `stats/base/dists/lognormal/entropy` to ULP-based asser…
test: migrate `math/base/special/binet` to ULP-based assertions
test: migrate `stats/base/dists/uniform/quantile` to ULP-based assert…