|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# factorial2f |
| 22 | + |
| 23 | +> Evaluate the [double factorial][double-factorial] function as a single-precision floating-point number. |
| 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 factorial2f = require( '@stdlib/math/base/special/factorial2f' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### factorial2f( n ) |
| 44 | + |
| 45 | +Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var v = factorial2f( 3 ); |
| 49 | +// returns 3 |
| 50 | + |
| 51 | +v = factorial2f( 4 ); |
| 52 | +// returns 8 |
| 53 | + |
| 54 | +v = factorial2f( 10 ); |
| 55 | +// returns 3840 |
| 56 | +``` |
| 57 | + |
| 58 | +If `n > 56`, the function returns `NaN`, as larger [double factorial][double-factorial] values cannot be safely represented in [single-precision floating-point format][ieee754]. |
| 59 | + |
| 60 | +```javascript |
| 61 | +var v = factorial2f( 57 ); |
| 62 | +// returns Infinity |
| 63 | +``` |
| 64 | + |
| 65 | +If not provided a nonnegative integer value, the function returns `NaN`. |
| 66 | + |
| 67 | +```javascript |
| 68 | +var v = factorial2f( 3.14 ); |
| 69 | +// returns NaN |
| 70 | + |
| 71 | +v = factorial2f( -1 ); |
| 72 | +// returns NaN |
| 73 | +``` |
| 74 | + |
| 75 | +If provided `NaN`, the function returns `NaN`. |
| 76 | + |
| 77 | +```javascript |
| 78 | +var v = factorial2f( NaN ); |
| 79 | +// returns NaN |
| 80 | +``` |
| 81 | + |
| 82 | +</section> |
| 83 | + |
| 84 | +<!-- /.usage --> |
| 85 | + |
| 86 | +<section class="examples"> |
| 87 | + |
| 88 | +## Examples |
| 89 | + |
| 90 | +<!-- eslint no-undef: "error" --> |
| 91 | + |
| 92 | +```javascript |
| 93 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 94 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 95 | +var factorial2f = require( '@stdlib/math/base/special/factorial2f' ); |
| 96 | + |
| 97 | +var x = discreteUniform( 10, 0, 56, { |
| 98 | + 'dtype': 'int32' |
| 99 | +}); |
| 100 | + |
| 101 | +logEachMap( 'factorial2f(%d) = %0.1f', x, factorial2f ); |
| 102 | +``` |
| 103 | + |
| 104 | +</section> |
| 105 | + |
| 106 | +<!-- /.examples --> |
| 107 | + |
| 108 | +<!-- C interface documentation. --> |
| 109 | + |
| 110 | +* * * |
| 111 | + |
| 112 | +<section class="c"> |
| 113 | + |
| 114 | +## C APIs |
| 115 | + |
| 116 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 117 | + |
| 118 | +<section class="intro"> |
| 119 | + |
| 120 | +</section> |
| 121 | + |
| 122 | +<!-- /.intro --> |
| 123 | + |
| 124 | +<!-- C usage documentation. --> |
| 125 | + |
| 126 | +<section class="usage"> |
| 127 | + |
| 128 | +### Usage |
| 129 | + |
| 130 | +```c |
| 131 | +#include "stdlib/math/base/special/factorial2f.h" |
| 132 | +``` |
| 133 | + |
| 134 | +#### stdlib_base_factorial2f( n ) |
| 135 | + |
| 136 | +Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number. |
| 137 | + |
| 138 | +```c |
| 139 | +float out = stdlib_base_factorial2f( 3 ); |
| 140 | +// returns 3.0f |
| 141 | +``` |
| 142 | + |
| 143 | +The function accepts the following arguments: |
| 144 | + |
| 145 | +- **n**: `[in] int32_t` input value. |
| 146 | + |
| 147 | +```c |
| 148 | +float stdlib_base_factorial2f( const int32_t n ); |
| 149 | +``` |
| 150 | +
|
| 151 | +</section> |
| 152 | +
|
| 153 | +<!-- /.usage --> |
| 154 | +
|
| 155 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 156 | +
|
| 157 | +<section class="notes"> |
| 158 | +
|
| 159 | +</section> |
| 160 | +
|
| 161 | +<!-- /.notes --> |
| 162 | +
|
| 163 | +<!-- C API usage examples. --> |
| 164 | +
|
| 165 | +<section class="examples"> |
| 166 | +
|
| 167 | +### Examples |
| 168 | +
|
| 169 | +```c |
| 170 | +#include "stdlib/math/base/special/factorial2f.h" |
| 171 | +#include <stdio.h> |
| 172 | +#include <stdint.h> |
| 173 | +
|
| 174 | +int main( void ) { |
| 175 | + const int32_t x[] = { 1, 10, 50, 56, 57 }; |
| 176 | +
|
| 177 | + float b; |
| 178 | + int i; |
| 179 | + for ( i = 0; i < 5; i++ ) { |
| 180 | + b = stdlib_base_factorial2f( x[ i ] ); |
| 181 | + printf ( "factorial2f(%d) = %f\n", x[ i ], b ); |
| 182 | + } |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +</section> |
| 187 | + |
| 188 | +<!-- /.examples --> |
| 189 | + |
| 190 | +</section> |
| 191 | + |
| 192 | +<!-- /.c --> |
| 193 | + |
| 194 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 195 | + |
| 196 | +<section class="related"> |
| 197 | + |
| 198 | +</section> |
| 199 | + |
| 200 | +<!-- /.related --> |
| 201 | + |
| 202 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 203 | + |
| 204 | +<section class="links"> |
| 205 | + |
| 206 | +[double-factorial]: https://en.wikipedia.org/wiki/Double_factorial |
| 207 | + |
| 208 | +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 |
| 209 | + |
| 210 | +<!-- <related-links> --> |
| 211 | + |
| 212 | +<!-- </related-links> --> |
| 213 | + |
| 214 | +</section> |
| 215 | + |
| 216 | +<!-- /.links --> |
0 commit comments