diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/README.md b/lib/node_modules/@stdlib/math/base/special/fibonaccif/README.md new file mode 100644 index 000000000000..3407c9518748 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/README.md @@ -0,0 +1,258 @@ + + +# Fibonaccif + +> Compute the nth [Fibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754]. + +
+ +The [Fibonacci numbers][fibonacci-number] are the integer sequence + + + +```math +0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, \ldots +``` + + + + + +The sequence is defined by the recurrence relation + + + +```math +F_n = F_{n-1} + F_{n-2} +``` + + + + + +with seed values `F_0 = 0` and `F_1 = 1`. + +
+ + + +
+ +## Usage + +```javascript +var fibonaccif = require( '@stdlib/math/base/special/fibonaccif' ); +``` + +#### fibonaccif( n ) + +Computes the nth [Fibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754]. + +```javascript +var v = fibonaccif( 0 ); +// returns 0 + +v = fibonaccif( 1 ); +// returns 1 + +v = fibonaccif( 2 ); +// returns 1 + +v = fibonaccif( 3 ); +// returns 2 + +v = fibonaccif( 36 ); +// returns 14930352 +``` + +If `n > 36`, the function returns `NaN`, as larger [Fibonacci numbers][fibonacci-number] cannot be safely represented in [single-precision floating-point format][ieee754]. + +```javascript +var v = fibonaccif( 37 ); +// returns NaN +``` + +If not provided a nonnegative integer value, the function returns `NaN`. + +```javascript +var v = fibonaccif( 3.14 ); +// returns NaN + +v = fibonaccif( -1 ); +// returns NaN +``` + +If provided `NaN`, the function returns `NaN`. + +```javascript +var v = fibonaccif( NaN ); +// returns NaN +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var fibonaccif = require( '@stdlib/math/base/special/fibonaccif' ); + +var v; +var i; + +for ( i = 0; i < 37; i++ ) { + v = fibonaccif( i ); + console.log( v ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/fibonaccif.h" +``` + +#### stdlib_base_fibonaccif( n ) + +Computes the nth [Fibonacci number][fibonacci-number] as a [single-precision floating-point number][ieee754]. + +```c +float out = stdlib_base_fibonaccif( 0 ); +// returns 0 + +out = stdlib_base_fibonaccif( 1 ); +// returns 1 +``` + +The function accepts the following arguments: + +- **n**: `[in] int32_t` input value. + +```c +float stdlib_base_fibonaccif( const int32_t n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/fibonaccif.h" +#include +#include + +int main( void ) { + int32_t i; + float v; + + for ( i = 0; i < 37; i++ ) { + v = stdlib_base_fibonaccif( i ); + printf( "fibonaccif(%d) = %f\n", i, v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.js new file mode 100644 index 000000000000..e80863c8e0e2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.js @@ -0,0 +1,396 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var Int32Array = require( '@stdlib/array/int32' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var floorf = require( '@stdlib/math/base/special/floorf' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); +var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' ); +var pkg = require( './../package.json' ).name; +var FIBONACCIF = require( './../lib/fibonaccif.json' ); +var fibonaccif = require( './../lib' ); + + +// VARIABLES // + +var SQRT_5 = sqrtf( 5.0 ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::analytic', function benchmark( b ) { + var x; + var y; + var i; + + function fibonaccif( n ) { + return roundf( float64ToFloat32( pow( FLOAT32_PHI, n ) ) / SQRT_5 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::table', function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = FIBONACCIF[ x ]; + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::naive_recursion', function benchmark( b ) { + var x; + var y; + var i; + + function fibonacci( n ) { + if ( n < 2 ) { + return n; + } + return fibonacci( n-1 ) + fibonacci( n-2 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*19.0 ); // limit upper bound + y = fibonacci( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::recursion_memoized', function benchmark( b ) { + var arr; + var N; + var x; + var y; + var i; + + arr = new Int32Array( 37 ); + arr[ 0 ] = 0; + arr[ 1 ] = 1; + arr[ 2 ] = 1; + N = 2; + + function fibonaccif( n ) { + if ( n <= N ) { + return arr[ n ]; + } + arr[ n ] = fibonaccif( n-1 ) + fibonaccif( n-2 ); + return arr[ n ]; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*19.0 ); // limit upper bound + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::naive_iterative', function benchmark( b ) { + var x; + var y; + var i; + + function fibonaccif( n ) { + var arr; + var i; + + arr = new Int32Array( n+1 ); + arr[ 0 ] = 0; + arr[ 1 ] = 1; + arr[ 2 ] = 1; + for ( i = 3; i <= n; i++ ) { + arr[ i ] = arr[ i-1 ] + arr[ i-2 ]; + } + return arr[ n ]; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iterative', function benchmark( b ) { + var x; + var y; + var i; + + function fibonaccif( n ) { + var a; + var b; + var c; + var i; + + a = 1; + b = 1; + for ( i = 3; i <= n; i++ ) { + c = a + b; + a = b; + b = c; + } + return b; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iterative_memoized', function benchmark( b ) { + var arr; + var N; + var x; + var y; + var i; + + arr = new Int32Array( 37 ); + arr[ 0 ] = 0; + arr[ 1 ] = 1; + arr[ 2 ] = 1; + N = 2; + + function fibonaccif( n ) { + var i; + if ( n > N ) { + for ( i = N+1; i <= n; i++ ) { + arr[ i ] = arr[ i-1 ] + arr[ i-2 ]; + } + N = n; + } + return arr[ n ]; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iterative_doubling', function benchmark( b ) { + var x; + var y; + var i; + + function fibonaccif( n ) { + var i = n - 1; + var a = 1; + var b = 0; + var c = 0; + var d = 1; + var t; + + if ( n < 1 ) { + return n; + } + while ( i > 0 ) { + if ( (i&1) === 1 ) { // is odd + t = (d*(b+a)) + (c*b); + a = (d*b) + (c*a); + b = t; + } + t = d * ((2*c) + d); + c = (c*c) + (d*d); + d = t; + i >>= 1; // i >> 1 is equal to floor( i/2 ) + } + return a + b; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { + var arr; + var N; + var x; + var y; + var i; + + arr = new Int32Array( 37 ); + arr[ 0 ] = 0; + arr[ 1 ] = 1; + arr[ 2 ] = 1; + N = 2; + + function fibonaccif( n ) { + var i; + var a; + var b; + var c; + var d; + var t; + + if ( n <= N ) { + return arr[ n ]; + } + if ( n < 1 ) { + return n; + } + i = n - 1; + a = 1; + b = 0; + c = 0; + d = 1; + while ( i > 0 ) { + if ( (i&1) === 1 ) { // is odd + t = (d*(b+a)) + (c*b); + a = (d*b) + (c*a); + b = t; + } + t = d * ((2*c) + d); + c = (c*c) + (d*d); + d = t; + i >>= 1; // i >> 1 is equal to floor( i/2 ) + } + arr[ n ] = a + b; + return a + b; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.native.js new file mode 100644 index 000000000000..a35a0f994e81 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/benchmark.native.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var floorf = require( '@stdlib/math/base/special/floorf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var fibonaccif = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( fibonaccif instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = floorf( randu()*37.0 ); + y = fibonaccif( x ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/Makefile new file mode 100644 index 000000000000..d564e8b2d6f9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/Makefile @@ -0,0 +1,127 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler +# @param {string} [CFLAGS] - C compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/benchmark.c new file mode 100644 index 000000000000..5e8c2a34a2d7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/benchmark.c @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include +#include + +#define NAME "fibonaccif::naive_recursion" +#define ITERATIONS 100 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Computes the nth Fibonacci number. +* +* @param n Fibonacci number to compute +* @return Fibonacci number +*/ +int fibonaccif( int n ) { + if ( n < 2 ) { + return n; + } + return fibonaccif( n-1 ) + fibonaccif( n-2 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double t; + int x; + int y; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = (int)floorf( 40.0f*rand_float() ); + y = fibonaccif( x ); + if ( y < 0 ) { + printf( "should return a nonnegative integer\n" ); + break; + } + } + elapsed = tic() - t; + if ( y < 0 ) { + printf( "should return a nonnegative integer\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..411d85086e8f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/benchmark/c/native/benchmark.c @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fibonaccif.h" +#include +#include +#include +#include +#include + +#define NAME "fibonaccif" +#define ITERATIONS 100 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + int32_t x; + double t; + float y; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = (int32_t)floorf( 40.0f*rand_float() ); + y = stdlib_base_fibonaccif( x ); + if ( y < 0 ) { + printf( "should return a nonnegative integer\n" ); + break; + } + } + elapsed = tic() - t; + if ( y < 0 ) { + printf( "should return a nonnegative integer\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/binding.gyp b/lib/node_modules/@stdlib/math/base/special/fibonaccif/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_recurrence_relation.svg b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_recurrence_relation.svg new file mode 100644 index 000000000000..4c635bc9d903 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_recurrence_relation.svg @@ -0,0 +1,34 @@ + +upper F Subscript n Baseline equals upper F Subscript n minus 1 Baseline plus upper F Subscript n minus 2 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_sequence.svg b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_sequence.svg new file mode 100644 index 000000000000..805bc80aea27 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/img/equation_fibonacci_sequence.svg @@ -0,0 +1,63 @@ + +0 comma 1 comma 1 comma 2 comma 3 comma 5 comma 8 comma 13 comma 21 comma 34 comma 55 comma 89 comma 144 comma ellipsis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/repl.txt new file mode 100644 index 000000000000..9d88ac34b61b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( n ) + Computes the nth Fibonacci number as a single-precision + floating-point number. + + Fibonacci numbers follow the recurrence relation + + F_n = F_{n-1} + F_{n-2} + + with seed values F_0 = 0 and F_1 = 1. + + If `n` is greater than `36`, the function returns `NaN`, as larger Fibonacci + numbers cannot be accurately represented due to limitations of single- + precision floating-point format. + + If not provided a nonnegative integer value, the function returns `NaN`. + + If provided `NaN`, the function returns `NaN`. + + Parameters + ---------- + n: integer + Input value. + + Returns + ------- + y: integer + Fibonacci number. + + Examples + -------- + > var y = {{alias}}( 0 ) + 0 + > y = {{alias}}( 1 ) + 1 + > y = {{alias}}( 2 ) + 1 + > y = {{alias}}( 3 ) + 2 + > y = {{alias}}( 4 ) + 3 + > y = {{alias}}( 37 ) + NaN + > y = {{alias}}( NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/index.d.ts new file mode 100644 index 000000000000..ae8af8c6a2d7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/index.d.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Computes the nth Fibonacci number as a single-precision floating-point number. +* +* ## Notes +* +* - If `n` is greater than `36`, the function returns `NaN`, as larger Fibonacci numbers cannot be accurately represented due to limitations of single-precision floating-point format. +* - If not provided a nonnegative integer value, the function returns `NaN`. +* +* @param n - the Fibonacci number to compute +* @returns Fibonacci number +* +* @example +* var y = fibonaccif( 0 ); +* // returns 0 +* +* @example +* var y = fibonaccif( 1 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 2 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 3 ); +* // returns 2 +* +* @example +* var y = fibonaccif( 4 ); +* // returns 3 +* +* @example +* var y = fibonaccif( 5 ); +* // returns 5 +* +* @example +* var y = fibonaccif( 6 ); +* // returns 8 +* +* @example +* var y = fibonaccif( NaN ); +* // returns NaN +* +* @example +* var y = fibonaccif( 3.14 ); +* // returns NaN +* +* @example +* var y = fibonaccif( -1.0 ); +* // returns NaN +*/ +declare function fibonaccif( n: number ): number; + + +// EXPORTS // + +export = fibonaccif; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/test.ts new file mode 100644 index 000000000000..ea01795f88af --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import fibonaccif = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + fibonaccif( 7 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + fibonaccif( true ); // $ExpectError + fibonaccif( false ); // $ExpectError + fibonaccif( null ); // $ExpectError + fibonaccif( undefined ); // $ExpectError + fibonaccif( '5' ); // $ExpectError + fibonaccif( [] ); // $ExpectError + fibonaccif( {} ); // $ExpectError + fibonaccif( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + fibonaccif(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/example.c new file mode 100644 index 000000000000..cab99e248bac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fibonaccif.h" +#include +#include + +int main( void ) { + int32_t i; + float v; + + for ( i = 0; i < 37; i++ ) { + v = stdlib_base_fibonaccif( i ); + printf( "fibonaccif(%d) = %f\n", i, v ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/index.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/index.js new file mode 100644 index 000000000000..b4ab9fe28601 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var fibonaccif = require( './../lib' ); + +var v; +var i; + +for ( i = 0; i < 37; i++ ) { + v = fibonaccif( i ); + console.log( v ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/include.gypi b/lib/node_modules/@stdlib/math/base/special/fibonaccif/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Computes the nth Fibonacci number as a single-precision floating-point number. +*/ +float stdlib_base_fibonaccif( const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_FIBONACCIF_H diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/fibonaccif.json b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/fibonaccif.json new file mode 100644 index 000000000000..66bb27dccf5d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/fibonaccif.json @@ -0,0 +1 @@ +[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352] diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/index.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/index.js new file mode 100644 index 000000000000..422cf0a10f95 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/index.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the nth Fibonacci number as a single-precision floating-point number. +* +* @module @stdlib/math/base/special/fibonaccif +* +* @example +* var fibonaccif = require( '@stdlib/math/base/special/fibonaccif' ); +* +* var y = fibonaccif( 0 ); +* // returns 0 +* +* y = fibonaccif( 1 ); +* // returns 1 +* +* y = fibonaccif( 2 ); +* // returns 1 +* +* y = fibonaccif( 3 ); +* // returns 2 +* +* y = fibonaccif( 4 ); +* // returns 3 +* +* y = fibonaccif( 5 ); +* // returns 5 +* +* y = fibonaccif( 6 ); +* // returns 8 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/main.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/main.js new file mode 100644 index 000000000000..b6af3c968e22 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/main.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); +var FLOAT32_MAX_SAFE_NTH_FIBONACCI = require( '@stdlib/constants/float32/max-safe-nth-fibonacci' ); // eslint-disable-line id-length +var FIBONACCIF = require( './fibonaccif.json' ); + + +// MAIN // + +/** +* Computes the nth Fibonacci number as a single-precision floating-point number. +* +* @param {NonNegativeInteger} n - the Fibonacci number to compute +* @returns {NonNegativeInteger} Fibonacci number +* +* @example +* var y = fibonaccif( 0 ); +* // returns 0 +* +* @example +* var y = fibonaccif( 1 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 2 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 3 ); +* // returns 2 +* +* @example +* var y = fibonaccif( 4 ); +* // returns 3 +* +* @example +* var y = fibonaccif( 5 ); +* // returns 5 +* +* @example +* var y = fibonaccif( 6 ); +* // returns 8 +* +* @example +* var y = fibonaccif( NaN ); +* // returns NaN +* +* @example +* var y = fibonaccif( 3.14 ); +* // returns NaN +* +* @example +* var y = fibonaccif( -1.0 ); +* // returns NaN +*/ +function fibonaccif( n ) { + if ( + isnanf( n ) || + isIntegerf( n ) === false || + n < 0 || + n > FLOAT32_MAX_SAFE_NTH_FIBONACCI + ) { + return NaN; + } + return FIBONACCIF[ n ]; +} + + +// EXPORTS // + +module.exports = fibonaccif; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/native.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/native.js new file mode 100644 index 000000000000..6df1e9d5ea29 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/lib/native.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the nth Fibonacci number as a single-precision floating-point number. +* +* @private +* @param {NonNegativeInteger} n - the Fibonacci number to compute +* @returns {NonNegativeInteger} Fibonacci number +* +* @example +* var y = fibonaccif( 0 ); +* // returns 0 +* +* @example +* var y = fibonaccif( 1 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 2 ); +* // returns 1 +* +* @example +* var y = fibonaccif( 3 ); +* // returns 2 +* +* @example +* var y = fibonaccif( 4 ); +* // returns 3 +* +* @example +* var y = fibonaccif( 5 ); +* // returns 5 +* +* @example +* var y = fibonaccif( 6 ); +* // returns 8 +* +* @example +* var y = fibonaccif( -1 ); +* // returns NaN +*/ +function fibonaccif( n ) { + return addon( n ); +} + + +// EXPORTS // + +module.exports = fibonaccif; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/manifest.json b/lib/node_modules/@stdlib/math/base/special/fibonaccif/manifest.json new file mode 100644 index 000000000000..26a079a0b09f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/manifest.json @@ -0,0 +1,72 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary", + "@stdlib/constants/float32/max-safe-nth-fibonacci" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/constants/float32/max-safe-nth-fibonacci" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/constants/float32/max-safe-nth-fibonacci" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/package.json b/lib/node_modules/@stdlib/math/base/special/fibonaccif/package.json new file mode 100644 index 000000000000..92be95e2ee61 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/math/base/special/fibonaccif", + "version": "0.0.0", + "description": "Compute the nth Fibonacci number as a single-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "special functions", + "special", + "function", + "fibonacci", + "fib", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/Makefile b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/addon.c new file mode 100644 index 000000000000..89356973ba9d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fibonaccif.h" +#include "stdlib/math/base/napi/unary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_fibonaccif ) diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/main.c b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/main.c new file mode 100644 index 000000000000..09637926c034 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/src/main.c @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fibonaccif.h" +#include "stdlib/constants/float32/max_safe_nth_fibonacci.h" + +static const int32_t fibonacci_value[ 37 ] = { + 0, + 1, + 1, + 2, + 3, + 5, + 8, + 13, + 21, + 34, + 55, + 89, + 144, + 233, + 377, + 610, + 987, + 1597, + 2584, + 4181, + 6765, + 10946, + 17711, + 28657, + 46368, + 75025, + 121393, + 196418, + 317811, + 514229, + 832040, + 1346269, + 2178309, + 3524578, + 5702887, + 9227465, + 14930352 +}; + +/** +* Computes the nth Fibonacci number as a single-precision floating-point number. +* +* @param n input value +* @return output value +* +* @example +* float out = stdlib_base_fibonaccif( 1 ); +* // returns 1 +*/ +float stdlib_base_fibonaccif( const int32_t n ) { + if ( n < 0 || n > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_FIBONACCI ) { + return 0.0 / 0.0; // NaN + } + return fibonacci_value[ n ]; +} diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.js new file mode 100644 index 000000000000..30d12b7d2fc2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var fibonaccif = require( './../lib' ); + + +// FIXTURES // + +var FIBONACCIF = require( './../lib/fibonaccif.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fibonaccif, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative number, the function returns `NaN`', function test( t ) { + var v; + var i; + + t.strictEqual( isnanf( fibonaccif( -3.14 ) ), true, 'returns NaN' ); + + for ( i = -1; i > -100; i-- ) { + v = fibonaccif( i ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i ); + } + t.end(); +}); + +tape( 'if provided positive infinity, the function returns `NaN`', function test( t ) { + var v = fibonaccif( PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided +infinity' ); + t.end(); +}); + +tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { + var v = fibonaccif( NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided a NaN' ); + t.end(); +}); + +tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) { + var v = fibonaccif( 3.14 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns the nth Fibonacci number', function test( t ) { + var v; + var i; + for ( i = 0; i < 37; i++ ) { + v = fibonaccif( i ); + t.strictEqual( v, FIBONACCIF[ i ], 'returns the '+i+'th Fibonacci number' ); + } + t.end(); +}); + +tape( 'if provided nonnegative integers greater than `36`, the function returns `NaN`', function test( t ) { + var i; + var v; + for ( i = 37; i < 500; i++ ) { + v = fibonaccif( i ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.native.js new file mode 100644 index 000000000000..89f16f37e055 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fibonaccif/test/test.native.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var FIBONACCIF = require( './../lib/fibonaccif.json' ); + + +// VARIABLES // + +var fibonaccif = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( fibonaccif instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fibonaccif, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a negative number, the function returns `NaN`', opts, function test( t ) { + var v; + var i; + + for ( i = -1; i > -100; i-- ) { + v = fibonaccif( i ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i ); + } + t.end(); +}); + +tape( 'the function returns the nth Fibonacci number', opts, function test( t ) { + var v; + var i; + for ( i = 0; i < 37; i++ ) { + v = fibonaccif( i ); + t.strictEqual( v, FIBONACCIF[ i ], 'returns the '+i+'th Fibonacci number' ); + } + t.end(); +}); + +tape( 'if provided nonnegative integers greater than `78`, the function returns `NaN`', opts, function test( t ) { + var i; + var v; + for ( i = 37; i < 500; i++ ) { + v = fibonaccif( i ); + t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i ); + } + t.end(); +});