Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/tribonaccif/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ logEachMap( 'tribonaccif(%d) = %0.4f', v, tribonaccif );
Computes the nth [Tribonacci number][tribonacci-number] as a [single-precision floating-point number][ieee754].

```c
float out = stdlib_base_tribonaccif( 0 );
float out = stdlib_base_tribonaccif( 0.0f );
// returns 0.0f

out = stdlib_base_tribonaccif( 4 );
out = stdlib_base_tribonaccif( 4.0f );
// returns 2.0f
```

The function accepts the following arguments:

- **n**: `[in] int32_t` input value.
- **n**: `[in] float` input value.

```c
float stdlib_base_tribonaccif( const int32_t n );
float stdlib_base_tribonaccif( const float n );
```

</section>
Expand All @@ -200,15 +200,14 @@ float stdlib_base_tribonaccif( const int32_t n );
```c
#include "stdlib/math/base/special/tribonaccif.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
float i;
float v;

for ( i = 0; i < 31; i++ ) {
for ( i = 0.0f; i < 31.0f; i++ ) {
v = stdlib_base_tribonaccif( i );
printf( "tribonaccif(%d) = %f\n", i, v );
printf( "tribonaccif(%f) = %f\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ static float rand_float( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
int32_t x[ 100 ];
float x[ 100 ];
double elapsed;
double t;
float y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int32_t)floorf( 40.0f*rand_float() );
x[ i ] = floorf( 40.0f*rand_float() );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

#include "stdlib/math/base/special/tribonaccif.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
float i;
float v;

for ( i = 0; i < 31; i++ ) {
for ( i = 0.0f; i < 31.0f; i++ ) {
v = stdlib_base_tribonaccif( i );
printf( "tribonaccif(%d) = %f\n", i, v );
printf( "tribonaccif(%f) = %f\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_TRIBONACCIF_H
#define STDLIB_MATH_BASE_SPECIAL_TRIBONACCIF_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* Computes the nth Tribonacci number as a single-precision floating-point number.
*/
float stdlib_base_tribonaccif( const int32_t n );
float stdlib_base_tribonaccif( const float n );

#ifdef __cplusplus
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
var isNonnegativeIntegerf = require( '@stdlib/math/base/assert/is-nonnegative-integerf' );
var FLOAT32_MAX_SAFE_NTH_TRIBONACCI = require( '@stdlib/constants/float32/max-safe-nth-tribonacci' ); // eslint-disable-line id-length
var TRIBONACCIF = require( './tribonaccif.json' );

Expand Down Expand Up @@ -77,8 +77,7 @@ var TRIBONACCIF = require( './tribonaccif.json' );
function tribonaccif( n ) {
if (
isnanf( n ) ||
isIntegerf( n ) === false ||
n < 0 ||
!isNonnegativeIntegerf( n ) ||
n > FLOAT32_MAX_SAFE_NTH_TRIBONACCI
) {
return NaN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float32/max-safe-nth-tribonacci"
"@stdlib/constants/float32/max-safe-nth-tribonacci",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-nanf"
]
},
{
Expand All @@ -51,7 +53,9 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/max-safe-nth-tribonacci"
"@stdlib/constants/float32/max-safe-nth-tribonacci",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-nanf"
]
},
{
Expand All @@ -65,7 +69,9 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/max-safe-nth-tribonacci"
"@stdlib/constants/float32/max-safe-nth-tribonacci",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-nanf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/tribonaccif.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_tribonaccif )
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_tribonaccif )
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

#include "stdlib/math/base/special/tribonaccif.h"
#include "stdlib/constants/float32/max_safe_nth_tribonacci.h"
#include "stdlib/math/base/assert/is_nonnegative_integerf.h"
#include "stdlib/math/base/assert/is_nanf.h"
#include <stdint.h>
#include <stdlib.h>

static const int32_t tribonaccif_value[ 31 ] = {
0,
Expand Down Expand Up @@ -61,12 +64,12 @@ static const int32_t tribonaccif_value[ 31 ] = {
* @return output value
*
* @example
* float out = stdlib_base_tribonaccif( 1 );
* float out = stdlib_base_tribonaccif( 1.0f );
* // returns 0.0f
*/
float stdlib_base_tribonaccif( const int32_t n ) {
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_TRIBONACCI ) {
float stdlib_base_tribonaccif( const float n ) {
if ( stdlib_base_is_nanf( n ) || !stdlib_base_is_nonnegative_integerf( n ) || n > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_TRIBONACCI ) {
return 0.0f / 0.0f; // NaN
}
return tribonaccif_value[ n ];
return tribonaccif_value[ (size_t)n ];
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -58,6 +59,24 @@ tape( 'if provided a negative number, the function returns `NaN`', opts, functio
t.end();
});

tape( 'if provided positive infinity, the function returns `NaN`', function test( t ) {
var v = tribonaccif( PINF );
t.strictEqual( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
var v = tribonaccif( NaN );
t.strictEqual( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) {
var v = tribonaccif( 3.14 );
t.strictEqual( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns the nth Tribonacci number', opts, function test( t ) {
var v;
var i;
Expand Down