Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use max-safe-nth-factorial package in math/base/special/factorial #2676

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
var gamma = require( '@stdlib/math/base/special/gamma' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var FLOAT64_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-factorial' );

Check warning on line 27 in lib/node_modules/@stdlib/math/base/special/factorial/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Identifier name 'FLOAT64_MAX_SAFE_NTH_FACTORIAL' is too long (> 25)
var FACTORIALS = require( './factorials.json' );


// VARIABLES //

var MAX_FACTORIAL = 170; // TODO: consider extracting as a constant


// MAIN //

/**
Expand Down Expand Up @@ -76,7 +72,7 @@
if ( x < 0 ) {
return NaN;
}
if ( x <= MAX_FACTORIAL ) {
if ( x <= FLOAT64_MAX_SAFE_NTH_FACTORIAL ) {
return FACTORIALS[ x ];
}
return PINF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/special/gamma",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/max-safe-nth-factorial"
]
},
{
Expand All @@ -57,7 +58,8 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/special/gamma",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/max-safe-nth-factorial"
]
},
{
Expand All @@ -74,7 +76,8 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/special/gamma",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/max-safe-nth-factorial"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "stdlib/math/base/assert/is_integer.h"
#include "stdlib/math/base/special/gamma.h"
#include "stdlib/constants/float64/pinf.h"
#include "stdlib/constants/float64/max_safe_nth_factorial.h"
#include <stdint.h>

static const double MAX_FACTORIAL = 170.0;
static const double FACTORIALS[ 171 ] = {
1.0,
1.0,
Expand Down Expand Up @@ -217,7 +217,7 @@ double stdlib_base_factorial( const double x ) {
if ( x < 0.0 ) {
return 0.0 / 0.0; // NaN
}
if ( x <= MAX_FACTORIAL ) {
if ( x <= STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_FACTORIAL ) {
return FACTORIALS[ (int32_t)x ];
}
return STDLIB_CONSTANT_FLOAT64_PINF;
Expand Down
Loading