Skip to content

fix: differentiate positive and negative zero in doctesting - #15745

Merged
kgryte merged 2 commits into
stdlib-js:developfrom
officiallyanee:fix/compare-values-signed-zero
Oct 2, 2026
Merged

kgryte merged 2 commits into
stdlib-js:developfrom
officiallyanee:fix/compare-values-signed-zero

Conversation

@officiallyanee

Copy link
Copy Markdown
Member

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

Resolves none

Description

What is the purpose of this pull request?

This pull request:

fixes an issue in compareValues where signed zero (-0.0 vs +0.0) was not differentiated in doctest return value comparisons:

  • Previously, numeric comparison fell through to epsdiff( actual, expected ) < 10.0. Because IEEE 754 treats -0.0 == 0.0 as true, epsdiff( -0.0, 0.0 ) evaluated to 0, causing doctests to pass when a function returned -0.0 where 0.0/+0.0 was expected (or vice versa).
  • When parsed from array return annotations (e.g., [ -0 ]), numeric -0 values had their negative sign erased by String( expected ) coercion (since in JavaScript String(-0) evaluates to '0').
  • When formatting error messages for TypedArray instances in compareEntries, calling map( actual, formatValue ) allocated a new typed array of the same constructor, which coerce the formatted '-0.0' string back into a numeric float and stringified it to '0', which will result in confusing error messages like Expected entries [0], but observed [0].

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • None

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.

No.

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.".

I used AI to understand where the issue stems from along with what are the possible fixes for it, compared some methods and reasoned to this one and checked the test cases for validness myself.


@stdlib-js/reviewers

---
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: passed
  - 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
---
@officiallyanee
officiallyanee requested a review from a team October 1, 2026 14:14
@officiallyanee
officiallyanee marked this pull request as draft October 1, 2026 14:14
@stdlib-bot stdlib-bot added Tools Issue or pull request related to project tooling. Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Oct 1, 2026
Comment thread lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js Outdated
t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' );

actual = new Float64Array( [ -0.0, 0.0 ] );
expected = '<Float64Array>[ -0.0, 0.0 ]';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely an improvement!

@kgryte

kgryte commented Oct 2, 2026

Copy link
Copy Markdown
Member

@officiallyanee You marked this PR as draft. Was that intentional?

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

Copy link
Copy Markdown
Member Author

@kgryte Yes, I got caught up in something as I was writing the PR. I drafted it out so I can come back and check once more before marking it ready for review.
It's marked ready for review now.

@officiallyanee
officiallyanee marked this pull request as ready for review October 2, 2026 13:16
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 2, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Oct 2, 2026

@kgryte kgryte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kgryte kgryte changed the title fix: differentiate positive and negative zero in compare-values fix: differentiate positive and negative zero in doctesting Oct 2, 2026
@kgryte
kgryte merged commit 2cab31d into stdlib-js:develop Oct 2, 2026
27 checks passed
@officiallyanee
officiallyanee deleted the fix/compare-values-signed-zero branch October 2, 2026 23:31
kgryte pushed a commit that referenced this pull request Oct 12, 2026
PR-URL: #15830
Reviewed-by: Athan Reines <kgryte@gmail.com>
Ref: #15745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools Issue or pull request related to project tooling.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants