Skip to content

Conversation

@Amansingh0807
Copy link
Contributor

Resolves None

Description

What is the purpose of this pull request?

This pull request:

  • This PR adds math/base/special/roundnf.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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

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


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Dec 27, 2025
@Amansingh0807 Amansingh0807 marked this pull request as draft December 27, 2025 07:06
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Dec 27, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 27, 2025

Coverage Report

Package Statements Branches Functions Lines
math/base/special/roundnf $\color{red}269/271$
$\color{green}+2.67%$
$\color{red}22/23$
$\color{green}+5.72%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{red}269/271$
$\color{green}+2.67%$

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

@Amansingh0807 Amansingh0807 force-pushed the feat-math-base-special-roundnf branch from 4a794b6 to 15255de Compare December 27, 2025 08:11
@Amansingh0807 Amansingh0807 marked this pull request as ready for review December 27, 2025 08:27
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 27, 2025
@Amansingh0807
Copy link
Contributor Author

Amansingh0807 commented Dec 28, 2025

Hi @kgryte !!
I noticed packages like roundn and others include Python, Julia, and R benchmarks for cross-language performance comparison. Should I add these benchmarks for completeness, or are the current JS/Native benchmarks sufficient for this PR?

@anandkaranubc anandkaranubc self-requested a review December 30, 2025 23:27
---
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: 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
    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
---
---
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: 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
    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
    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: 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
---
Copy link
Contributor

@anandkaranubc anandkaranubc left a comment

Choose a reason for hiding this comment

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

This PR needs a lot of cleanup. I think the best approach would be to go through all the comments above and the files again, and check whether it closely resembles what is being done in roundn. I have pushed a few changes, but there are still some remaining. Ping me whenever you need clarification on why certain comments and changes were made.

Comment on lines 30 to 31
* var v = roundnf( 3.141592, -2 );
* // returns 3.140000104904175
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* var v = roundnf( 3.141592, -2 );
* // returns 3.140000104904175
* var v = roundnf( 3.1415927410125732, -2 );
* // returns ~3.14

It’s better to use approximate return values here using ~. If you use exact return values and the implementation changes for this package or the packages it depends on, it will break the linting for these files as well.

* var roundnf = require( '@stdlib/math/base/special/roundnf' );
*
* // If n = 0, `roundnf` behaves like `roundf`:
* var v = roundnf( 3.141592, 0 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* var v = roundnf( 3.141592, 0 );
* var v = roundnf( 3.1415927410125732, 0 );

Keeping the same example as above here too, for consistency.

Comment on lines 40 to 41
* @example
* var roundnf = require( '@stdlib/math/base/special/roundnf' );
Copy link
Contributor

Choose a reason for hiding this comment

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

You only need to use @example once in the index.js file. For more context you can refer to the index.js in roundn.

Comment on lines 23 to 24
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );

You only need the single-precision based packages here.

var roundf = require( '@stdlib/math/base/special/roundf' );
var powf = require( '@stdlib/math/base/special/powf' );
var absf = require( '@stdlib/math/base/special/absf' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );

Comment on lines 36 to 47
* @example
* var v = roundnf( 3.141592, -2 );
* // returns 3.140000104904175
*
* @example
* var v = roundnf( 3.141592, 0 );
* // returns 3.0
*
* @example
* var v = roundnf( 1234.56, 2 );
* // returns 1200.0
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @example
* var v = roundnf( 3.141592, -2 );
* // returns 3.140000104904175
*
* @example
* var v = roundnf( 3.141592, 0 );
* // returns 3.0
*
* @example
* var v = roundnf( 1234.56, 2 );
* // returns 1200.0
*/
* @example
* // Round a value to 2 decimal places:
* var v = roundnf( 3.1415927410125732, -2 );
* // returns ~3.14
*
* @example
* // If n = 0, `roundnf` behaves like `roundf`:
* var v = roundnf( 3.1415927410125732, 0 );
* // returns 3.0
*
* @example
* // Round a value to the nearest thousand:
* var v = roundnf( 12368.0, 3 );
* // returns ~12000.0
*/

You have to folllow the same example structure as main.js

Copy link
Contributor

Choose a reason for hiding this comment

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

@Amansingh0807 This entire file needs revision. I would suggest reviewing https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/math/base/special/roundn/test/test.js. Copy over all the tests from that file and modify them accordingly for this package. It seems like you are missing several important tests.

Also, that file uses EPS-based thresholds. Can you use var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' ); here instead?

The same applies to test.native.js as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem the way we do C benchmarking. You will need to refer to what was done in https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/math/base/special/secf/benchmark/c/native/benchmark.c

Copy link
Contributor

Choose a reason for hiding this comment

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

@anandkaranubc anandkaranubc added JavaScript Issue involves or relates to JavaScript. C Issue involves or relates to C. Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Dec 31, 2025
@anandkaranubc
Copy link
Contributor

@Amansingh0807 I just finished reviewing #4881, and the expected changes here are very similar to the changes I recently made in that PR. The best way to update this PR would be to go through that one and follow the same commits.

@Amansingh0807
Copy link
Contributor Author

Hi @anandkaranubc,
Thanks for the review! I've made the necessary changes as per the reviews.
Ready for review!

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. JavaScript Issue involves or relates to JavaScript. Math Issue or pull request specific to math functionality. 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