Skip to content
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 @@ -174,19 +174,19 @@ logEachMap( 'negafibonaccif(%d) = %0.4f', v, negafibonaccif );
Computes the nth [negaFibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754].

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

out = stdlib_base_negafibonaccif( -1 );
out = stdlib_base_negafibonaccif( -1.0f );
// returns 1.0f
```

The function accepts the following arguments:

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

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

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

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

for ( i = 0; i > -37; i-- ) {
for ( i = 0.0f; i > -37.0f; i-- ) {
v = stdlib_base_negafibonaccif( i );
printf( "negafibonaccif(%d) = %f\n", i, v );
printf( "negafibonaccif(%f) = %f\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

#include "stdlib/math/base/special/negafibonaccif.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -91,14 +90,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( 36.0f*rand_float());
x[ i ] = floorf( 36.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/negafibonaccif.h"
#include <stdio.h>
#include <stdint.h>

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

for ( i = 0; i > -37; i-- ) {
for ( i = 0.0f; i > -37.0f; i-- ) {
v = stdlib_base_negafibonaccif( i );
printf( "negafibonaccif(%d) = %f\n", i, v );
printf( "negafibonaccif(%f) = %f\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_NEGAFIBONACCIF_H
#define STDLIB_MATH_BASE_SPECIAL_NEGAFIBONACCIF_H

#include <stdint.h>

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -31,7 +29,7 @@ extern "C" {
/**
* Computes the nth negaFibonacci number as a single-precision floating-point number.
*/
float stdlib_base_negafibonaccif( const int32_t n );
float stdlib_base_negafibonaccif( const float n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float32/max-safe-nth-fibonacci",
"@stdlib/math/base/special/absf"
"@stdlib/math/base/special/absf",
"@stdlib/math/base/assert/is-integerf"
]
},
{
Expand All @@ -53,7 +54,8 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/max-safe-nth-fibonacci",
"@stdlib/math/base/special/absf"
"@stdlib/math/base/special/absf",
"@stdlib/math/base/assert/is-integerf"
]
},
{
Expand All @@ -68,7 +70,8 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/max-safe-nth-fibonacci",
"@stdlib/math/base/special/absf"
"@stdlib/math/base/special/absf",
"@stdlib/math/base/assert/is-integerf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/negafibonaccif.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_negafibonaccif )
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_negafibonaccif )
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/

#include "stdlib/math/base/special/negafibonaccif.h"
#include "stdlib/math/base/assert/is_integerf.h"
#include "stdlib/math/base/special/absf.h"
#include "stdlib/constants/float32/max_safe_nth_fibonacci.h"
#include <stdint.h>
#include <stdlib.h>

static const float negafibonaccif_value[ 37 ] = {
0.0f,
Expand Down Expand Up @@ -68,17 +69,17 @@ static const float negafibonaccif_value[ 37 ] = {
* @return output value
*
* @example
* float out = stdlib_base_negafibonaccif( -1 );
* float out = stdlib_base_negafibonaccif( -1.0f );
* // returns 1.0f
*/
float stdlib_base_negafibonaccif( const int32_t n ) {
int32_t an;
if ( n > 0 ) {
float stdlib_base_negafibonaccif( const float n ) {
float an;
if ( !stdlib_base_is_integerf( n ) || n > 0.0f ) {
return 0.0f / 0.0f; // NaN
}
an = stdlib_base_absf( n );
if ( an > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_FIBONACCI ) {
return 0.0f / 0.0f; // NaN
}
return negafibonaccif_value[ an ];
return negafibonaccif_value[ (size_t)an ];
}