|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# FLOAT64_MAX_SAFE_NTH_FACTORIAL |
| 22 | + |
| 23 | +> Maximum safe nth [factorial][factorial] when stored in [double-precision floating-point][ieee754] format. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +<!-- eslint-disable id-length --> |
| 30 | + |
| 31 | +```javascript |
| 32 | +var FLOAT64_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-factorial' ); |
| 33 | +``` |
| 34 | + |
| 35 | +#### FLOAT64_MAX_SAFE_NTH_FACTORIAL |
| 36 | + |
| 37 | +The maximum [safe][safe-integers] nth [factorial][factorial] when stored in [double-precision floating-point][ieee754] format. |
| 38 | + |
| 39 | +<!-- eslint-disable id-length --> |
| 40 | + |
| 41 | +```javascript |
| 42 | +var bool = ( FLOAT64_MAX_SAFE_NTH_FACTORIAL === 170 ); |
| 43 | +// returns true |
| 44 | +``` |
| 45 | + |
| 46 | +</section> |
| 47 | + |
| 48 | +<!-- /.usage --> |
| 49 | + |
| 50 | +<section class="examples"> |
| 51 | + |
| 52 | +## Examples |
| 53 | + |
| 54 | +<!-- eslint-disable id-length --> |
| 55 | + |
| 56 | +<!-- eslint no-undef: "error" --> |
| 57 | + |
| 58 | +```javascript |
| 59 | +var FLOAT64_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-factorial' ); |
| 60 | + |
| 61 | +function factorial( n ) { |
| 62 | + var a; |
| 63 | + var i; |
| 64 | + |
| 65 | + a = 1; |
| 66 | + for ( i = 2; i <= n; i++ ) { |
| 67 | + a *= i; |
| 68 | + } |
| 69 | + return a; |
| 70 | +} |
| 71 | + |
| 72 | +for ( i = 0; i < 200; i++ ) { |
| 73 | + v = factorial( i ); |
| 74 | + if ( i > FLOAT64_MAX_SAFE_NTH_FACTORIAL ) { |
| 75 | + console.log( 'Unsafe: %d', v ); |
| 76 | + } else { |
| 77 | + console.log( 'Safe: %d', v ); |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +</section> |
| 83 | + |
| 84 | +<!-- /.examples --> |
| 85 | + |
| 86 | +<!-- C interface documentation. --> |
| 87 | + |
| 88 | +* * * |
| 89 | + |
| 90 | +<section class="c"> |
| 91 | + |
| 92 | +## C APIs |
| 93 | + |
| 94 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 95 | + |
| 96 | +<section class="intro"> |
| 97 | + |
| 98 | +</section> |
| 99 | + |
| 100 | +<!-- /.intro --> |
| 101 | + |
| 102 | +<!-- C usage documentation. --> |
| 103 | + |
| 104 | +<section class="usage"> |
| 105 | + |
| 106 | +### Usage |
| 107 | + |
| 108 | +```c |
| 109 | +#include "stdlib/constants/float64/max_safe_nth_factorial.h" |
| 110 | +``` |
| 111 | + |
| 112 | +#### STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FACTORIAL |
| 113 | + |
| 114 | +Macro for the maximum [safe][safe-integers] nth [factorial][factorial] when stored in [double-precision floating-point][ieee754] format. |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.usage --> |
| 119 | + |
| 120 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 121 | + |
| 122 | +<section class="notes"> |
| 123 | + |
| 124 | +</section> |
| 125 | + |
| 126 | +<!-- /.notes --> |
| 127 | + |
| 128 | +<!-- C API usage examples. --> |
| 129 | + |
| 130 | +<section class="examples"> |
| 131 | + |
| 132 | +</section> |
| 133 | + |
| 134 | +<!-- /.examples --> |
| 135 | + |
| 136 | +</section> |
| 137 | + |
| 138 | +<!-- /.c --> |
| 139 | + |
| 140 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 141 | + |
| 142 | +<section class="related"> |
| 143 | + |
| 144 | +</section> |
| 145 | + |
| 146 | +<!-- /.related --> |
| 147 | + |
| 148 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 149 | + |
| 150 | +<section class="links"> |
| 151 | + |
| 152 | +[safe-integers]: http://www.2ality.com/2013/10/safe-integers.html |
| 153 | + |
| 154 | +[factorial]: https://en.wikipedia.org/wiki/Factorial |
| 155 | + |
| 156 | +[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 |
| 157 | + |
| 158 | +<!-- <related-links> --> |
| 159 | + |
| 160 | +<!-- </related-links> --> |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.links --> |
0 commit comments