diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/README.md b/lib/node_modules/@stdlib/math/base/special/lcmf/README.md new file mode 100644 index 000000000000..f51c3aa9151d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/README.md @@ -0,0 +1,227 @@ + + +# lcmf + +> Compute the [least common multiple][lcm] of two single-precision floating-point numbers. + + + +
+ +The [least common multiple][lcm] (lcm) of two non-zero integers `a` and `b` is the smallest positive integer that is divisible by both `a` and `b`. The lcm is also known as the **lowest common multiple** or **smallest common multiple** and finds common use in calculating the **lowest common denominator** (lcd). + +
+ + + + + +
+ +## Usage + +```javascript +var lcmf = require( '@stdlib/math/base/special/lcmf' ); +``` + +### lcmf( a, b ) + +Computes the [least common multiple][lcm] for two single-precision floating-point numbers `a` and `b`. + +```javascript +var v = lcmf( 10, 12 ); +// returns 60 +``` + +If either `a` or `b` is `0`, the function returns `0`. + +```javascript +var v = lcmf( 0, 12 ); +// returns 0 +``` + +Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. + +```javascript +var v = lcmf( 3.14, 12 ); +// returns NaN + +v = lcmf( NaN, 12 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var lcmf = require( '@stdlib/math/base/special/lcmf' ); + +var v; +var i; + +for ( i = 0; i < 100; i++ ) { + a = round( randu() * 50 ); + b = round( randu() * 50 ); + v = lcmf( a, b ); + console.log( 'lcmf(%d,%d) = %d', a, b, v ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/lcmf.h" +``` + +### stdlib_base_lcmf( a, b ) + +Computes the [least common multiple][lcm] for two single-precision floating-point numbers `a` and `b`. + +```c +float v = stdlib_base_lcmf( 10.0f, 12.0f ); +// returns 60.0f +``` + +The function accepts the following arguments: + +- **a**: `[in] float` input value. +- **b**: `[in] float` input value. + +```c +float stdlib_base_lcmf( const float a, const float b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/lcmf.h" +#include + +int main( void ) { + const float a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; + const float b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; + + float out; + int i; + for (i = 0; i < 5; i++) { + out = stdlib_base_lcmf( a[ i ], b[ i ] ); + printf( "lcm(%f, %f) = %f\n", a[ i ], b[ i ], out ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js new file mode 100644 index 000000000000..2577313c6fa7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var lcmf = require( './../lib' ); + +bench( pkg, function benchmark( b ) { + var x; + var y; + var z; + var i; + + x = randu( 100, 0, 50 ); + y = randu( 100, 0, 50 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = lcmf( x[ i % x.length ], y[ i % y.length ] ); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..fce885646936 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var lcmf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( lcmf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var z; + var i; + + x = randu( 100, 0, 50 ); + y = randu( 100, 0, 50 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = lcmf( x[ i % x.length ], y[ i % y.length ] ); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..3f41176faf73 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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: +LIBRARIES ?= + +# List of library paths: +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 for position independent code +# @param {string} [INCLUDE] - list of includes +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths +# @param {string} [LIBRARIES] - list of libraries +# +# @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/lcmf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..044e0e56368b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/lcmf.h" +#include +#include +#include +#include +#include + +#define NAME "lcmf" +#define ITERATIONS 1000000 +#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 integer in the interval [1, 20]. +* +* @return random integer +*/ +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; + float x[ 100 ]; + float y[ 100 ]; + float z; + double t; + int i; + + t = tic(); + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 20.0f * rand_float() ) - 10.0f; + y[ i ] = ( 2048.0f * rand_float() ) - 1024.0f; + } + for ( i = 0; i < ITERATIONS; i++ ) { + z = stdlib_base_lcmf( x[ i % 100 ], y[ i % 100 ] ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Seed the random number generator with the current time + 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/lcmf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/lcmf/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/lcmf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt new file mode 100644 index 000000000000..eff6d986fb28 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt @@ -0,0 +1,28 @@ +{{alias}}( a, b ) + Computes the least common multiple (LCM) of two single-precision floating-point numbers. + + If either `a` or `b` is `0`, the function returns `0`. + + Both `a` and `b` must have integer values; otherwise, the function returns + `NaN`. + + Parameters + ---------- + a: integer + First integer. + + b: integer + Second integer. + + Returns + ------- + out: integer + Least common multiple. + + Examples + -------- + > var v = {{alias}}( 21, 6 ) + 42 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/index.d.ts new file mode 100644 index 000000000000..72f98da2ec96 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/index.d.ts @@ -0,0 +1,51 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 least common multiple (LCM) of two single-precision floating-point numbers. +* +* ## Notes +* +* - If either `a` or `b` is `0`, the function returns `0`. +* - The inputs `a` and `b` are expected to be single-precision floating-point numbers. +* - If `a` or `b` are not whole numbers, the function returns `NaN`. +* +* @param a - integer +* @param b - integer +* @returns least common multiple +* +* @example +* var v = lcmf( 21.0, 6.0 ); +* // returns 42.0 +* +* @example +* var v = lcmf( 3.14, 6.0 ); +* // returns NaN +* +* @example +* var v = lcmf( NaN, 6.0 ); +* // returns NaN +*/ +declare function lcmf( a: number, b: number ): number; + + +// EXPORTS // + +export = lcmf; diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/test.ts new file mode 100644 index 000000000000..315ca5657885 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/test.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 lcmf = require( './index' ); + +// TESTS // + +// The function returns a number... +{ + lcmf( 10.0, 5.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than single precision floating-point numbers... +{ + lcmf( true, 5.0 ); // $ExpectError + lcmf( false, 5.0 ); // $ExpectError + lcmf( '5.0', 5.0 ); // $ExpectError + lcmf( [], 5.0 ); // $ExpectError + lcmf( {}, 5.0 ); // $ExpectError + lcmf( ( x: number ): number => x, 5.0 ); // $ExpectError + lcmf( 10.0, true ); // $ExpectError + lcmf( 10.0, false ); // $ExpectError + lcmf( 10.0, '5.0' ); // $ExpectError + lcmf( 10.0, [] ); // $ExpectError + lcmf( 10.0, {} ); // $ExpectError + lcmf( 10.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + lcmf(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/lcmf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/example.c new file mode 100644 index 000000000000..3990dec0525e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/example.c @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/lcmf.h" +#include +#include + +int main( void ) { + float y; + int i; + + const float frac[] = { 0.5f, 5.0f, 0.0f, 3.5f, 7.9f }; + const int32_t exp[] = { 3, -2, 20, 39, 14 }; + + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_lcmf( frac[ i ], exp[ i ] ); + printf( "lcmf(%.2f, %d) = %f\n", frac[ i ], exp[ i ], y ); + } + + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js new file mode 100644 index 000000000000..1ca2e7d0ff0b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js @@ -0,0 +1,31 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 linspace = require( '@stdlib/array/base/linspace' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var lcmf = require( './../lib' ); + +var numsA = linspace( 1.0, 10.0, 10 ); +var numsB = discreteUniform( 100, 0, 10 ); + +var i; +for ( i = 0; i < numsA.length; i++ ) { + console.log( 'lcmf(%d, %d) = %d', numsA[ i ], numsB[ i ], lcmf( numsA[ i ], numsB[ i ] ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/include.gypi b/lib/node_modules/@stdlib/math/base/special/lcmf/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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 least common multiple (LCM) of two floating-point numbers. +*/ +float stdlib_base_lcmf( float a, float b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_LCMF_H diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js new file mode 100644 index 000000000000..ec87461ebfa0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* Computes the least common multiple (LCM) of two single-precision floating-point numbers. +* +* @module @stdlib/math/base/special/lcmf +* +* @example +* var lcmf = require( '@stdlib/math/base/special/lcmf' ); +* +* var v = lcmf( 10.0 , 5.0 ); +* // returns 10.0 +* +* v = lcmf( 15.0 , 6.0 ); +* // returns 30.0 +* +* v = lcmf( 0.0 , 6.0 ); +* // returns 0.0 +* +* v = lcmf( 3.14 , 6.0 ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js new file mode 100644 index 000000000000..632f546edd49 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 gcdf = require( '@stdlib/math/base/special/gcdf' ); + + +// MAIN // + +/** +* Computes the least common multiple (LCM) of two single-precision floating-point numbers. +* +* @param {number} a - integer +* @param {number} b - integer +* @returns {number} least common multiple of `a` and `b` +* +* @example +* var v = lcmf( 21.0, 6.0 ); +* // returns 42.0 +* +* @example +* var v = lcmf( 3.0, 7.0 ); +* // returns 21.0 +* +* @example +* var v = lcmf( 0.0, 5.0 ); +* // returns 0.0 +* +* @example +* var v = lcmf( NaN, 5.0 ); +* // returns NaN +*/ +function lcmf( a, b ) { + var d; + if ( a === 0 || b === 0 ) { + return 0; + } + if ( a < 0 ) { + a = -a; + } + if ( b < 0 ) { + b = -b; + } + + // Note: we rely on `gcd` to perform further argument validation... + d = gcd( a, b ); + if ( isnanf( d ) ) { + return d; + } + return ( a / d ) * b; +} + + +// EXPORTS // + +module.exports = lcmf; diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js new file mode 100644 index 000000000000..98db309241dc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 least common multiple (LCM) of two single-precision floating-point numbers. +* +* @private +* @param {number} a - integer +* @param {number} b - integer +* @returns {number} least common multiple of `a` and `b` +* +* @example +* var v = lcmf( 21.0, 6.0 ); +* // returns 42.0 +* +* @example +* var v = lcmf( 3.0, 7.0 ); +* // returns 21.0 +* +* @example +* var v = lcmf( NaN, 5.0 ); +* // returns NaN +*/ +function lcmf( a, b ) { + return addon( a, b ); +} + + +// EXPORTS // + +module.exports = lcmf; diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/manifest.json b/lib/node_modules/@stdlib/math/base/special/lcmf/manifest.json new file mode 100644 index 000000000000..ad83dc57770d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/manifest.json @@ -0,0 +1,76 @@ +{ + "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/binary", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/gcdf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/gcdf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/gcdf" + ] + } + ] + } + diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/package.json b/lib/node_modules/@stdlib/math/base/special/lcmf/package.json new file mode 100644 index 000000000000..a22970cb7261 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/math/base/special/lcmf", + "version": "0.0.0", + "description": "Compute the least common multiple (LCM) of two single-precision floating-numbers", + "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", + "math", + "mathematics", + "euclid", + "euclidean", + "least common multiple", + "lcm", + "lcmf", + "arithmetic", + "discrete", + "gcd", + "integer" + ] + } + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/lcmf/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/lcmf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c new file mode 100644 index 000000000000..1d2a302e41ac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/lcmf.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_lcmf ) diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c b/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c new file mode 100644 index 000000000000..98d33e0227a3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/lcmf.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/special/gcdf.h" + +/** +* Computes the least common multiple (LCM) of two single-precision floating-point numbers. +* +* @param a integer +* @param b integer +* @return least common multiple +* +* @example +* float out = stdlib_base_lcmf( 21.0f, 6.0f ); +* // returns 42.0f +*/ +float stdlib_base_lcmf( const float a, const float b ) { + float an; + float bn; + float d; + + if ( a == 0.0f || b == 0.0f ) { + return 0.0f; + } + if ( a < 0.0 ) { + an = -a; + } else { + an = a; + } + if ( b < 0.0 ) { + bn = -b; + } else { + bn = b; + } + // Note: we rely on `gcd` to perform further argument validation... + d = stdlib_base_gcdf( an, bn ); + if ( stdlib_base_is_nanf ( d ) ){ + return d; + } + + return ( an / d ) * bn; +} diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js new file mode 100644 index 000000000000..5a36a82e2ff1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 NINF = require( '@stdlib/constants/float32/ninf' ); +var lcmf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof lcmf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `NaN`', function test( t ) { + var v; + + v = lcmf( NaN, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `+infinity`', function test( t ) { + var v; + + v = lcmf( PINF, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( PINF, PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `-infinity`', function test( t ) { + var v; + + v = lcmf( NINF, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, NINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( NINF, NINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is not a floating-point integer', function test( t ) { + var v; + + v = lcmf( 3.14, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, 3.14 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 3.14, 6.18 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `0` if either argument is `0`', function test( t ) { + var v; + + v = lcmf( 0.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 2.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 0.0, -3.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + t.end(); +}); + +tape( 'the function computes the least common multiple', function test( t ) { + var v; + + v = lcmf( 6.0, 4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( 6.0, -4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( -6.0, -4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( 2.0, 8.0 ); + t.strictEqual( v, 8.0, 'returns 8' ); + + v = lcmf( 15.0, 20.0 ); + t.strictEqual( v, 60.0, 'returns 60' ); + + v = lcmf( 20.0, 15.0 ); + t.strictEqual( v, 60.0, 'returns 60' ); + + v = lcmf( 35.0, -21.0 ); + t.strictEqual( v, 105.0, 'returns 105' ); + + v = lcmf( 48.0, 18.0 ); + t.strictEqual( v, 144.0, 'returns 144' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.native.js new file mode 100644 index 000000000000..072c2491a7ce --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.native.js @@ -0,0 +1,161 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + +// VARIABLES // + +var lcmf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( lcmf instanceof Error ) +}; + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof lcmf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `NaN`', opts, function test( t ) { + var v; + + v = lcmf( NaN, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `+infinity`', opts, function test( t ) { + var v; + + v = lcmf( PINF, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( PINF, PINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `-infinity`', opts, function test( t ) { + var v; + + v = lcmf( NINF, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, NINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( NINF, NINF ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is not a valid floating-point number', opts, function test( t ) { + var v; + + v = lcmf( 3.14, 10.0 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10.0, 3.14 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 3.14, 6.18 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `0` if either argument is `0`', opts, function test( t ) { + var v = lcmf( 0.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 2.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 0.0, -3.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + t.end(); +}); + +tape( 'the function computes the least common multiple of two floating-point numbers', opts, function test( t ) { + var v; + + v = lcmf( 0.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 1.0, 0.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 0.0, 1.0 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + v = lcmf( 6.0, 4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( 6.0, -4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( -6.0, -4.0 ); + t.strictEqual( v, 12.0, 'returns 12' ); + + v = lcmf( 2.0, 8.0 ); + t.strictEqual( v, 8.0, 'returns 8' ); + + v = lcmf( 15.0, 20.0 ); + t.strictEqual( v, 60.0, 'returns 60' ); + + v = lcmf( 20.0, 15.0 ); + t.strictEqual( v, 60.0, 'returns 60' ); + + v = lcmf( 35.0, -21.0 ); + t.strictEqual( v, 105.0, 'returns 105' ); + + v = lcmf( 48.0, 18.0 ); + t.strictEqual( v, 144.0, 'returns 144' ); + + v = lcmf( 5.0, 6.0 ); + t.strictEqual( v, 30.0, 'returns 30' ); + + v = lcmf( 3.0, 8.0 ); + t.strictEqual( v, 24.0, 'returns 24' ); + + t.end(); +});