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 @@ -151,19 +151,19 @@ for ( i = 1; i < 100; i++ ) {
Computes the nth non-Fibonacci single-precision floating-point number.

```c
float out = stdlib_base_nonfibonaccif( 1 );
float out = stdlib_base_nonfibonaccif( 1.0f );
// returns 4.0f

out = stdlib_base_nonfibonaccif( 2 );
out = stdlib_base_nonfibonaccif( 2.0f );
// returns 6.0f
```

The function accepts the following arguments:

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

```c
float stdlib_base_nonfibonaccif( const int32_t x );
float stdlib_base_nonfibonaccif( const float x );
```

</section>
Expand All @@ -189,10 +189,12 @@ float stdlib_base_nonfibonaccif( const int32_t x );
#include <stdio.h>

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

for ( i = 1; i < 12; i++ ) {
printf( "x: %i => result: %f\n", i, stdlib_base_nonfibonaccif( i ) );
for ( i = 1.0f; i < 12.0f; i++ ) {
v = stdlib_base_nonfibonaccif( i );
printf( "nonfibonaccif(%f) = %f\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ static float rand_float( void ) {
*/
static double benchmark( void ) {
double elapsed;
int x[ 100 ];
float x[ 100 ];
double t;
float y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int)floorf( ( 100.0f * rand_float() ) + 1.0f );
x[ i ] = floorf( ( 100.0f * rand_float() ) + 1.0f );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include <stdio.h>

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

for ( i = 1; i < 12; i++ ) {
printf( "x: %i => result: %f\n", i, stdlib_base_nonfibonaccif( i ) );
for ( i = 1.0f; i < 12.0f; i++ ) {
v = stdlib_base_nonfibonaccif( i );
printf( "nonfibonaccif(%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_NONFIBONACCIF_H
#define STDLIB_MATH_BASE_SPECIAL_NONFIBONACCIF_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 @@ -32,7 +30,7 @@ extern "C"
/**
* Computes the nth non-Fibonacci single-precision floating-point number.
*/
float stdlib_base_nonfibonaccif( const int32_t n );
float stdlib_base_nonfibonaccif( const float n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float32/nan",
"@stdlib/math/base/special/floorf",
"@stdlib/math/base/special/lnf"
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-integerf",
"@stdlib/constants/float32/pinf"
]
},
{
Expand All @@ -55,7 +57,9 @@
"dependencies": [
"@stdlib/constants/float32/nan",
"@stdlib/math/base/special/floorf",
"@stdlib/math/base/special/lnf"
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-integerf",
"@stdlib/constants/float32/pinf"
]
},
{
Expand All @@ -71,7 +75,9 @@
"dependencies": [
"@stdlib/constants/float32/nan",
"@stdlib/math/base/special/floorf",
"@stdlib/math/base/special/lnf"
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-integerf",
"@stdlib/constants/float32/pinf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/nonfibonaccif.h"
#include "stdlib/math/base/napi/unary.h"

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

#include "stdlib/math/base/special/nonfibonaccif.h"
#include "stdlib/math/base/assert/is_integerf.h"
#include "stdlib/constants/float32/nan.h"
#include "stdlib/constants/float32/pinf.h"
#include "stdlib/math/base/special/floorf.h"
#include "stdlib/math/base/special/lnf.h"
#include <stdint.h>

static const float SQRT5 = 2.23606797749979f;
static const float LN_PHI = 0.48121182506f;
Expand All @@ -32,30 +33,30 @@ static const float LN_PHI = 0.48121182506f;
* @return output value
*
* @example
* float y = stdlib_base_nonfibonaccif( 2 );
* float y = stdlib_base_nonfibonaccif( 2.0f );
* // returns 6.0f
*
* @example
* float y = stdlib_base_nonfibonaccif( 1 );
* float y = stdlib_base_nonfibonaccif( 1.0f );
* // returns 4.0f
*
* @example
* float y = stdlib_base_nonfibonaccif( 3 );
* float y = stdlib_base_nonfibonaccif( 3.0f );
* // returns 7.0f
*
* @example
* float y = stdlib_base_nonfibonaccif( -1 );
* float y = stdlib_base_nonfibonaccif( -1.0f );
* // returns NaN
*/
float stdlib_base_nonfibonaccif( const int32_t n ) {
int32_t m;
float stdlib_base_nonfibonaccif( const float n ) {
float m;
float a;
float b;

if ( n < 1 ) {
if ( !stdlib_base_is_integerf( n ) || n == STDLIB_CONSTANT_FLOAT32_PINF || n < 1.0f ) {
return STDLIB_CONSTANT_FLOAT32_NAN;
}
m = n + 1;
m = n + 1.0f;
a = stdlib_base_lnf( m * SQRT5 ) / LN_PHI;
b = stdlib_base_lnf( ( SQRT5 * ( m + a ) ) - 5.0f + ( 3.0f / m ) ) / LN_PHI;
return stdlib_base_floorf( m + b - 2.0f );
Expand Down