Skip to content

Conversation

@iampratik13
Copy link
Contributor

Resolves none

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:

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

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

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

stdlib-bot commented Dec 25, 2025

Coverage Report

Package Statements Branches Functions Lines
complex/float32/base/div $\color{green}466/466$
$\color{green}+0.00%$
$\color{green}25/25$
$\color{green}+0.00%$
$\color{green}6/6$
$\color{green}+0.00%$
$\color{green}466/466$
$\color{green}+0.00%$

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

@iampratik13
Copy link
Contributor 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
var out;
var v;

// Note: test cases adapted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf for float32.
Copy link
Member

Choose a reason for hiding this comment

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

@iampratik13 You say that these test cases were adapted from Figure 6. How were they adapted?

Comment on lines +193 to +196
re1 = pow( 2.0, -80.0 );
im1 = pow( 2.0, -20.0 );
re2 = pow( 2.0, -130.0 );
im2 = pow( 2.0, -140.0 );
Copy link
Member

Choose a reason for hiding this comment

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

@iampratik13 How did you derive these test cases? Can you provide the mathematics?

q = cdiv( z1, z2 );

idx = bitdiff( real( q ), pow( 2.0, -127.0 ) );
t.ok( idx === -1 || idx >= 2, 'real component has expected binary representation' );
Copy link
Member

Choose a reason for hiding this comment

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

@iampratik13 Do you see any problems with this sort of assertion?

t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' );

z1 = new Complex64( 1.0, 0.5 );
z2 = new Complex64( float64ToFloat32( 1.0e38 ), float64ToFloat32( 5.0e37 ) );
Copy link
Member

Choose a reason for hiding this comment

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

Why are we wrapping these values in an f32 call before passing to Complex64?

z1 = new Complex64( 1.0e-38, 2.0e-38 );
z2 = new Complex64( 1.0, 2.0 );
v = cdiv( z1, z2 );
expected = [ 9.999999350456404e-39, 0.0 ];
Copy link
Member

Choose a reason for hiding this comment

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

How did you compute this value (and similar values below)?

q = cdiv( z1, 1, 0, z2, 1, 0, new Float32Array( 2 ), 1, 0 );

idx = bitdiff( q[ 0 ], pow( 2.0, -127.0 ) );
t.ok( idx === -1 || idx >= 0, 'real component has expected binary representation' );
Copy link
Member

Choose a reason for hiding this comment

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

@iampratik13 See any problems with this assertion?

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.

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

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

Labels

Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants