Skip to content

Commit 1de9166

Browse files
committed
feat: add math/base/special/gamma-lanczos-sum-expg-scaledf
--- 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: 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: na - task: lint_license_headers status: passed ---
1 parent b80419f commit 1de9166

File tree

20 files changed

+113
-221
lines changed

20 files changed

+113
-221
lines changed

lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# Gamma Scaled Lanczos Sum
2222

23-
> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function].
23+
> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function] as a single precision floating-point number.
2424
2525
<section class="intro">
2626

@@ -32,26 +32,16 @@ The [Lanczos approximation][lanczos-approximation] for the [gamma function][gamm
3232
\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)
3333
```
3434

35-
<!-- <div class="equation" align="center" data-raw-text="\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)" data-equation="eq:lanczos_approximation">
36-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled/docs/img/equation_lanczos_approximation.svg" alt="Lanczos approximation for gamma function.">
37-
<br>
38-
</div> -->
39-
4035
<!-- </equation> -->
4136

42-
where `g` is an [arbitrary constant][@stdlib/constants/float64/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. The scaled Lanczos sum is given by
37+
where `g` is an [arbitrary constant][@stdlib/constants/float32/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. The scaled Lanczos sum is given by
4338

4439
<!-- <equation class="equation" label="eq:scaled_lanczos_sum" align="center" raw="L_g(n) \cdot \exp(-g)" alt="Scaled Lanczos sum."> -->
4540

4641
```math
4742
L_g(n) \cdot \exp(-g)
4843
```
4944

50-
<!-- <div class="equation" align="center" data-raw-text="L_g(n) \cdot \exp(-g)" data-equation="eq:scaled_lanczos_sum">
51-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled/docs/img/equation_scaled_lanczos_sum.svg" alt="Scaled Lanczos sum.">
52-
<br>
53-
</div> -->
54-
5545
<!-- </equation> -->
5646

5747
</section>
@@ -62,23 +52,27 @@ L_g(n) \cdot \exp(-g)
6252

6353
## Usage
6454

55+
<!-- eslint-disable id-length -->
56+
6557
```javascript
66-
var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' );
58+
var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' );
6759
```
6860

6961
#### gammaLanczosSumExpGScaledf( x )
7062

71-
Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 10.900511`).
63+
Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number.
64+
65+
<!-- eslint-disable id-length -->
7266

7367
```javascript
7468
var v = gammaLanczosSumExpGScaledf( 4.0 );
75-
// returns ~0.018
69+
// returns ~0.748
7670

7771
v = gammaLanczosSumExpGScaledf( -1.5 );
78-
// returns ~25.337
72+
// returns ~0.193
7973

8074
v = gammaLanczosSumExpGScaledf( -0.5 );
81-
// returns ~-12.911
75+
// returns ~-0.558
8276

8377
v = gammaLanczosSumExpGScaledf( 0.5 );
8478
// returns ~1.772
@@ -100,13 +94,15 @@ v = gammaLanczosSumExpGScaledf( NaN );
10094

10195
<!-- eslint no-undef: "error" -->
10296

97+
<!-- eslint-disable id-length -->
98+
10399
```javascript
104100
var uniform = require( '@stdlib/random/array/uniform' );
105101
var logEachMap = require( '@stdlib/console/log-each-map' );
106-
var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' );
102+
var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' );
107103

108104
var opts = {
109-
'dtype': 'float64'
105+
'dtype': 'float32'
110106
};
111107
var x = uniform( 100, -10.0, 10.0, opts );
112108

@@ -140,27 +136,27 @@ logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammaLanczosSumExpGScaledf );
140136
### Usage
141137

142138
```c
143-
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h"
139+
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h"
144140
```
145141

146142
#### stdlib_base_gamma_lanczos_sum_expg_scaledf( x )
147143

148-
Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 10.900511`).
144+
Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number.
149145

150146
```c
151-
double out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0 );
152-
// returns ~0.018
147+
float out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0f );
148+
// returns ~0.018f
153149

154-
out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5 );
155-
// returns ~25.337
150+
out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5f );
151+
// returns ~25.337f
156152
```
157153

158154
The function accepts the following arguments:
159155

160-
- **x**: `[in] double` input value.
156+
- **x**: `[in] float` input value.
161157

162158
```c
163-
double stdlib_base_gamma_lanczos_sum_expg_scaledf( const double x );
159+
float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x );
164160
```
165161
166162
</section>
@@ -182,18 +178,17 @@ double stdlib_base_gamma_lanczos_sum_expg_scaledf( const double x );
182178
### Examples
183179
184180
```c
185-
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h"
186-
#include <stdlib.h>
181+
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h"
187182
#include <stdio.h>
188183
189184
int main( void ) {
190-
const double x[] = { 4.0, -1.5, -0.5, 0.5 };
185+
const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f };
191186
192-
double y;
187+
float y;
193188
int i;
194189
for ( i = 0; i < 4; i++ ) {
195190
y = stdlib_base_gamma_lanczos_sum_expg_scaledf( x[ i ] );
196-
printf( "gamma_lanczos_sum_expg_scaled(%lf) = %lf\n", x[ i ], y );
191+
printf( "gamma_lanczos_sum_expg_scaledf(%f) = %f\n", x[ i ], y );
197192
}
198193
}
199194
```
@@ -210,13 +205,6 @@ int main( void ) {
210205

211206
<section class="related">
212207

213-
* * *
214-
215-
## See Also
216-
217-
- <span class="package-name">[`@stdlib/math/base/special/gamma`][@stdlib/math/base/special/gamma]</span><span class="delimiter">: </span><span class="description">gamma function.</span>
218-
- <span class="package-name">[`@stdlib/math/base/special/gamma-lanczos-sum`][@stdlib/math/base/special/gamma-lanczos-sum]</span><span class="delimiter">: </span><span class="description">calculate the Lanczos sum for the approximation of the gamma function.</span>
219-
220208
</section>
221209

222210
<!-- /.related -->
@@ -225,18 +213,14 @@ int main( void ) {
225213

226214
<section class="links">
227215

228-
[@stdlib/constants/float64/gamma-lanczos-g]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float64/gamma-lanczos-g
216+
[@stdlib/constants/float32/gamma-lanczos-g]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float32/gamma-lanczos-g
229217

230218
[gamma-function]: https://en.wikipedia.org/wiki/Gamma_function
231219

232220
[lanczos-approximation]: https://en.wikipedia.org/wiki/Lanczos_approximation
233221

234222
<!-- <related-links> -->
235223

236-
[@stdlib/math/base/special/gamma]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma
237-
238-
[@stdlib/math/base/special/gamma-lanczos-sum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma-lanczos-sum
239-
240224
<!-- </related-links> -->
241225

242226
</section>

lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var uniform = require( '@stdlib/random/array/uniform' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var gammaLanczosSumExpGScaledf = require( './../lib' );
2828

@@ -34,17 +34,19 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = uniform( 100, -50.0, 50.0 );
37+
x = uniform( 100, -50.0, 50.0, {
38+
'dtype': 'float32'
39+
});
3840

3941
b.tic();
4042
for ( i = 0; i < b.iterations; i++ ) {
4143
y = gammaLanczosSumExpGScaledf( x[ i%x.length ] );
42-
if ( isnan( y ) ) {
44+
if ( isnanf( y ) ) {
4345
b.fail( 'should not return NaN' );
4446
}
4547
}
4648
b.toc();
47-
if ( isnan( y ) ) {
49+
if ( isnanf( y ) ) {
4850
b.fail( 'should not return NaN' );
4951
}
5052
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.native.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/array/uniform' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

@@ -43,17 +43,19 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = uniform( 100, -50.0, 50.0 );
46+
x = uniform( 100, -50.0, 50.0, {
47+
'dtype': 'float32'
48+
});
4749

4850
b.tic();
4951
for ( i = 0; i < b.iterations; i++ ) {
5052
y = gammaLanczosSumExpGScaledf( x[ i%x.length ] );
51-
if ( isnan( y ) ) {
53+
if ( isnanf( y ) ) {
5254
b.fail( 'should not return NaN' );
5355
}
5456
}
5557
b.toc();
56-
if ( isnan( y ) ) {
58+
if ( isnanf( y ) ) {
5759
b.fail( 'should not return NaN' );
5860
}
5961
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h"
19+
#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222
#include <math.h>
2323
#include <time.h>
2424
#include <sys/time.h>
2525

26-
#define NAME "gamma_lanczos_sum_expg_scaled"
26+
#define NAME "gamma_lanczos_sum_expg_scaledf"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -79,9 +79,9 @@ static double tic( void ) {
7979
*
8080
* @return random number
8181
*/
82-
static double rand_double( void ) {
82+
static float rand_float( void ) {
8383
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
return (float)r / ( (float)RAND_MAX + 1.0f );
8585
}
8686

8787
/**
@@ -91,13 +91,13 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x[ 100 ];
95-
double y;
94+
float x[ 100 ];
9695
double t;
96+
float y;
9797
int i;
9898

9999
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 100.0 * rand_double() ) - 50.0;
100+
x[ i ] = ( 100.0f*rand_float() ) - 50.0f;
101101
}
102102

103103
t = tic();

lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)