Skip to content

Commit 9e94d1f

Browse files
committed
feat: temp commit
1 parent 036ceeb commit 9e94d1f

File tree

28 files changed

+2230
-0
lines changed

28 files changed

+2230
-0
lines changed
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# factorial2
22+
23+
> [Double factorial][double-factorial] function.
24+
25+
<section class="intro">
26+
27+
The [double factorial][double-factorial] of a number `n`, denoted `n!!`, is defined as the product of all the positive integers up to `n` that have the same parity (odd or even) as `n`.
28+
29+
Thus, for example, `5!!` is `5 * 3 * 1 = 15` and `8!!` is `8 * 6 * 4 * 2 = 384`.
30+
31+
</section>
32+
33+
<!-- /.intro -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var factorial2 = require( '@stdlib/math/base/special/factorial2' );
41+
```
42+
43+
#### factorial2( n )
44+
45+
Evaluates the [double factorial][double-factorial] of `n`.
46+
47+
```javascript
48+
var v = factorial2( 2 );
49+
// returns 2
50+
51+
v = factorial2( 3 );
52+
// returns 3
53+
54+
v = factorial2( 0 );
55+
// returns 1
56+
57+
v = factorial2( 4 );
58+
// returns 8
59+
60+
v = factorial2( 5 );
61+
// returns 15
62+
63+
v = factorial2( NaN );
64+
// returns NaN
65+
66+
v = factorial2( 301 );
67+
// returns Infinity
68+
```
69+
70+
</section>
71+
72+
<!-- /.usage -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var oneTo = require( '@stdlib/array/base/one-to' );
82+
var factorial2 = require( '@stdlib/math/base/special/factorial2' );
83+
84+
var values = oneTo( 300 );
85+
86+
var i;
87+
for ( i = 0; i < values.length; i++ ) {
88+
console.log( 'f(%d): %d', values[ i ], factorial2( values[ i ] ) );
89+
}
90+
```
91+
92+
</section>
93+
94+
<!-- /.examples -->
95+
96+
<!-- C interface documentation. -->
97+
98+
* * *
99+
100+
<section class="c">
101+
102+
## C APIs
103+
104+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
105+
106+
<section class="intro">
107+
108+
</section>
109+
110+
<!-- /.intro -->
111+
112+
<!-- C usage documentation. -->
113+
114+
<section class="usage">
115+
116+
### Usage
117+
118+
```c
119+
#include "stdlib/math/base/special/factorial2.h"
120+
```
121+
122+
#### stdlib_base_factorial2( n )
123+
124+
Evaluates the [double factorial][double-factorial] of `n`.
125+
126+
```c
127+
double out = stdlib_base_factorial2( 3 );
128+
// returns 3
129+
```
130+
131+
The function accepts the following arguments:
132+
133+
- **n**: `[in] int32_t` input value.
134+
135+
```c
136+
double stdlib_base_factorial2( const int32_t n );
137+
```
138+
139+
</section>
140+
141+
<!-- /.usage -->
142+
143+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
144+
145+
<section class="notes">
146+
147+
</section>
148+
149+
<!-- /.notes -->
150+
151+
<!-- C API usage examples. -->
152+
153+
<section class="examples">
154+
155+
### Examples
156+
157+
```c
158+
#include "stdlib/math/base/special/factorial2.h"
159+
#include <stdio.h>
160+
#include <stdint.h>
161+
162+
int main( void ) {
163+
const int32_t x[] = { 1, 10, 1, 301, 302 };
164+
165+
double b;
166+
int i;
167+
for ( i = 0; i < 5; i++ ){
168+
b = stdlib_base_factorial2( x[ i ] );
169+
printf ( "factorial2(%d) = %lf\n", x[ i ], b );
170+
}
171+
}
172+
```
173+
174+
</section>
175+
176+
<!-- /.examples -->
177+
178+
</section>
179+
180+
<!-- /.c -->
181+
182+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
183+
184+
<section class="related">
185+
186+
* * *
187+
188+
## See Also
189+
190+
- <span class="package-name">[`@stdlib/math/base/special/factorial`][@stdlib/math/base/special/factorial]</span><span class="delimiter">: </span><span class="description">evaluate a factorial.</span>
191+
192+
</section>
193+
194+
<!-- /.related -->
195+
196+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
197+
198+
<section class="links">
199+
200+
[double-factorial]: https://en.wikipedia.org/wiki/Double_factorial
201+
202+
<!-- <related-links> -->
203+
204+
[@stdlib/math/base/special/factorial]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/factorial
205+
206+
<!-- </related-links> -->
207+
208+
</section>
209+
210+
<!-- /.links -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pkg = require( './../package.json' ).name;
26+
var factorial2 = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var y;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
y = factorial2( i%301 );
38+
if ( isnan( y ) ) {
39+
b.fail( 'should not return NaN' );
40+
}
41+
}
42+
b.toc();
43+
if ( isnan( y ) ) {
44+
b.fail( 'should not return NaN' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var tryRequire = require( '@stdlib/utils/try-require' );
27+
var pkg = require( './../package.json' ).name;
28+
29+
30+
// VARIABLES //
31+
32+
var factorial2 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
33+
var opts = {
34+
'skip': ( factorial2 instanceof Error )
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg+'::native', opts, function benchmark( b ) {
41+
var y;
42+
var i;
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
y = factorial2( i % 301 );
47+
if ( isnan( y ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
}
51+
b.toc();
52+
if ( isnan( y ) ) {
53+
b.fail( 'should not return NaN' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});

0 commit comments

Comments
 (0)