File tree 3 files changed +10
-11
lines changed
lib/node_modules/@stdlib/math/base/special/factorial
3 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,10 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
24
24
var isInteger = require ( '@stdlib/math/base/assert/is-integer' ) ;
25
25
var gamma = require ( '@stdlib/math/base/special/gamma' ) ;
26
26
var PINF = require ( '@stdlib/constants/float64/pinf' ) ;
27
+ var FLOAT64_MAX_SAFE_NTH_FACTORIAL = require ( '@stdlib/constants/float64/max-safe-nth-factorial' ) ;
27
28
var FACTORIALS = require ( './factorials.json' ) ;
28
29
29
30
30
- // VARIABLES //
31
-
32
- var MAX_FACTORIAL = 170 ; // TODO: consider extracting as a constant
33
-
34
-
35
31
// MAIN //
36
32
37
33
/**
@@ -76,7 +72,7 @@ function factorial( x ) {
76
72
if ( x < 0 ) {
77
73
return NaN ;
78
74
}
79
- if ( x <= MAX_FACTORIAL ) {
75
+ if ( x <= FLOAT64_MAX_SAFE_NTH_FACTORIAL ) {
80
76
return FACTORIALS [ x ] ;
81
77
}
82
78
return PINF ;
Original file line number Diff line number Diff line change 40
40
" @stdlib/math/base/assert/is-nan" ,
41
41
" @stdlib/math/base/assert/is-integer" ,
42
42
" @stdlib/math/base/special/gamma" ,
43
- " @stdlib/constants/float64/pinf"
43
+ " @stdlib/constants/float64/pinf" ,
44
+ " @stdlib/constants/float64/max-safe-nth-factorial"
44
45
]
45
46
},
46
47
{
57
58
" @stdlib/math/base/assert/is-nan" ,
58
59
" @stdlib/math/base/assert/is-integer" ,
59
60
" @stdlib/math/base/special/gamma" ,
60
- " @stdlib/constants/float64/pinf"
61
+ " @stdlib/constants/float64/pinf" ,
62
+ " @stdlib/constants/float64/max-safe-nth-factorial"
61
63
]
62
64
},
63
65
{
74
76
" @stdlib/math/base/assert/is-nan" ,
75
77
" @stdlib/math/base/assert/is-integer" ,
76
78
" @stdlib/math/base/special/gamma" ,
77
- " @stdlib/constants/float64/pinf"
79
+ " @stdlib/constants/float64/pinf" ,
80
+ " @stdlib/constants/float64/max-safe-nth-factorial"
78
81
]
79
82
}
80
83
]
Original file line number Diff line number Diff line change 21
21
#include "stdlib/math/base/assert/is_integer.h"
22
22
#include "stdlib/math/base/special/gamma.h"
23
23
#include "stdlib/constants/float64/pinf.h"
24
+ #include "stdlib/constants/float64/max_safe_nth_factorial.h"
24
25
#include <stdint.h>
25
26
26
- static const double MAX_FACTORIAL = 170.0 ;
27
27
static const double FACTORIALS [ 171 ] = {
28
28
1.0 ,
29
29
1.0 ,
@@ -217,7 +217,7 @@ double stdlib_base_factorial( const double x ) {
217
217
if ( x < 0.0 ) {
218
218
return 0.0 / 0.0 ; // NaN
219
219
}
220
- if ( x <= MAX_FACTORIAL ) {
220
+ if ( x <= STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FACTORIAL ) {
221
221
return FACTORIALS [ (int32_t )x ];
222
222
}
223
223
return STDLIB_CONSTANT_FLOAT64_PINF ;
You can’t perform that action at this time.
0 commit comments