Skip to content

feat: add math/base/special/gammaf#10805

Open
nirmaljb wants to merge 3 commits intostdlib-js:developfrom
nirmaljb:feat/gammaf
Open

feat: add math/base/special/gammaf#10805
nirmaljb wants to merge 3 commits intostdlib-js:developfrom
nirmaljb:feat/gammaf

Conversation

@nirmaljb
Copy link
Contributor

@nirmaljb nirmaljb commented Mar 8, 2026


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

Progresses #649

Description

What is the purpose of this pull request?

This pull request:

  • add Gammaf implementation (JavaScript + C)
  • Test, Fixtures, Benchmark, Examples

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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

---
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: passed
  - 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
---
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Mar 8, 2026
@nirmaljb
Copy link
Contributor Author

nirmaljb commented Mar 8, 2026

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Mar 8, 2026
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Mar 8, 2026
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Mar 8, 2026

Coverage Report

Package Statements Branches Functions Lines
math/base/special/gammaf $\color{red}548/558$
$\color{green}+98.21%$
$\color{red}52/57$
$\color{green}+91.23%$
$\color{green}6/6$
$\color{green}+100.00%$
$\color{red}548/558$
$\color{green}+98.21%$

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

xc = q;
}
// if ( xc >= 10.0f ) {
// z = stirlingApprox( xc );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Followed the cephes reference just like how it's followed in gamma. Where they have a fall-through, which cobbles the Stirling result.

The CI/CD marked it as an issue, so I had to comment it out. Anyways, Stirling result is a wasted compute.

t.end();
});

tape( 'the function uses a small value approximation for tiny positive x', function test( t ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the reference, the negative recurrence loop is commented out. All negative inputs are handled by the reflection formula.
So,
Only the positive-side test matters, just need to verify smallApprox is triggered when 0 < x < 1e-4 during the positive recurrence.

@nirmaljb
Copy link
Contributor Author

nirmaljb commented Mar 8, 2026

The R fixture runner. R passes lint locally with a newer R version, but the CI runner has R 3.5.3, which is too old to install lintr (requires R ≥ 3.6). This appears to be an environment issue rather than a code issue; the same failure would occur for any package that includes an R file.

I also put it on zulip: #dev-questions > R lint CI failure — lintr not available for R 3.5.3


w = f32( 1.0 / x );
w = f32( 1.0 + f32( w * polyval( w ) ) );
y = f32( exp( -x ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using exp with float64tofloat32 wrapper on.
Until expf gets merged, this is the workaround.

@rautelaKamal
Copy link
Contributor

Hey @nirmaljb! I noticed the CI check Lint Changed Files is failing. I checked out your branch locally and found a few strict JavaScript linting errors (ESLint) in lib/main.js. stdlib is very strict about spaces inside parentheses and around operators!

Here are the fixes needed in lib/main.js:

  1. Line 104:
    // Change:
    if ( ( isIntegerf( x ) && x < 0 )|| isnanf( x ) || x === NINF ) {
    // To:
    if ( ( isIntegerf( x ) && x < 0 ) || isnanf( x ) || x === NINF ) {
  2. Line 125:
    // Change:
    if ( (p&1) === 0 ) {
    // To:
    if ( ( p & 1 ) === 0 ) {
  3. Line 150:
    // Change:
    z = stirlingApprox(x);
    // To:
    z = stirlingApprox( x );
  4. Line 179:
    // Change:
    z = f32( ONE/z );
    // To:
    z = f32( ONE / z );

Also, in lib/polyval_p.js and lib/polyval_s.js, the expressions like (x * ( need spaces inside the parentheses: ( x * (.

Hope this helps you get those CI checks green so this awesome PR can get merged! 🚀

@Neerajpathak07
Copy link
Member

A small advice here to prevent indentation errors in future would be to setup EditorConfig locally which adheres to the indentation rules stated in the already present .editorconfig file in stdlib.

@Neerajpathak07 Neerajpathak07 changed the title feat: add implementation for math/base/special/gammaf feat: add math/base/special/gammaf Mar 9, 2026
@nirmaljb
Copy link
Contributor Author

nirmaljb commented Mar 9, 2026

A small advice here to prevent indentation errors in future would be to setup EditorConfig locally which adheres to the indentation rules stated in the already present .editorconfig file in stdlib.

Actually, I believe I do have EditorConfig set up in my VS Code with the stdlib configuration.
I am not sure what could've gone wrong, but I will look into it.

But, anyways, thank you for the suggestion! @Neerajpathak07

Screenshot 2026-03-09 at 8 14 13 PM

---
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
---
@nirmaljb
Copy link
Contributor Author

nirmaljb commented Mar 9, 2026

@rautelaKamal Thank you for your feedback! I will fix those inconsistencies.

@Neerajpathak07
Copy link
Member

@nirmaljb just a quick heads-up the Lint error flagged here is for your fixtures/runner.py file. Would be better to take a look at that and compare it against a similar upstream implementation of math package which utilizes R to generate fixtures!!!

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

Labels

Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants