Skip to content

Commit d92269d

Browse files
committed
chore: apply suggestions from review
--- 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: na - task: lint_repl_help status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f934da8 commit d92269d

File tree

11 files changed

+67
-77
lines changed

11 files changed

+67
-77
lines changed

lib/node_modules/@stdlib/math/base/special/rising-factorial/README.md

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

2121
# Rising Factorial
2222

23-
Compute the [rising factorial][rising-and-rising-factorials].
23+
> Compute the [rising factorial][falling-and-rising-factorials].
2424
2525
<section class="intro">
2626

@@ -38,7 +38,7 @@ var risingFactorial = require( '@stdlib/math/base/special/rising-factorial' );
3838

3939
#### risingFactorial( x, n )
4040

41-
Evaluates the [rising factorial][rising-and-rising-factorials] of `x` and `n`.
41+
Evaluates the [rising factorial][falling-and-rising-factorials] of `x` and `n`.
4242

4343
```javascript
4444
var v = risingFactorial( 0.9, 5 );
@@ -128,7 +128,7 @@ for ( i = 0; i < 100; i++ ) {
128128

129129
#### stdlib_base_rising_factorial( x, n )
130130

131-
Evaluates the rising factorial of `x` and `n`.
131+
Evaluates the [rising factorial][falling-and-rising-factorials] of `x` and `n`.
132132

133133
```c
134134
double out = stdlib_base_rising_factorial( 0.9, 5 );
@@ -148,26 +148,37 @@ double stdlib_base_rising_factorial( const double x, const int32_t n );
148148
```
149149
150150
</section>
151+
151152
<!-- /.usage -->
153+
152154
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
155+
153156
<section class="notes">
157+
154158
</section>
159+
155160
<!-- /.notes -->
161+
156162
<!-- C API usage examples. -->
163+
157164
<section class="examples">
165+
158166
### Examples
167+
159168
```c
160169
#include "stdlib/math/base/special/rising_factorial.h"
161170
#include <stdio.h>
162171
#include <stdint.h>
172+
163173
int main( void ) {
164174
const double x[] = { -10.0, -7.78, -5.56, -3.33, -1.11, 1.11, 3.33, 5.56, 7.78, 10.0 };
165175
const int32_t n[] = { 5, 4, 3, 2, 1, 0, -1, -2, -3, -4 };
176+
166177
double v;
167178
int i;
168179
for ( i = 0; i < 10; i++ ) {
169180
v = stdlib_base_rising_factorial( x[ i ], n[ i ] );
170-
printf( "x: %lf, n: %d, rising_factorial(x,n): %lf\n", x[ i ], n[ i ], v );
181+
printf( "risingFactorial(%lf, %d) = %lf\n", x[ i ], n[ i ], v );
171182
}
172183
}
173184
```
@@ -188,7 +199,7 @@ int main( void ) {
188199

189200
## See Also
190201

191-
- <span class="package-name">[`@stdlib/math/base/special/rising-factorial`][@stdlib/math/base/special/rising-factorial]</span><span class="delimiter">: </span><span class="description">compute the rising factorial.</span>
202+
- <span class="package-name">[`@stdlib/math/base/special/falling-factorial`][@stdlib/math/base/special/falling-factorial]</span><span class="delimiter">: </span><span class="description">compute the falling factorial.</span>
192203

193204
</section>
194205

@@ -198,11 +209,11 @@ int main( void ) {
198209

199210
<section class="links">
200211

201-
[rising-and-rising-factorials]: https://en.wikipedia.org/wiki/rising_and_rising_factorials
212+
[falling-and-rising-factorials]: https://en.wikipedia.org/wiki/Falling_and_rising_factorials
202213

203214
<!-- <related-links> -->
204215

205-
[@stdlib/math/base/special/rising-factorial]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/rising-factorial
216+
[@stdlib/math/base/special/falling-factorial]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/falling-factorial
206217

207218
<!-- </related-links> -->
208219

lib/node_modules/@stdlib/math/base/special/rising-factorial/benchmark/benchmark.native.js

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -39,18 +39,18 @@ var opts = {
3939

4040
// MAIN //
4141

42-
bench( pkg, opts, function benchmark( b ) {
42+
bench( pkg+'::native', opts, function benchmark( b ) {
4343
var x;
4444
var n;
4545
var y;
4646
var i;
4747

48-
x = randu( 100, 1.0, 41.0 );
49-
n = discreteUniform( 100, 0, 40 );
48+
x = uniform( 100, -50.0, 50.0 );
49+
n = discreteUniform( 100, -50, 50 );
5050

5151
b.tic();
5252
for ( i = 0; i < b.iterations; i++ ) {
53-
y = risingFactorial( x[ i % x.length ], n[ i % n.length ] );
53+
y = risingFactorial( x[ i%x.length ], n[ i%n.length ] );
5454
if ( isnan( y ) ) {
5555
b.fail( 'should not return NaN' );
5656
}

lib/node_modules/@stdlib/math/base/special/rising-factorial/benchmark/c/native/benchmark.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "stdlib/math/base/special/rising_factorial.h"
2020
#include <stdlib.h>
21+
#include <stdint.h>
2122
#include <stdio.h>
2223
#include <math.h>
2324
#include <time.h>
@@ -98,13 +99,13 @@ static double benchmark( void ) {
9899
int i;
99100

100101
for ( i = 0; i < 100; i++ ) {
101-
x[ i ] = ( 40.0 * rand_double() ) + 1.0;
102-
n[ i ] = (int32_t)( 41.0 * rand_double() );
102+
x[ i ] = ( 100.0*rand_double() ) - 50.0;
103+
n[ i ] = (int32_t)( 50.0*rand_double() );
103104
}
104105

105106
t = tic();
106107
for ( i = 0; i < ITERATIONS; i++ ) {
107-
y = stdlib_base_rising_factorial( x[ i % 100 ], n[ i % 100 ] );
108+
y = stdlib_base_rising_factorial( x[ i%100 ], n[ i%100 ] );
108109
if ( y != y ) {
109110
printf( "should return a nonnegative integer\n" );
110111
break;

lib/node_modules/@stdlib/math/base/special/rising-factorial/examples/c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ int main( void ) {
2828
int i;
2929
for ( i = 0; i < 10; i++ ) {
3030
v = stdlib_base_rising_factorial( x[ i ], n[ i ] );
31-
printf( "x: %lf, n: %d, rising_factorial(x,n): %lf\n", x[ i ], n[ i ], v );
31+
printf( "risingFactorial(%lf, %d) = %lf\n", x[ i ], n[ i ], v );
3232
}
3333
}

lib/node_modules/@stdlib/math/base/special/rising-factorial/examples/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/array/uniform' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
2222
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
23+
var logEachMap = require( '@stdlib/console/log-each-map' );
2324
var risingFactorial = require( './../lib' );
2425

25-
var n;
26-
var x;
27-
var i;
26+
var opts = {
27+
'dtype': 'float64'
28+
};
29+
var x = uniform( 100, -20.0, 20.0, opts );
30+
var n = discreteUniform( 100, -20, 20, opts );
2831

29-
x = randu( 100, -20.0, 20.0 );
30-
n = discreteUniform( 100, 0, 20 );
31-
32-
for ( i = 0; i < 100; i++ ) {
33-
console.log( 'risingFactorial(%d,%d) = %d', x[ i ], n[ i ], risingFactorial( x[ i ], n[ i ] ) );
34-
}
32+
logEachMap( 'risingFactorial(%0.4f, %d) = %0.4f', x, n, risingFactorial );

lib/node_modules/@stdlib/math/base/special/rising-factorial/lib/native.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17-
*
18-
*
19-
* ## Notice
20-
*
21-
* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_64_0/boost/math/special_functions/factorials.hpp}. The implementation has been modified for JavaScript.
22-
*
23-
* ```text
24-
* (C) Copyright John Maddock 2006, 2010.
25-
*
26-
* Use, modification and distribution are subject to the
27-
* Boost Software License, Version 1.0. (See accompanying file
28-
* LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
29-
* ```
3017
*/
3118

3219
'use strict';
@@ -41,20 +28,7 @@ var addon = require( './../src/addon.node' );
4128
/**
4229
* Computes the rising factorial of `x` and `n`.
4330
*
44-
* ## Notes
45-
*
46-
* - The rising factorial is defined as
47-
*
48-
* ```tex
49-
* \operatorname{risingFactorial}(x, n) = x (x-1) (x-2) (x-3) \ldots (x-n+1)
50-
* ```
51-
*
52-
* or equivalently
53-
*
54-
* ```tex
55-
* \operatorname{risingFactorial}(x, n) = \frac{ \Gamma(x + n) }{ \Gamma(x) };
56-
* ```
57-
*
31+
* @private
5832
* @param {number} x - first function parameter
5933
* @param {integer} n - second function parameter
6034
* @returns {number} function value

lib/node_modules/@stdlib/math/base/special/rising-factorial/manifest.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/binary",
40-
"@stdlib/math/base/assert/is-integer",
4140
"@stdlib/math/base/assert/is-nan",
4241
"@stdlib/math/base/special/gamma-delta-ratio",
4342
"@stdlib/math/base/special/falling-factorial"
@@ -54,7 +53,6 @@
5453
"libraries": [],
5554
"libpath": [],
5655
"dependencies": [
57-
"@stdlib/math/base/assert/is-integer",
5856
"@stdlib/math/base/assert/is-nan",
5957
"@stdlib/math/base/special/gamma-delta-ratio",
6058
"@stdlib/math/base/special/falling-factorial"
@@ -71,7 +69,6 @@
7169
"libraries": [],
7270
"libpath": [],
7371
"dependencies": [
74-
"@stdlib/math/base/assert/is-integer",
7572
"@stdlib/math/base/assert/is-nan",
7673
"@stdlib/math/base/special/gamma-delta-ratio",
7774
"@stdlib/math/base/special/falling-factorial"

lib/node_modules/@stdlib/math/base/special/rising-factorial/src/addon.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919
#include "stdlib/math/base/special/rising_factorial.h"
2020
#include "stdlib/math/base/napi/binary.h"
2121

22-
// cppcheck-suppress shadowFunction
2322
STDLIB_MATH_BASE_NAPI_MODULE_DI_D( stdlib_base_rising_factorial )

lib/node_modules/@stdlib/math/base/special/rising-factorial/src/main.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* ## Notice
2020
*
21-
* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_64_0/boost/math/special_functions/factorials.hpp}. The implementation has been modified according to project conventions.
21+
* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_64_0/boost/math/special_functions/factorials.hpp}. The implementation has been modified according to stdlib conventions.
2222
*
2323
* ```text
2424
* (C) Copyright John Maddock 2006, 2010.
@@ -33,6 +33,8 @@
3333
#include "stdlib/math/base/assert/is_nan.h"
3434
#include "stdlib/math/base/special/gamma_delta_ratio.h"
3535
#include "stdlib/math/base/special/falling_factorial.h"
36+
#include <stdint.h>
37+
#include <stdbool.h>
3638

3739
/**
3840
* Computes the rising factorial of `x` and `n`.
@@ -51,9 +53,9 @@
5153
* \operatorname{stdlib_base_rising_factorial}(x, n) = \frac{ \Gamma(x + n) }{ \Gamma(x) };
5254
* ```
5355
*
54-
* @param {number} x - first function parameter
55-
* @param {integer} n - second function parameter
56-
* @returns {number} function value
56+
* @param x first function parameter
57+
* @param n second function parameter
58+
* @return function value
5759
*
5860
* @example
5961
* double v = stdlib_base_rising_factorial( 0.9, 5 );
@@ -77,19 +79,20 @@ double stdlib_base_rising_factorial( const double x, const int32_t n ) {
7779
double xc;
7880
bool inv;
7981

80-
if ( stdlib_base_is_nan( x ) || !stdlib_base_is_integer( n ) ) {
82+
if ( stdlib_base_is_nan( x ) ) {
8183
return 0.0 / 0.0; // NaN
8284
}
8385
nc = n;
8486
xc = x;
8587
inv = false;
8688
if ( xc < 0.0 ) {
87-
if ( nc < 0.0 ) {
89+
// For `x < 0`, we really have a falling factorial, modulo a possible change of sign. Note that the falling factorial isn't defined for negative `n`, so we'll get rid of that case first:
90+
if ( nc < 0 ) {
8891
xc += nc;
8992
nc = -nc;
9093
inv = true;
9194
}
92-
result = ( ( nc & 1 ) ? -1.0 : 1.0 ) * stdlib_base_falling_factorial( -xc, nc );
95+
result = ( (nc&1) ? -1.0 : 1.0 ) * stdlib_base_falling_factorial( -xc, nc );
9396
if ( inv ) {
9497
result = 1.0 / result;
9598
}
@@ -104,11 +107,10 @@ double stdlib_base_rising_factorial( const double x, const int32_t n ) {
104107
}
105108
return 0.0;
106109
}
107-
if ( ( xc < 1.0 ) && ( xc + nc < 0.0 ) ) {
110+
if ( ( xc < 1.0 ) && ( xc+nc < 0.0 ) ) {
108111
result = stdlib_base_gamma_delta_ratio( 1.0 - xc, -nc );
109-
return ( nc & 1 ) ? -result : result;
112+
return ( nc&1 ) ? -result : result;
110113
}
111-
112114
// We don't optimize this for small `nc`, because `stdlib_base_gamma_delta_ratio` is already optimized for that use case:
113115
return 1.0 / stdlib_base_gamma_delta_ratio( xc, nc );
114116
}

lib/node_modules/@stdlib/math/base/special/rising-factorial/test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2425
var abs = require( '@stdlib/math/base/special/abs' );
2526
var EPS = require( '@stdlib/constants/float64/eps' );
2627
var risingFactorial = require( './../lib' );

0 commit comments

Comments
 (0)