Skip to content

feat: add complex/float32/base/div - #9371

Merged
kgryte merged 21 commits into
stdlib-js:developfrom
iampratik13:feat/add-complex-float32-base-div
Aug 4, 2026
Merged

feat: add complex/float32/base/div#9371
kgryte merged 21 commits into
stdlib-js:developfrom
iampratik13:feat/add-complex-float32-base-div

Conversation

@iampratik13

@iampratik13 iampratik13 commented Dec 25, 2025

Copy link
Copy Markdown
Member

Resolves stdlib-js/metr-issue-tracker#1107

Description

What is the purpose of this pull request?

This pull request:

feat: add complex/float32/base/div

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

stdlib-js/metr-issue-tracker#1107

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

Claude Code Generation


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 25, 2025
@stdlib-bot

stdlib-bot commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
complex/float32/base/div $\\color{green}325/325$
$\\color{green}+0.00\\%$
$\\color{green}15/15$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}325/325$
$\\color{green}+0.00\\%$

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

@iampratik13

Copy link
Copy Markdown
Member Author

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Dec 25, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Dec 25, 2025
@kgryte kgryte added the Feature Issue or pull request for adding a new feature. label Dec 27, 2025
@kgryte kgryte mentioned this pull request Dec 27, 2025
1 task
@kgryte
kgryte self-requested a review December 27, 2025 02:07
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Dec 27, 2025
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 27, 2025
---
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: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
---
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: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Dec 27, 2025
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.assign.js Outdated
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.assign.js Outdated
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.main.js Outdated
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.main.js Outdated
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.main.js Outdated
Comment thread lib/node_modules/@stdlib/complex/float32/base/div/test/test.strided.js Outdated

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

@iampratik13 A few comments:

  1. Single-precision arithmetic implementations need to emulate single-precision arithmetic, as performed in C. See other float32 implementations.
  2. Given how the tests were written, it looks like you used AI, which you did not disclose in the OP. Furthermore, you did not check that the generated assertions made sense, with some test cases always returning true regardless of the actual test result. This smells of having AI attempt to resolve failing test cases. The most surefire way to do so is to author the tests such that they always pass. This is disappointing. I suggest revisiting the tests in this PR and actually implementing them by hand. And for those tests which appear to diverge from Julia, well, I suggest digging in to figure out why they differ. Perhaps, even read Julia's source code (ref: https://github.com/JuliaLang/julia/blob/966d0af0fdffc727eb240e2e4c908fdd46697e57/base/complex.jl#L357). It is possible that their single-precision implementation differs from their double-precision implementation. You might also consider whether the algorithm from Scilab is appropriate for single-precision by actually reading the paper (ref: https://arxiv.org/pdf/1210.4539). It is possible that it is, but it may also require tweaks. You should understand what those are.

@iampratik13

Copy link
Copy Markdown
Member Author

Thanks for the detailed feedback, and apologies for the issues you pointed out. You’re right that the single-precision implementation should properly emulate C-style float32 arithmetic, and I’ll revise it to match existing float32 patterns in the codebase.
I also acknowledge the problems with the tests and will rework them manually to ensure the assertions are meaningful. I’ll review Julia’s implementation and the referenced paper to better understand any single-precision–specific differences and update the PR accordingly.

@iampratik13

Copy link
Copy Markdown
Member Author

/stdlib update-copyright-years

iampratik13 and others added 3 commits January 5, 2026 11:59
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Pratik  <bhagwatpratik781@gmail.com>
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Pratik  <bhagwatpratik781@gmail.com>
---
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: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - 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
---
@iampratik13
iampratik13 requested a review from kgryte January 5, 2026 07:47
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 5, 2026
@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label May 5, 2026
@kgryte
kgryte requested a review from anandkaranubc May 5, 2026 04:04
- Smith, Robert L. 1962. "Algorithm 116: Complex Division." _Commun. ACM_ 5 (8). New York, NY, USA: ACM: 435. doi:[10.1145/368637.368661][@smith:1962a].
- Stewart, G. W. 1985. "A Note on Complex Division." _ACM Trans. Math. Softw._ 11 (3). New York, NY, USA: ACM: 238–41. doi:[10.1145/214408.214414][@stewart:1985a].
- Priest, Douglas M. 2004. "Efficient Scaling for Complex Division." _ACM Trans. Math. Softw._ 30 (4). New York, NY, USA: ACM: 389–401. doi:[10.1145/1039813.1039814][@priest:2004a].
- Julia. "complex.jl." Julia Programming Language. [&lt;https://github.com/JuliaLang/julia/blob/master/base/complex.jl>][@julia:complex].

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.

Suggested change
- Julia. "complex.jl." Julia Programming Language. [&lt;https://github.com/JuliaLang/julia/blob/master/base/complex.jl>][@julia:complex].

anandkaranubc and others added 7 commits August 3, 2026 21:54
---
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_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
---
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_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: passed
  - 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
---
---
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_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: passed
  - task: lint_license_headers
    status: passed
---
---
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_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: passed
  - 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
---
---
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_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: passed
  - 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
---
---
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_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
---
@anandkaranubc anandkaranubc added JavaScript Issue involves or relates to JavaScript. C Issue involves or relates to C. METR Pull request associated with the METR project. labels Aug 4, 2026

@anandkaranubc anandkaranubc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bit ironic that I’m approving my own changes, but this looks good to me.

Spent a whopping 10 hours on this, haha. Thanks @iampratik13 for the initial template, and your dedicated work on this!

cc: @kgryte

@anandkaranubc

Copy link
Copy Markdown
Contributor

Hopefully, this will unlock all the remaining packages that depend on it! 😄

@kgryte

kgryte commented Aug 4, 2026

Copy link
Copy Markdown
Member

@anandkaranubc You were able to figure out the accuracy issues?!?!

@kgryte kgryte removed the Needs Review A pull request which needs code review. label Aug 4, 2026
@anandkaranubc

anandkaranubc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@anandkaranubc You were able to figure out the accuracy issues?!?!

Yes Sir! Since inputs are float32, widening to float64 makes all intermediate products exact and the denominator cannot overflow or underflow, so no scaling is needed. Just the plain formula in double precision with one final rounding, matching Julia's Complex{Float32} division. Verified bit for bit against Julia on 6500 fixtures and 65 edge cases (subnormals, signed zeros, infinities, NaNs), for both JS and C, and across all optimization levels.

😃

Also tried to reference all of this in the code too, so it doesn't get lost anywhere in the future.....

@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 commented Aug 4, 2026

Copy link
Copy Markdown
Member

And yeah, while not ideal to rely on double-precision, I think it is fine for now given that we don't have much of an alternative.

@kgryte
kgryte merged commit b423804 into stdlib-js:develop Aug 4, 2026
65 checks passed
@anandkaranubc

Copy link
Copy Markdown
Contributor

WOOWOWOWO, this was quick! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Issue involves or relates to C. Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. METR Pull request associated with the METR project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean-up complex/float32/base/div

4 participants