Skip to content

fix: disable zero-padding for special values in string/base/format-interpolate #6957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025

Conversation

anandkaranubc
Copy link
Contributor

Resolves None

Description

What is the purpose of this pull request?

This pull request:

  • Updates format-interpolate to disable zero-padding for special values

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves 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.


@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: passed
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 8, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented May 8, 2025

Coverage Report

Package Statements Branches Functions Lines
string/base/format-interpolate $\color{red}712/739$
$\color{green}+96.35\%$
$\color{red}123/139$
$\color{green}+88.49\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{red}712/739$
$\color{green}+96.35\%$

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

---
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: passed
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
Comment on lines +628 to +651
str = '%.10f %.10f baz';
tokens = formatTokenize( str );
actual = formatInterpolate( tokens, PINF, NINF );
expected = 'infinity -infinity baz';
t.strictEqual( actual, expected, 'returns expected output' );

str = '%0.10f %0.10f baz';
tokens = formatTokenize( str );
actual = formatInterpolate( tokens, PINF, NINF );
expected = 'infinity -infinity baz';
t.strictEqual( actual, expected, 'returns expected output' );

str = '%.4f';
tokens = formatTokenize( str );
actual = formatInterpolate( tokens, NaN );
expected = 'nan';
t.strictEqual( actual, expected, 'returns expected output' );

str = '%0.4f';
tokens = formatTokenize( str );
actual = formatInterpolate( tokens, NaN );
expected = 'nan';
t.strictEqual( actual, expected, 'returns expected output' );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these are probably the most relevant ones related to the fix. If the other tests below are not needed, I can remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for choosing %0.10f for infinity and -infinity is that -infinity is 9 characters long, and using a precision of 10 can correctly check for no zero-padding. The same reasoning applies to NaN and 0.4f.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense.

@anandkaranubc anandkaranubc requested a review from kgryte May 8, 2025 07:01
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the patch, @anandkaranubc!

@kgryte kgryte removed the Needs Review A pull request which needs code review. label May 8, 2025
@kgryte kgryte changed the title fix: disable zero-padding for special values in formatInterpolate fix: disable zero-padding for special values in string/base/format-interpolate May 8, 2025
@kgryte kgryte merged commit b3c2d12 into stdlib-js:develop May 8, 2025
15 checks passed
@anandkaranubc anandkaranubc deleted the format-interpolate branch May 8, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants