From 89e920f2f0cdcda840da7d0722a9f5e7f6df5b3e Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:05:09 +0530 Subject: [PATCH 01/10] feat: basic setup --- .../@stdlib/math/base/special/lcmf/README.md | 240 ++++++++++++++++++ .../math/base/special/lcmf/binding.gyp | 170 +++++++++++++ .../math/base/special/lcmf/include.gypi | 53 ++++ .../math/base/special/lcmf/manifest.json | 75 ++++++ .../math/base/special/lcmf/package.json | 72 ++++++ 5 files changed, 610 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/package.json 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..92d2afcf0e36 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/README.md @@ -0,0 +1,240 @@ + + +# lcmf + +> Compute the [least common multiple][lcm] (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] (lcm) of two single-precision floating-point numbers. + +```javascript +var v = lcmf( 48, 18 ); +// returns 144 +``` + +If either `a` or `b` is `0`, the function returns `0`. + +```javascript +var v = lcmf( 0, 0 ); +// returns 0 + +v = lcmf( 2, 0 ); +// returns 0 + +v = lcmf( 0, 3 ); +// returns 0 +``` + +Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. + +```javascript +var v = lcmf( 3.14, 18 ); +// returns NaN + +v = lcmf( 48, 3.14 ); +// returns NaN + +v = lcmf( NaN, 18 ); +// returns NaN + +v = lcmf( 48, NaN ); +// 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 a; +var b; +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] (lcm) of two single-precision floating-point numbers. + +```c +double v = stdlib_base_lcmf( 48.0f, 18.0f ); +// returns 144.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( "lcmf(%f, %f) = %f\n", a[ i ], b[ i ], out ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + 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/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': [ + '=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", + "lowest common multiple", + "smallest common multiple", + "lowest common denominator", + "lcm", + "lcd", + "discrete", + "arithmetic", + "integer", + "gcd" + ] +} From b028c87e1e84cd248c0da4edc2199563926b4dd0 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:17:58 +0530 Subject: [PATCH 02/10] feat: basic c files added --- .../include/stdlib/math/base/special/lcmf.h | 38 ++++++++++ .../math/base/special/lcmf/src/Makefile | 70 +++++++++++++++++++ .../math/base/special/lcmf/src/addon.c | 22 ++++++ .../@stdlib/math/base/special/lcmf/src/main.c | 58 +++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/include/stdlib/math/base/special/lcmf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/include/stdlib/math/base/special/lcmf.h b/lib/node_modules/@stdlib/math/base/special/lcmf/include/stdlib/math/base/special/lcmf.h new file mode 100644 index 000000000000..399bf9664e45 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/include/stdlib/math/base/special/lcmf.h @@ -0,0 +1,38 @@ +/** +* @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. +*/ + +#ifndef STDLIB_MATH_BASE_SPECIAL_LCMF_H +#define STDLIB_MATH_BASE_SPECIAL_LCMF_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Computes the least common multiple (lcm) of two single-precision floating-point numbers. +*/ +float stdlib_base_lcmf( const float a, const float b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_LCMF_H 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..fd0997898913 --- /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/binary.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..7477dc361c06 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c @@ -0,0 +1,58 @@ +/** +* @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 +* double 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.0f ) { + an = -a; + } else { + an = a; + } + if ( b < 0.0f ) { + bn = -b; + } else { + bn = b; + } + // Note: we rely on `gcdf` to perform further argument validation... + d = stdlib_base_gcdf( an, bn ); + if ( stdlib_base_is_nanf( d ) ) { + return d; + } + return ( an / d ) * bn; +} From 13ddb811c393277aafe43ea40e5edb76f10798c7 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:20:37 +0530 Subject: [PATCH 03/10] feat: basic js files added --- .../math/base/special/lcmf/lib/index.js | 40 +++++++++++ .../math/base/special/lcmf/lib/main.js | 70 +++++++++++++++++++ .../math/base/special/lcmf/lib/native.js | 55 +++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js 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..b749d82611bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 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( 21, 6 ); +* // returns 42 +*/ + +// 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..f7ff64a4268c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 {integer} a - integer +* @param {integer} b - integer +* @returns {integer} least common multiple +* +* @example +* var v = lcmf( 21, 6 ); +* // returns 42 +* +* @example +* var v = lcmf( 3.14, 6 ); +* // returns NaN +* +* @example +* var v = lcmf( NaN, 6 ); +* // 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 `gcdf` to perform further argument validation... + d = gcdf( 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..c84d84119fab --- /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 {integer} a - integer +* @param {integer} b - integer +* @returns {number} 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 +*/ +function lcmf( a, b ) { + return addon( a, b ); +} + + +// EXPORTS // + +module.exports = lcmf; From b1f4e3eea60d209fa13c64b5e4c7fda82a97d799 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:27:16 +0530 Subject: [PATCH 04/10] feat: tests added --- .../math/base/special/lcmf/test/test.js | 148 +++++++++++++++++ .../base/special/lcmf/test/test.native.js | 157 ++++++++++++++++++ 2 files changed, 305 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/test/test.native.js 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..213bc600dee8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js @@ -0,0 +1,148 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 an integer value', function test( t ) { + var v; + + v = lcmf( 3.14, 10 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 = lcmf( 0, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 2, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 0, -3 ); + t.strictEqual( v, 0, 'returns 0' ); + + t.end(); +}); + +tape( 'the function computes the least common multiple', function test( t ) { + var v; + + v = lcmf( 0, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 1, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 0, 1 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 6, 4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( 6, -4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( -6, -4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( 2, 8 ); + t.strictEqual( v, 8, 'returns 8' ); + + v = lcmf( 15, 20 ); + t.strictEqual( v, 60, 'returns 60' ); + + v = lcmf( 20, 15 ); + t.strictEqual( v, 60, 'returns 60' ); + + v = lcmf( 35, -21 ); + t.strictEqual( v, 105, 'returns 105' ); + + v = lcmf( 48, 18 ); + t.strictEqual( v, 144, '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..e0e8486cec8e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.native.js @@ -0,0 +1,157 @@ +/** +* @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/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 an integer value', opts, function test( t ) { + var v; + + v = lcmf( 3.14, 10 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + v = lcmf( 10, 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 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 2, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 0, -3 ); + t.strictEqual( v, 0, 'returns 0' ); + + t.end(); +}); + +tape( 'the function computes the least common multiple', opts, function test( t ) { + var v; + + v = lcmf( 0, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 1, 0 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 0, 1 ); + t.strictEqual( v, 0, 'returns 0' ); + + v = lcmf( 6, 4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( 6, -4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( -6, -4 ); + t.strictEqual( v, 12, 'returns 12' ); + + v = lcmf( 2, 8 ); + t.strictEqual( v, 8, 'returns 8' ); + + v = lcmf( 15, 20 ); + t.strictEqual( v, 60, 'returns 60' ); + + v = lcmf( 20, 15 ); + t.strictEqual( v, 60, 'returns 60' ); + + v = lcmf( 35, -21 ); + t.strictEqual( v, 105, 'returns 105' ); + + v = lcmf( 48, 18 ); + t.strictEqual( v, 144, 'returns 144' ); + + t.end(); +}); From 80ea46f2d57213b511859102bfb017ce162d199d Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:29:22 +0530 Subject: [PATCH 05/10] feat: docs added --- .../math/base/special/lcmf/docs/repl.txt | 31 ++++++++++ .../base/special/lcmf/docs/types/index.d.ts | 50 +++++++++++++++++ .../math/base/special/lcmf/docs/types/test.ts | 56 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/test.ts 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..9819b5c2a818 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt @@ -0,0 +1,31 @@ + +{{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..3a1b04aba2db --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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`. +* - Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. +* +* @param a - integer +* @param b - integer +* @returns least common multiple +* +* @example +* var v = lcmf( 21, 6 ); +* // returns 42 +* +* @example +* var v = lcmf( 3.14, 6 ); +* // returns NaN +* +* @example +* var v = lcmf( NaN, 6 ); +* // 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..d3614c79d547 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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( 8, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + lcmf( true, 3 ); // $ExpectError + lcmf( false, 2 ); // $ExpectError + lcmf( '5', 1 ); // $ExpectError + lcmf( [], 1 ); // $ExpectError + lcmf( {}, 2 ); // $ExpectError + lcmf( ( x: number ): number => x, 2 ); // $ExpectError + + lcmf( 9, true ); // $ExpectError + lcmf( 9, false ); // $ExpectError + lcmf( 5, '5' ); // $ExpectError + lcmf( 8, [] ); // $ExpectError + lcmf( 9, {} ); // $ExpectError + lcmf( 8, ( x: number ): number => x ); // $ExpectError + + lcmf( [], true ); // $ExpectError + lcmf( {}, false ); // $ExpectError + lcmf( false, '5' ); // $ExpectError + lcmf( {}, [] ); // $ExpectError + lcmf( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + lcmf(); // $ExpectError + lcmf( 3 ); // $ExpectError +} From 7074eb6652e735fece38cc6f24ff3183f5ae2c82 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:31:19 +0530 Subject: [PATCH 06/10] feat: docs added --- .../base/special/lcmf/examples/c/Makefile | 146 ++++++++++++++++++ .../base/special/lcmf/examples/c/example.c | 32 ++++ .../math/base/special/lcmf/examples/index.js | 35 +++++ 3 files changed, 213 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js 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..2f7806162498 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/c/example.c @@ -0,0 +1,32 @@ +/** +* @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 + +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( "lcmf(%f, %f) = %f\n", a[ i ], b[ i ], out ); + } +} 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..7f1956de4545 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var lcmf = require( './../lib' ); + +var a; +var b; +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 ); +} From 678e01562851fce3e92d207eeebd1af55df99be4 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:34:11 +0530 Subject: [PATCH 07/10] feat: benchmark added --- .../base/special/lcmf/benchmark/benchmark.js | 54 +++++++ .../lcmf/benchmark/benchmark.native.js | 63 ++++++++ .../special/lcmf/benchmark/c/native/Makefile | 146 ++++++++++++++++++ .../lcmf/benchmark/c/native/benchmark.c | 135 ++++++++++++++++ 4 files changed, 398 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/benchmark.c 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..51ca31e8906d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 round = require( '@stdlib/math/base/special/round' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var lcmf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = round( randu() * 50.0 ); + y = round( randu() * 50.0 ); + z = lcmf( x, y ); + 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..c4def26ea0c7 --- /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/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +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; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = round( randu() * 50.0 ); + y = round( randu() * 50.0 ); + z = lcmf( x, y ); + 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..f69e9da2b4d3 --- /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 (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/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..ae5748f7bb2d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/benchmark.c @@ -0,0 +1,135 @@ +/** +* @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 "lcm" +#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 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; + float x; + float y; + float z; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = round( rand_float() * 500.0f ); + y = round( rand_float() * 500.0f ); + z = stdlib_base_lcmf( x, y ); + 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; + + // 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 ); +} From 21af19e12d511810d8a493fc1cd5d8e97bf5189c Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:45:12 +0530 Subject: [PATCH 08/10] fix: cppcheck-suppress shadowFunction --- lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c | 1 + 1 file changed, 1 insertion(+) 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 index fd0997898913..a1fea24f71a6 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/addon.c @@ -19,4 +19,5 @@ #include "stdlib/math/base/special/lcmf.h" #include "stdlib/math/base/napi/binary.h" +// cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_lcmf ) From 883bd8d50eb2aad84690a484a5364c3357afd2f9 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 19 Nov 2024 21:36:57 +0530 Subject: [PATCH 09/10] chore: changes from code review --- .../@stdlib/math/base/special/lcmf/README.md | 8 +-- .../base/special/lcmf/benchmark/benchmark.js | 12 ++--- .../lcmf/benchmark/benchmark.native.js | 10 ++-- .../lcmf/benchmark/c/native/benchmark.c | 23 ++++---- .../math/base/special/lcmf/docs/repl.txt | 4 +- .../base/special/lcmf/docs/types/index.d.ts | 2 +- .../math/base/special/lcmf/docs/types/test.ts | 2 +- .../math/base/special/lcmf/examples/index.js | 8 +-- .../math/base/special/lcmf/lib/index.js | 2 +- .../math/base/special/lcmf/lib/main.js | 5 +- .../@stdlib/math/base/special/lcmf/src/main.c | 2 +- .../math/base/special/lcmf/test/test.js | 54 +++++++++---------- .../base/special/lcmf/test/test.native.js | 52 +++++++++--------- 13 files changed, 94 insertions(+), 90 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/lcmf/README.md b/lib/node_modules/@stdlib/math/base/special/lcmf/README.md index 92d2afcf0e36..9215e3bac914 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/README.md @@ -102,7 +102,7 @@ v = lcmf( 48, NaN ); ```javascript var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); var lcmf = require( '@stdlib/math/base/special/lcmf' ); var a; @@ -111,8 +111,8 @@ var v; var i; for ( i = 0; i < 100; i++ ) { - a = round( randu()*50 ); - b = round( randu()*50 ); + a = roundf( randu() * 50 ); + b = roundf( randu() * 50 ); v = lcmf( a, b ); console.log( 'lcmf(%d,%d) = %d', a, b, v ); } @@ -153,7 +153,7 @@ for ( i = 0; i < 100; i++ ) { Computes the [least common multiple][lcm] (lcm) of two single-precision floating-point numbers. ```c -double v = stdlib_base_lcmf( 48.0f, 18.0f ); +float v = stdlib_base_lcmf( 48.0f, 18.0f ); // returns 144.0f ``` 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 index 51ca31e8906d..0551712152c6 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = 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' ); @@ -36,11 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = discreteUniform( 100, 1.0, 100.0 ); + y = discreteUniform( 100, 1.0, 100.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = round( randu() * 50.0 ); - y = round( randu() * 50.0 ); - z = lcmf( x, y ); + z = lcmf( x[ i % x.length ], y[ i % y.length ] ); if ( isnanf( z ) ) { b.fail( 'should not return NaN' ); } 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 index c4def26ea0c7..930fb72b773f 100644 --- 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 @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = 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; @@ -45,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; + x = discreteUniform( 100, 1.0, 100.0 ); + y = discreteUniform( 100, 1.0, 100.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = round( randu() * 50.0 ); - y = round( randu() * 50.0 ); - z = lcmf( x, y ); + z = lcmf( x[ i % x.length ], y[ i % y.length ] ); if ( isnanf( z ) ) { b.fail( 'should not return NaN' ); } 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 index ae5748f7bb2d..0bd824ad5e14 100644 --- 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 @@ -23,7 +23,7 @@ #include #include -#define NAME "lcm" +#define NAME "lcmf" #define ITERATIONS 1000000 #define REPEATS 3 @@ -91,27 +91,30 @@ static float rand_float( void ) { */ static double benchmark( void ) { double elapsed; - float x; - float y; - float z; + float a[ 100 ]; + float b[ 100 ]; double t; + float y; int i; + for ( i = 0; i < 100; i++ ) { + a[ i ] = roundf( 500.0f * rand_float() ); + b[ i ] = roundf( 500.0f * rand_float() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = round( rand_float() * 500.0f ); - y = round( rand_float() * 500.0f ); - z = stdlib_base_lcmf( x, y ); - if ( z != z ) { + y = stdlib_base_lcmf( a[ i % 100 ], b[ i % 100 ] ); + if ( y != y ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( z != z ) { + if ( y != y ) { printf( "should not return NaN\n" ); } - return elapsed; + return elapsed; } /** 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 index 9819b5c2a818..f03302c19ab8 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( a, b ) - Computes the least common multiple (lcm) of two - single-precision floating-point numbers. + Computes the least common multiple (lcm) of two single-precision + floating-point numbers. If either `a` or `b` is `0`, the function returns `0`. 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 index 3a1b04aba2db..690215aec199 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. 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 index d3614c79d547..659720ca8cb9 100644 --- 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 @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. 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 index 7f1956de4545..762dd5382e7d 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -19,7 +19,7 @@ 'use strict'; var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); var lcmf = require( './../lib' ); var a; @@ -28,8 +28,8 @@ var v; var i; for ( i = 0; i < 100; i++ ) { - a = round( randu() * 50 ); - b = round( randu() * 50 ); + a = roundf( randu() * 50 ); + b = roundf( randu() * 50 ); v = lcmf( a, b ); console.log( 'lcmf(%d,%d) = %d', a, b, v ); } 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 index b749d82611bf..d7e4d8ddc6bb 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. 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 index f7ff64a4268c..d22e4857d296 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -56,12 +56,13 @@ function lcmf( a, b ) { if ( b < 0 ) { b = -b; } + // Note: we rely on `gcdf` to perform further argument validation... d = gcdf( a, b ); if ( isnanf( d ) ) { return d; } - return (a/d) * b; + return ( a / d ) * b; } 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 index 7477dc361c06..b7a9ff140b76 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c @@ -28,7 +28,7 @@ * @return least common multiple * * @example -* double out = stdlib_base_lcmf( 21.0f, 6.0f ); +* float out = stdlib_base_lcmf( 21.0f, 6.0f ); * // returns 42.0f */ float stdlib_base_lcmf( const float a, const float b ) { 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 index 213bc600dee8..60b33d12c4dc 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -39,13 +39,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', function test( t var v; v = lcmf( NaN, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -54,13 +54,13 @@ tape( 'the function returns `NaN` if either argument is `+infinity`', function t var v; v = lcmf( PINF, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, PINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( PINF, PINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -69,13 +69,13 @@ tape( 'the function returns `NaN` if either argument is `-infinity`', function t var v; v = lcmf( NINF, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, NINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( NINF, NINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -84,26 +84,26 @@ tape( 'the function returns `NaN` if either argument is not an integer value', f var v; v = lcmf( 3.14, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, 3.14 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 3.14, 6.18 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `0` if either argument is `0`', function test( t ) { var v = lcmf( 0, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 2, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 0, -3 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); t.end(); }); @@ -112,37 +112,37 @@ tape( 'the function computes the least common multiple', function test( t ) { var v; v = lcmf( 0, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 1, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 0, 1 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 6, 4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( 6, -4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( -6, -4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( 2, 8 ); - t.strictEqual( v, 8, 'returns 8' ); + t.strictEqual( v, 8, 'returns expected value' ); v = lcmf( 15, 20 ); - t.strictEqual( v, 60, 'returns 60' ); + t.strictEqual( v, 60, 'returns expected value' ); v = lcmf( 20, 15 ); - t.strictEqual( v, 60, 'returns 60' ); + t.strictEqual( v, 60, 'returns expected value' ); v = lcmf( 35, -21 ); - t.strictEqual( v, 105, 'returns 105' ); + t.strictEqual( v, 105, 'returns expected value' ); v = lcmf( 48, 18 ); - t.strictEqual( v, 144, 'returns 144' ); + t.strictEqual( v, 144, 'returns expected value' ); 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 index e0e8486cec8e..b674f5425785 100644 --- 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 @@ -48,13 +48,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', opts, function t var v; v = lcmf( NaN, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( NaN, NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -63,13 +63,13 @@ tape( 'the function returns `NaN` if either argument is `+infinity`', opts, func var v; v = lcmf( PINF, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, PINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( PINF, PINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -78,13 +78,13 @@ tape( 'the function returns `NaN` if either argument is `-infinity`', opts, func var v; v = lcmf( NINF, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, NINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( NINF, NINF ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -93,26 +93,26 @@ tape( 'the function returns `NaN` if either argument is not an integer value', o var v; v = lcmf( 3.14, 10 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 10, 3.14 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = lcmf( 3.14, 6.18 ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `0` if either argument is `0`', opts, function test( t ) { var v = lcmf( 0, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 2, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 0, -3 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); t.end(); }); @@ -121,37 +121,37 @@ tape( 'the function computes the least common multiple', opts, function test( t var v; v = lcmf( 0, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 1, 0 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 0, 1 ); - t.strictEqual( v, 0, 'returns 0' ); + t.strictEqual( v, 0, 'returns expected value' ); v = lcmf( 6, 4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( 6, -4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( -6, -4 ); - t.strictEqual( v, 12, 'returns 12' ); + t.strictEqual( v, 12, 'returns expected value' ); v = lcmf( 2, 8 ); - t.strictEqual( v, 8, 'returns 8' ); + t.strictEqual( v, 8, 'returns expected value' ); v = lcmf( 15, 20 ); - t.strictEqual( v, 60, 'returns 60' ); + t.strictEqual( v, 60, 'returns expected value' ); v = lcmf( 20, 15 ); - t.strictEqual( v, 60, 'returns 60' ); + t.strictEqual( v, 60, 'returns expected value' ); v = lcmf( 35, -21 ); - t.strictEqual( v, 105, 'returns 105' ); + t.strictEqual( v, 105, 'returns expected value' ); v = lcmf( 48, 18 ); - t.strictEqual( v, 144, 'returns 144' ); + t.strictEqual( v, 144, 'returns expected value' ); t.end(); }); From 9b7b0c56478295c60bf3406c74365b1ea4721cd8 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 19 Nov 2024 21:47:37 +0530 Subject: [PATCH 10/10] chore: stuff from code review --- lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c | 1 + 1 file changed, 1 insertion(+) 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 index b7a9ff140b76..60f1f3d28ae2 100644 --- a/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c @@ -49,6 +49,7 @@ float stdlib_base_lcmf( const float a, const float b ) { } else { bn = b; } + // Note: we rely on `gcdf` to perform further argument validation... d = stdlib_base_gcdf( an, bn ); if ( stdlib_base_is_nanf( d ) ) {