Skip to content

Commit

Permalink
refactor: use external constant in math/base/special/tribonacci
Browse files Browse the repository at this point in the history
PR-URL: #3324
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
gunjjoshi authored Dec 4, 2024
1 parent 1d10ce5 commit 4bc5c7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
var FLOAT64_MAX_SAFE_NTH_TRIBONACCI = require( '@stdlib/constants/float64/max-safe-nth-tribonacci' ); // eslint-disable-line id-length
var TRIBONACCI = require( './tribonacci.json' );


// VARIABLES //

var MAX_TRIBONACCI = 63;


// MAIN //

/**
Expand Down Expand Up @@ -83,7 +79,7 @@ function tribonacci( n ) {
isnan( n ) ||
isInteger( n ) === false ||
n < 0 ||
n > MAX_TRIBONACCI
n > FLOAT64_MAX_SAFE_NTH_TRIBONACCI
) {
return NaN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary"
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float64/max-safe-nth-tribonacci"
]
},
{
Expand All @@ -49,7 +50,9 @@
],
"libraries": [],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-tribonacci"
]
},
{
"task": "examples",
Expand All @@ -61,7 +64,9 @@
],
"libraries": [],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/constants/float64/max-safe-nth-tribonacci"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

#include "stdlib/math/base/special/tribonacci.h"
#include "stdlib/constants/float64/max_safe_nth_tribonacci.h"

static const int32_t STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_TRIBONACCI = 63; // TODO: consider making a package similar to `@stdlib/constants/float64/max-safe-nth-fibonacci`
static const int64_t tribonacci_value[ 64 ] = {
0,
0,
Expand Down Expand Up @@ -96,7 +96,7 @@ static const int64_t tribonacci_value[ 64 ] = {
* // returns 0
*/
double stdlib_base_tribonacci( const int32_t n ) {
if ( n < 0 || n > STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_TRIBONACCI ) {
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_TRIBONACCI ) {
return 0.0 / 0.0; // NaN
}
return tribonacci_value[ n ];
Expand Down

1 comment on commit 4bc5c7e

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/tribonacci $\color{green}150/150$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}150/150$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.