From 6cb67c5777492b226e54f250b3852e0b5e36332c Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:29:49 +0530 Subject: [PATCH 01/20] feat: added C files --- .../@stdlib/math/base/special/gcdf/README.md | 243 ++++++++++++++++++ .../math/base/special/gcdf/binding.gyp | 170 ++++++++++++ .../math/base/special/gcdf/include.gypi | 53 ++++ .../include/stdlib/math/base/special/gcdf.h | 38 +++ .../math/base/special/gcdf/manifest.json | 84 ++++++ .../math/base/special/gcdf/package.json | 199 ++++++++++++++ .../math/base/special/gcdf/src/Makefile | 70 +++++ .../math/base/special/gcdf/src/addon.c | 22 ++ .../@stdlib/math/base/special/gcdf/src/main.c | 183 +++++++++++++ 9 files changed, 1062 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md new file mode 100644 index 000000000000..cf09aa6051ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md @@ -0,0 +1,243 @@ + + +# gcd + +> Compute the [greatest common divisor][gcd] (gcd). + + + +
+ +The [greatest common divisor][gcd] (gcd) of two non-zero integers `a` and `b` is the largest positive integer which divides both `a` and `b` without a remainder. The gcd is also known as the **greatest common factor** (gcf), **highest common factor** (hcf), **highest common divisor**, and **greatest common measure** (gcm). + +
+ + + + + +
+ +## Usage + +```javascript +var gcdf = require( '@stdlib/math/base/special/gcdf' ); +``` + +#### gcdf( a, b ) + +Computes the [greatest common divisor][gcd] (gcd). + +```javascript +var v = gcdf( 48, 18 ); +// returns 6 +``` + +If both `a` and `b` are `0`, the function returns `0`. + +```javascript +var v = gcdf( 0, 0 ); +// returns 0 +``` + +Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. + +```javascript +var v = gcdf( 3.14, 18 ); +// returns NaN + +v = gcdf( 48, 3.14 ); +// returns NaN + +v = gcdf( NaN, 18 ); +// returns NaN + +v = gcdf( 48, NaN ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gcdf = require( '@stdlib/math/base/special/gcdf' ); + +var a = discreteUniform( 100, 0, 50 ); +var b = discreteUniform( a.length, 0, 50 ); + +var i; +for ( i = 0; i < a.length; i++ ) { + console.log( 'gcd(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/gcdf.h" +``` + +#### stdlib_base_gcdf( a, b ) + +Computes the greatest common divisor (gcd). + +```c +float v = stdlib_base_gcdf( 48.0, 18.0 ); +// returns 6.0 +``` + +The function accepts the following arguments: + +- **a**: `[in] float` input value. +- **b**: `[in] float` input value. + +```c +float stdlib_base_gcdf( const float a, const float b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/gcdf.h" +#include + +int main( void ) { + const float a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const float b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_gcdf( a[ i ], b[ i ] ); + printf( "gcd(%f, %f) = %f\n", a[ i ], b[ i ], out ); + } +} +``` + +
+ + + +
+ + + + + +
+ +## References + +- Stein, Josef. 1967. "Computational problems associated with Racah algebra." _Journal of Computational Physics_ 1 (3): 397–405. doi:[10.1016/0021-9991(67)90047-2][@stein:1967]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/gcdf/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/include.gypi b/lib/node_modules/@stdlib/math/base/special/gcdf/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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", + "stein", + "binary gcd", + "greatest common divisor", + "greatest common factor", + "highest common factor", + "greatest common measure", + "highest common divisor", + "gcd", + "gcf", + "hcf", + "gcm", + "arithmetic", + "integer" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "gcd", + "alias": "gcd", + "pkg_desc": "compute the greatest common divisor (gcd)", + "desc": "computes the greatest common divisor (gcd)", + "short_desc": "greatest common divisor (gcd)", + "parameters": [ + { + "name": "a", + "desc": "first number", + "type": { + "javascript": "integer", + "jsdoc": "integer", + "c": "double", + "dtype": "float64" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/discrete-uniform", + "parameters": [ + 0, + 50 + ] + }, + "example_values": [ + 1, + 2, + 4, + 5, + 9, + 10, + 15, + 20, + 21, + 25, + 28, + 30, + 33, + 35, + 39, + 40, + 42, + 45, + 48, + 50 + ] + }, + { + "name": "b", + "desc": "second number", + "type": { + "javascript": "integer", + "jsdoc": "integer", + "c": "double", + "dtype": "float64" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/discrete-uniform", + "parameters": [ + 0, + 50 + ] + }, + "example_values": [ + 1, + 2, + 4, + 5, + 9, + 10, + 15, + 20, + 21, + 25, + 28, + 30, + 33, + 35, + 39, + 40, + 42, + 45, + 48, + 50 + ] + } + ], + "returns": { + "desc": "greatest common divisor", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + } + }, + "keywords": [ + "binary gcd", + "greatest common divisor", + "greatest common factor", + "highest common factor", + "greatest common measure", + "highest common divisor", + "gcd", + "gcf", + "hcf", + "gcm" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/gcdf/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c new file mode 100644 index 000000000000..33b2779866bc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_gcdf ) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c new file mode 100644 index 000000000000..710cc09dc98f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c @@ -0,0 +1,183 @@ +/** +* @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/gcdf.h" +#include "stdlib/math/base/special/fmod.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/assert/is_integerf.h" +#include "stdlib/constants/float32/pinf.h" +#include "stdlib//constants/float32/ninf.h" +#include + +// 2^32 - 1 +static const int32_t STDLIB_CONSTANT_INT32_MAX = 2147483647; + +/** +* Computes the greatest common divisor (gcd) using the binary GCD algorithm. +* +* @param a first number +* @param b second number +* @return greatest common divisor +* +* @example +* float out = largeIntegersf(16777216.0, 65536.0); +* // returns 65536.0 +*/ +static float largeIntegersf( const float a, const float b ) { + float ac; + float bc; + float k; + float t; + + // Simple cases: + if ( a == 0.0 ) { + return b; + } + if ( b == 0.0 ) { + return a; + } + ac = a; + bc = b; + k = 1.0; + + // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... + while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 && stdlib_base_fmod( bc, 2.0 ) == 0.0 ) { + ac /= 2.0; // right shift + bc /= 2.0; // right shift + k *= 2.0; // left shift + } + // Reduce `a` to an odd number... + while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 ) { + ac /= 2.0; // right shift + } + // Henceforth, `a` is always odd... + while ( bc ) { + // Remove all factors of 2 in `b`, as they are not common... + while ( stdlib_base_fmod( bc, 2.0 ) == 0.0 ) { + bc /= 2.0; // right shift + } + // `a` and `b` are both odd. Swap values such that `b` is the larger of the two values, and then set `b` to the difference (which is even)... + if ( ac > bc ) { + t = bc; + bc = ac; + ac = t; + } + bc -= ac; // b=0 iff b=a + } + // Restore common factors of 2... + return k * ac; +} + +/** +* Computes the greatest common divisor (gcd) using the binary GCD algorithm and bitwise operations. +* +* @param a first number +* @param b second number +* @return greatest common divisor +* +* @example +* float out = bitwisef( 48.0, 18.0 ); +* // returns 6.0 +*/ +static float bitwisef( const float a, const float b ) { + int32_t ac; + int32_t bc; + int32_t k; + int32_t t; + + // Simple cases: + if ( a == 0.0 ) { + return b; + } + if ( b == 0.0 ) { + return a; + } + ac = (int32_t)a; + bc = (int32_t)b; + k = 0; + + // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... + while ( (ac & 1) == 0 && (bc & 1) == 0 ) { + ac >>= 1; // right shift + bc >>= 1; // right shift + k += 1; + } + // Reduce `a` to an odd number... + while ( (ac & 1) == 0 ) { + ac >>= 1; // right shift + } + // Henceforth, `a` is always odd... + while ( bc ) { + // Remove all factors of 2 in `b`, as they are not common... + while ( (bc & 1) == 0 ) { + bc >>= 1; // right shift + } + // `a` and `b` are both odd. Swap values such that `b` is the larger of the two values, and then set `b` to the difference (which is even)... + if ( ac > bc ) { + t = bc; + bc = ac; + ac = t; + } + bc -= ac; // b=0 iff b=a + } + // Restore common factors of 2... + return ac << k; +} + +/** +* Computes the greatest common divisor (gcd). +* +* @param a first number +* @param b second number +* @return greatest common divisor +* +* @example +* float out = stdlib_base_gcdf( 48.0, 18.0 ); +* // returns 6.0 +*/ +float stdlib_base_gcdf( const float a, const float b ) { + float ac; + float bc; + + if ( stdlib_base_is_nanf( a ) || stdlib_base_is_nanf( b ) ) { + return 0.0/0.0; // NaN + } + if ( + a == STDLIB_CONSTANT_FLOAT32_PINF || + b == STDLIB_CONSTANT_FLOAT32_PINF || + a == STDLIB_CONSTANT_FLOAT32_NINF || + b == STDLIB_CONSTANT_FLOAT32_NINF + ) { + return 0.0/0.0; // NaN + } + if ( !( stdlib_base_is_integerf( a ) && stdlib_base_is_integerf( b ) ) ) { + return 0.0/0.0; // NaN + } + ac = a; + bc = b; + if ( ac < 0 ) { + ac = -ac; + } + if ( bc < 0 ) { + bc = -bc; + } + if ( ac <= STDLIB_CONSTANT_INT32_MAX && bc <= STDLIB_CONSTANT_INT32_MAX ) { + return bitwisef( ac, bc ); + } + return largeIntegersf( ac, bc ); +} From 9f038924580dfb0e28f1a2ad6cf84e1d08ac3787 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:58:33 +0530 Subject: [PATCH 02/20] feat: added js files and tests --- .../math/base/special/gcdf/test/test.js | 162 +++++++++++++++++ .../base/special/gcdf/test/test.native.js | 171 ++++++++++++++++++ 2 files changed, 333 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js new file mode 100644 index 000000000000..b2be3c06f91d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js @@ -0,0 +1,162 @@ +/** +* @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 gcdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `NaN`', function test( t ) { + var v; + + v = gcdf( NaN, 10 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( 10, NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( NaN, NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `+infinity`', function test( t ) { + var v; + + v = gcdf( PINF, 10 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( 10, PINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( PINF, PINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `-infinity`', function test( t ) { + var v; + + v = gcdf( NINF, 10 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( 10, NINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( NINF, NINF ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is not an integer value', function test( t ) { + var v; + + v = gcdf( 3.14, 10 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( 10, 3.14 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = gcdf( 3.14, 6.18 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the greatest common divisor', function test( t ) { + var v; + + v = gcdf( 0, 0 ); + t.strictEqual( v, 0, 'returns expected value' ); + + v = gcdf( 1, 0 ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = gcdf( 0, 1 ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = gcdf( 6, 4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( 6, -4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( -6, -4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( 15, 20 ); + t.strictEqual( v, 5, 'returns expected value' ); + + v = gcdf( 20, 15 ); + t.strictEqual( v, 5, 'returns expected value' ); + + v = gcdf( 35, -21 ); + t.strictEqual( v, 7, 'returns expected value' ); + + v = gcdf( 48, 18 ); + t.strictEqual( v, 6, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing large integers (>= 2**31 - 1)', function test( t ) { + var TWO_100 = 1.2676506002282294e+30; + var TWO_53 = 9007199254740992; + var v; + + v = gcdf( TWO_100, 0 ); + t.strictEqual( v, TWO_100, 'returns expected value' ); + + v = gcdf( 0, TWO_53 ); + t.strictEqual( v, TWO_53, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, TWO_53 ); + t.strictEqual( v, TWO_53, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, 73453 ); + t.strictEqual( v, 1, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, 3491832 ); + t.strictEqual( v, 8, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( 3491832, TWO_100 ); + t.strictEqual( v, 8, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js new file mode 100644 index 000000000000..93336e5696a4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js @@ -0,0 +1,171 @@ +/** +* @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 isnan = 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 gcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( gcdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcd, '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 = gcdf( NaN, 10 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( 10, NaN ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( NaN, NaN ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `+infinity`', opts, function test( t ) { + var v; + + v = gcdf( PINF, 10 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( 10, PINF ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( PINF, PINF ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is `-infinity`', opts, function test( t ) { + var v; + + v = gcdf( NINF, 10 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( 10, NINF ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( NINF, NINF ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if either argument is not an integer value', opts, function test( t ) { + var v; + + v = gcdf( 3.14, 10 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( 10, 3.14 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = gcdf( 3.14, 6.18 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the greatest common divisor', opts, function test( t ) { + var v; + + v = gcdf( 0, 0 ); + t.strictEqual( v, 0, 'returns expected value' ); + + v = gcdf( 1, 0 ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = gcdf( 0, 1 ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = gcdf( 6, 4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( 6, -4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( -6, -4 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = gcdf( 15, 20 ); + t.strictEqual( v, 5, 'returns expected value' ); + + v = gcdf( 20, 15 ); + t.strictEqual( v, 5, 'returns expected value' ); + + v = gcdf( 35, -21 ); + t.strictEqual( v, 7, 'returns expected value' ); + + v = gcdf( 48, 18 ); + t.strictEqual( v, 6, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing large integers (>= 2**31 - 1)', opts, function test( t ) { + var TWO_100 = 1.2676506002282294e+30; + var TWO_53 = 9007199254740992; + var v; + + v = gcdf( TWO_100, 0 ); + t.strictEqual( v, TWO_100, 'returns expected value' ); + + v = gcdf( 0, TWO_53 ); + t.strictEqual( v, TWO_53, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, TWO_53 ); + t.strictEqual( v, TWO_53, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, 73453 ); + t.strictEqual( v, 1, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( TWO_100, 3491832 ); + t.strictEqual( v, 8, 'returns expected value' ); + + // Verified on Wolfram Alpha: + v = gcdf( 3491832, TWO_100 ); + t.strictEqual( v, 8, 'returns expected value' ); + + t.end(); +}); From e142976cfa859209f80e58053981e220101eb742 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:02:13 +0530 Subject: [PATCH 03/20] feat: lib js files added --- .../math/base/special/gcdf/lib/binary_gcd.js | 81 ++++++++++++++++++ .../special/gcdf/lib/bitwise_binary_gcd.js | 81 ++++++++++++++++++ .../math/base/special/gcdf/lib/index.js | 40 +++++++++ .../math/base/special/gcdf/lib/main.js | 83 +++++++++++++++++++ .../math/base/special/gcdf/lib/native.js | 51 ++++++++++++ 5 files changed, 336 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js new file mode 100644 index 000000000000..1fe947d71708 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js @@ -0,0 +1,81 @@ +/** +* @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'; + +/** +* Computes the greatest common divisor (gcd) using the binary GCD algorithm. +* +* ## References +* +* - Stein, Josef. 1967. "Computational problems associated with Racah algebra." _Journal of Computational Physics_ 1 (3): 397–405. doi:[10.1016/0021-9991(67)90047-2][@stein:1967]. +* +* [@stein:1967]: https://doi.org/10.1016/0021-9991(67)90047-2 +* +* @private +* @param {integer} a - first number +* @param {integer} b - second number +* @returns {integer} greatest common divisor +* +* @example +* var v = gcdf( 16777216.0, 65536.0 ); +* // returns 65536 +*/ +function gcdf( a, b ) { + var k = 1; + var t; + + // Simple cases: + if ( a === 0 ) { + return b; + } + if ( b === 0 ) { + return a; + } + // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... + while ( a%2 === 0 && b%2 === 0 ) { + a /= 2; // right shift + b /= 2; // right shift + k *= 2; // left shift + } + // Reduce `a` to an odd number... + while ( a%2 === 0 ) { + a /= 2; // right shift + } + // Henceforth, `a` is always odd... + while ( b ) { + // Remove all factors of 2 in `b`, as they are not common... + while ( b%2 === 0 ) { + b /= 2; // right shift + } + // `a` and `b` are both odd. Swap values such that `b` is the larger of the two values, and then set `b` to the difference (which is even)... + if ( a > b ) { + t = b; + b = a; + a = t; + } + b -= a; // b=0 iff b=a + } + // Restore common factors of 2... + return k * a; +} + + +// EXPORTS // + +module.exports = gcdf; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js new file mode 100644 index 000000000000..545facd8568c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js @@ -0,0 +1,81 @@ +/** +* @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'; + +/** +* Computes the greatest common divisor (gcd) using the binary GCD algorithm and bitwise operations. +* +* ## References +* +* - Stein, Josef. 1967. "Computational problems associated with Racah algebra." _Journal of Computational Physics_ 1 (3): 397–405. doi:[10.1016/0021-9991(67)90047-2][@stein:1967]. +* +* [@stein:1967]: https://doi.org/10.1016/0021-9991(67)90047-2 +* +* @private +* @param {integer32} a - first number +* @param {integer32} b - second number +* @returns {integer32} greatest common divisor +* +* @example +* var v = gcdf( 48, 18 ); +* // returns 6 +*/ +function gcdf( a, b ) { + var k = 0; + var t; + + // Simple cases: + if ( a === 0 ) { + return b; + } + if ( b === 0 ) { + return a; + } + // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... + while ( (a & 1) === 0 && (b & 1) === 0 ) { + a >>>= 1; // right shift + b >>>= 1; // right shift + k += 1; + } + // Reduce `a` to an odd number... + while ( (a & 1) === 0 ) { + a >>>= 1; // right shift + } + // Henceforth, `a` is always odd... + while ( b ) { + // Remove all factors of 2 in `b`, as they are not common... + while ( (b & 1) === 0 ) { + b >>>= 1; // right shift + } + // `a` and `b` are both odd. Swap values such that `b` is the larger of the two values, and then set `b` to the difference (which is even)... + if ( a > b ) { + t = b; + b = a; + a = t; + } + b -= a; // b=0 iff b=a + } + // Restore common factors of 2... + return a << k; +} + + +// EXPORTS // + +module.exports = gcdf; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js new file mode 100644 index 000000000000..ae86154475f0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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 greatest common divisor (gcd). +* +* @module @stdlib/math/base/special/gcdf +* +* @example +* var gcd = require( '@stdlib/math/base/special/gcdf' ); +* +* var v = gcdf( 48, 18 ); +* // returns 6 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js new file mode 100644 index 000000000000..f7e277a83736 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js @@ -0,0 +1,83 @@ +/** +* @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 isIntegerf = require( '@stdlib/math/base/assert/is-integerf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var INT32_MAX = require( '@stdlib/constants/int32/max' ); +var bitwisef = require( './bitwise_binary_gcd.js' ); +var largeIntegersf = require( './binary_gcd.js' ); + + +// MAIN // + +/** +* Computes the greatest common divisor (gcd). +* +* @param {integer} a - first number +* @param {integer} b - second number +* @returns {integer} greatest common divisor +* +* @example +* var v = gcdf( 48, 18 ); +* // returns 6 +* +* @example +* var v = gcdf( 3.14, 18 ); +* // returns NaN +* +* @example +* var v = gcdf( NaN, 18 ); +* // returns NaN +*/ +function gcdf( a, b ) { + if ( isnanf( a ) || isnanf( b ) ) { + return NaN; + } + if ( + a === PINF || + b === PINF || + a === NINF || + b === NINF + ) { + return NaN; + } + if ( !( isIntegerf( a ) && isIntegerf( b ) ) ) { + return NaN; + } + if ( a < 0 ) { + a = -a; + } + if ( b < 0 ) { + b = -b; + } + if ( a <= INT32_MAX && b <= INT32_MAX ) { + return bitwisef( a, b ); + } + return largeIntegersf( a, b ); +} + + +// EXPORTS // + +module.exports = gcdf; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js new file mode 100644 index 000000000000..3fa928d19706 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the greatest common divisor (gcd). +* +* @private +* @param {number} a - first number +* @param {number} b - second number +* @returns {number} greatest common divisor +* +* @example +* var v = gcd( 0.0, 0.0 ); +* // returns 0.0 +* +* @example +* var v = gcd( 48.0, 18.0 ); +* // returns 6.0 +*/ +function gcdf( a, b ) { + return addon( a, b ); +} + + +// EXPORTS // + +module.exports = gcdf; From d7fa9cba6f838984fcbcd8eeb95db6e15e15d4ea Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:07:07 +0530 Subject: [PATCH 04/20] feat: added examples --- .../base/special/gcdf/examples/c/Makefile | 146 ++++++++++++++++++ .../base/special/gcdf/examples/c/example.c | 32 ++++ .../math/base/special/gcdf/examples/index.js | 30 ++++ 3 files changed, 208 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c new file mode 100644 index 000000000000..b23af273b76c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf.h" +#include + +int main( void ) { + const float a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const float b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_gcdf( a[ i ], b[ i ] ); + printf( "gcd(%f, %f) = %f\n", a[ i ], b[ i ], out ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js new file mode 100644 index 000000000000..a934e8cb7bba --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gcdf = require( './../lib' ); + +var a = discreteUniform( 100, 0, 50 ); +var b = discreteUniform( a.length, 0, 50 ); + +var i; +for ( i = 0; i < a.length; i++ ) { + console.log( 'gcd(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); +} From 0711fb5cb54c6666faf5b984c4a852d2f96fa80f Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:17:21 +0530 Subject: [PATCH 05/20] feat: added benchmark --- .../base/special/gcdf/benchmark/benchmark.js | 54 +++++++ .../gcdf/benchmark/benchmark.native.js | 63 ++++++++ .../special/gcdf/benchmark/c/native/Makefile | 146 ++++++++++++++++++ .../gcdf/benchmark/c/native/benchmark.c | 135 ++++++++++++++++ .../base/special/gcdf/benchmark/julia/REQUIRE | 2 + .../special/gcdf/benchmark/julia/benchmark.jl | 144 +++++++++++++++++ .../gcdf/benchmark/python/benchmark.py | 105 +++++++++++++ 7 files changed, 649 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE create mode 100755 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl create mode 100755 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js new file mode 100644 index 000000000000..a09d9ac52f1a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var gcdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + 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++ ) { + z = gcdf( 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/gcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..e9cad9d34aad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var gcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( gcdf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + 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++ ) { + z = gcdf( 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/gcdf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..3aee16400fac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf.h" +#include +#include +#include +#include +#include + +#define NAME "gcdf" +#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.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + float a; + float b; + float y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + a = round( 500.0*rand_float() ); + b = round( 500.0*rand_float() ); + y = stdlib_base_gcdf( a, b ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + 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 ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE new file mode 100644 index 000000000000..98645e192e41 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 1.5 +BenchmarkTools 0.5.0 diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl new file mode 100755 index 000000000000..5ba794a062fe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl @@ -0,0 +1,144 @@ +#!/usr/bin/env julia +# +# @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. + +import BenchmarkTools +using Printf + +# Benchmark variables: +name = "gcdf"; +repeats = 3; + +""" + print_version() + +Prints the TAP version. + +# Examples + +``` julia +julia> print_version() +``` +""" +function print_version() + @printf( "TAP version 13\n" ); +end + +""" + print_summary( total, passing ) + +Print the benchmark summary. + +# Arguments + +* `total`: total number of tests +* `passing`: number of passing tests + +# Examples + +``` julia +julia> print_summary( 3, 3 ) +``` +""" +function print_summary( total, 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" ); +end + +""" + print_results( iterations, elapsed ) + +Print benchmark results. + +# Arguments + +* `iterations`: number of iterations +* `elapsed`: elapsed time (in seconds) + +# Examples + +``` julia +julia> print_results( 1000000, 0.131009101868 ) +``` +""" +function print_results( iterations, elapsed ) + rate = iterations / elapsed + + @printf( " ---\n" ); + @printf( " iterations: %d\n", iterations ); + @printf( " elapsed: %0.9f\n", elapsed ); + @printf( " rate: %0.9f\n", rate ); + @printf( " ...\n" ); +end + +""" + benchmark() + +Run a benchmark. + +# Notes + +* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. +* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. +* The elapsed time is in seconds. + +# Examples + +``` julia +julia> out = benchmark(); +``` +""" +function benchmark() + t = BenchmarkTools.@benchmark gcdf( convert( Int32, round( rand()*50.0 ) ), convert( Int32, round( rand()*50.0 ) ) ) samples=1e6 + + # Compute the total "elapsed" time and convert from nanoseconds to seconds: + s = sum( t.times ) / 1.0e9; + + # Determine the number of "iterations": + iter = length( t.times ); + + # Return the results: + [ iter, s ]; +end + +""" + main() + +Run benchmarks. + +# Examples + +``` julia +julia> main(); +``` +""" +function main() + print_version(); + for i in 1:repeats + @printf( "# julia::%s\n", name ); + results = benchmark(); + print_results( results[ 1 ], results[ 2 ] ); + @printf( "ok %d benchmark finished\n", i ); + end + print_summary( repeats, repeats ); +end + +main(); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py new file mode 100755 index 000000000000..cf4676d52776 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# +# @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. + +"""Benchmark gcdf.""" + +from __future__ import print_function +import timeit +import sys + +NAME = "gcdf" +REPEATS = 3 +ITERATIONS = 1000000 + + +def print_version(): + """Print the TAP version.""" + print("TAP version 13") + + +def print_summary(total, passing): + """Print the benchmark summary. + + # Arguments + + * `total`: total number of tests + * `passing`: number of passing tests + + """ + print("#") + print("1.." + str(total)) # TAP plan + print("# total " + str(total)) + print("# pass " + str(passing)) + print("#") + print("# ok") + + +def print_results(elapsed): + """Print benchmark results. + + # Arguments + + * `elapsed`: elapsed time (in seconds) + + # Examples + + ``` python + python> print_results(0.131009101868) + ``` + """ + rate = ITERATIONS / elapsed + + print(" ---") + print(" iterations: " + str(ITERATIONS)) + print(" elapsed: " + str(elapsed)) + print(" rate: " + str(rate)) + print(" ...") + + +def benchmark(): + """Run the benchmark and print benchmark results.""" + setup = "from math import gcd; from math import floor; from random import random;" + stmt = "y = gcd(floor(random()*50.0), floor(random()*50.0))" + + t = timeit.Timer(stmt, setup=setup) + + print_version() + + for i in range(REPEATS): + print("# python::" + NAME) + elapsed = t.timeit(number=ITERATIONS) + print_results(elapsed) + print("ok " + str(i+1) + " benchmark finished") + + print_summary(REPEATS, REPEATS) + + +def main(): + """Run the benchmark.""" + benchmark() + + +if __name__ == "__main__": + if sys.version_info[0] >= 3 and sys.version_info[1] >= 5: + main() + else: + print_version() + print("# python::" + NAME) + print("# Error: cannot run benchmarks. Requires Python >=3.5.") + print("#") + print("1..0") From 4c2151f3a61b481fda814d49040e82f5fa5c83ad Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:19:59 +0530 Subject: [PATCH 06/20] feat: added docs --- .../math/base/special/gcdf/docs/repl.txt | 30 ++++++++++ .../base/special/gcdf/docs/types/index.d.ts | 50 +++++++++++++++++ .../math/base/special/gcdf/docs/types/test.ts | 56 +++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt new file mode 100644 index 000000000000..79e22abd3e7d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( a, b ) + Computes the greatest common divisor (gcd). + + If both `a` and `b` are `0`, the function returns `0`. + + Both `a` and `b` must have integer values; otherwise, the function returns + `NaN`. + + Parameters + ---------- + a: integer + First number. + + b: integer + Second number. + + Returns + ------- + out: integer + Greatest common divisor. + + Examples + -------- + > var v = {{alias}}( 48, 18 ) + 6 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts new file mode 100644 index 000000000000..669b8ee59a59 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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 greatest common divisor (gcd). +* +* ## Notes +* +* - If both `a` and `b` are `0`, the function returns `0`. +* - Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. +* +* @param a - first number +* @param b - second number +* @returns greatest common divisor +* +* @example +* var v = gcdf( 48, 18 ); +* // returns 6 +* +* @example +* var v = gcdf( 3.14, 18 ); +* // returns NaN +* +* @example +* var v = gcdf( NaN, 18 ); +* // returns NaN +*/ +declare function gcdf( a: number, b: number ): number; + + +// EXPORTS // + +export = gcdf; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/test.ts new file mode 100644 index 000000000000..a3b974eefcbb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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 gcdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + gcdf( 8, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + gcdf( true, 3 ); // $ExpectError + gcdf( false, 2 ); // $ExpectError + gcdf( '5', 1 ); // $ExpectError + gcdf( [], 1 ); // $ExpectError + gcdf( {}, 2 ); // $ExpectError + gcdf( ( x: number ): number => x, 2 ); // $ExpectError + + gcdf( 9, true ); // $ExpectError + gcdf( 9, false ); // $ExpectError + gcdf( 5, '5' ); // $ExpectError + gcdf( 8, [] ); // $ExpectError + gcdf( 9, {} ); // $ExpectError + gcdf( 8, ( x: number ): number => x ); // $ExpectError + + gcdf( [], true ); // $ExpectError + gcdf( {}, false ); // $ExpectError + gcdf( false, '5' ); // $ExpectError + gcdf( {}, [] ); // $ExpectError + gcdf( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + gcdf(); // $ExpectError + gcdf( 3 ); // $ExpectError +} From 4f2075ed132f2dd2155fdd51cb045316f6eebc66 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:25:12 +0530 Subject: [PATCH 07/20] fix: updated dependencies --- .../math/base/special/gcdf/manifest.json | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json index 87c65f0cf256..4f788a9be254 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json @@ -37,11 +37,11 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/binary", - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/fmod", - "@stdlib/math/base/assert/is-integer", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf" + "@stdlib/math/base/assert/is-integerf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] }, { @@ -55,11 +55,11 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/fmod", - "@stdlib/math/base/assert/is-integer", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf" + "@stdlib/math/base/assert/is-integerf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] }, { @@ -73,11 +73,11 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/special/fmod", - "@stdlib/math/base/assert/is-integer", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf" + "@stdlib/math/base/assert/is-integerf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] } ] From 0631b43ef375bf2c6971e882989fc45a17b5b4fb Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:32:35 +0530 Subject: [PATCH 08/20] fix: typo in tests --- .../@stdlib/math/base/special/gcdf/test/test.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js index 93336e5696a4..d3f69f23bead 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.native.js @@ -40,7 +40,7 @@ var opts = { tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof gcd, 'function', 'main export is a function' ); + t.strictEqual( typeof gcdf, 'function', 'main export is a function' ); t.end(); }); From 9f8e83f8f46209edf18e7b0d08045d8b72fe85e9 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:43:13 +0530 Subject: [PATCH 09/20] fix: linting js files --- lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js index 3fa928d19706..3feba750317c 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js @@ -34,11 +34,11 @@ var addon = require( './../src/addon.node' ); * @returns {number} greatest common divisor * * @example -* var v = gcd( 0.0, 0.0 ); +* var v = gcdf( 0.0, 0.0 ); * // returns 0.0 * * @example -* var v = gcd( 48.0, 18.0 ); +* var v = gcdf( 48.0, 18.0 ); * // returns 6.0 */ function gcdf( a, b ) { From bc2ae67c38f4a4e64cbae20dc46dfbbd9e33da99 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:00:45 +0530 Subject: [PATCH 10/20] fix: linting C files --- lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c index 33b2779866bc..2f5253df682f 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/src/addon.c @@ -19,4 +19,5 @@ #include "stdlib/math/base/special/gcdf.h" #include "stdlib/math/base/napi/binary.h" +// cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_gcdf ) From 805f0d528be5eb12eebc03de384c3e6d18ea924e Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:20:51 +0530 Subject: [PATCH 11/20] fix: typo in README Signed-off-by: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> --- lib/node_modules/@stdlib/math/base/special/gcdf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md index cf09aa6051ee..939026a4dceb 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# gcd +# gcdf > Compute the [greatest common divisor][gcd] (gcd). From efb354f65ac35509919e609afebd9b7d4eb51638 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:26:05 +0530 Subject: [PATCH 12/20] fix: updated benchmarks --- .../math/base/special/gcdf/benchmark/julia/benchmark.jl | 4 ++-- .../math/base/special/gcdf/benchmark/python/benchmark.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl index 5ba794a062fe..aca5f3c68a53 100755 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl @@ -20,7 +20,7 @@ import BenchmarkTools using Printf # Benchmark variables: -name = "gcdf"; +name = "gcd"; repeats = 3; """ @@ -107,7 +107,7 @@ julia> out = benchmark(); ``` """ function benchmark() - t = BenchmarkTools.@benchmark gcdf( convert( Int32, round( rand()*50.0 ) ), convert( Int32, round( rand()*50.0 ) ) ) samples=1e6 + t = BenchmarkTools.@benchmark gcd( convert( Int32, round( rand()*50.0 ) ), convert( Int32, round( rand()*50.0 ) ) ) samples=1e6 # Compute the total "elapsed" time and convert from nanoseconds to seconds: s = sum( t.times ) / 1.0e9; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py index cf4676d52776..4d79a5e7f4b8 100755 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py @@ -22,7 +22,7 @@ import timeit import sys -NAME = "gcdf" +NAME = "gcd" REPEATS = 3 ITERATIONS = 1000000 From 8ee80fdacabc03c694d34678877bd54c0ef33a8f Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 21:59:56 +0530 Subject: [PATCH 13/20] fix: removed unwanted files --- .../base/special/gcdf/benchmark/julia/REQUIRE | 2 - .../special/gcdf/benchmark/julia/benchmark.jl | 144 ------------------ .../gcdf/benchmark/python/benchmark.py | 105 ------------- 3 files changed, 251 deletions(-) delete mode 100644 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE delete mode 100755 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl delete mode 100755 lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e192e41..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl deleted file mode 100755 index aca5f3c68a53..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @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. - -import BenchmarkTools -using Printf - -# Benchmark variables: -name = "gcd"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, 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" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark gcd( convert( Int32, round( rand()*50.0 ) ), convert( Int32, round( rand()*50.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py deleted file mode 100755 index 4d79a5e7f4b8..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/python/benchmark.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# -# @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. - -"""Benchmark gcdf.""" - -from __future__ import print_function -import timeit -import sys - -NAME = "gcd" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "from math import gcd; from math import floor; from random import random;" - stmt = "y = gcd(floor(random()*50.0), floor(random()*50.0))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - if sys.version_info[0] >= 3 and sys.version_info[1] >= 5: - main() - else: - print_version() - print("# python::" + NAME) - print("# Error: cannot run benchmarks. Requires Python >=3.5.") - print("#") - print("1..0") From aa18345a81e5c35602e9b8abaa1e830a6d0aa4a3 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:02:27 +0530 Subject: [PATCH 14/20] chore: updated year from 2018 to 2024 in license --- .../@stdlib/math/base/special/gcdf/benchmark/benchmark.js | 2 +- .../@stdlib/math/base/special/gcdf/docs/types/index.d.ts | 2 +- .../@stdlib/math/base/special/gcdf/docs/types/test.ts | 2 +- .../@stdlib/math/base/special/gcdf/examples/index.js | 2 +- .../@stdlib/math/base/special/gcdf/lib/binary_gcd.js | 2 +- .../@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js | 2 +- lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js index a09d9ac52f1a..cfb494331ebc 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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. diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts index 669b8ee59a59..d1ba5dd09e08 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/test.ts index a3b974eefcbb..1ad842a5d4c4 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js index a934e8cb7bba..43f02a241324 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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. diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js index 1fe947d71708..c3f566d9133f 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.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/gcdf/lib/bitwise_binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js index 545facd8568c..97f4e4594490 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.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/gcdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js index ae86154475f0..05ae074cdd34 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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/gcdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js index f7e277a83736..fcdb6c0d4977 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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. From 7656daebab3297e57116551595aa23b1d6b90ed4 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:20:13 +0530 Subject: [PATCH 15/20] chore: changes from code review --- .../@stdlib/math/base/special/gcdf/README.md | 22 ++++++------------- .../base/special/gcdf/benchmark/benchmark.js | 2 +- .../gcdf/benchmark/benchmark.native.js | 2 +- .../gcdf/benchmark/c/native/benchmark.c | 6 ++--- .../base/special/gcdf/examples/c/example.c | 6 ++--- .../math/base/special/gcdf/examples/index.js | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md index 939026a4dceb..730f2de62dcc 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md @@ -2,7 +2,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. @@ -20,7 +20,7 @@ limitations under the License. # gcdf -> Compute the [greatest common divisor][gcd] (gcd). +> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating point numbers. @@ -142,8 +142,8 @@ for ( i = 0; i < a.length; i++ ) { Computes the greatest common divisor (gcd). ```c -float v = stdlib_base_gcdf( 48.0, 18.0 ); -// returns 6.0 +float v = stdlib_base_gcdf( 48.0f, 18.0f ); +// returns 6.0f ``` The function accepts the following arguments: @@ -178,14 +178,14 @@ float stdlib_base_gcdf( const float a, const float b ); #include int main( void ) { - const float a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; - const float b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; + 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_gcdf( a[ i ], b[ i ] ); - printf( "gcd(%f, %f) = %f\n", a[ i ], b[ i ], out ); + printf( "gcdf(%f, %f) = %f\n", a[ i ], b[ i ], out ); } } ``` @@ -214,12 +214,6 @@ int main( void ) { @@ -234,8 +228,6 @@ int main( void ) { -[@stdlib/math/base/special/lcm]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/lcm - diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js index cfb494331ebc..159ea6573b20 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var gcdf = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js index e9cad9d34aad..db44774451c7 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/benchmark.native.js @@ -23,7 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c index 3aee16400fac..db4620ff0947 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c @@ -81,7 +81,7 @@ static double tic( void ) { */ static float rand_float( void ) { int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0 ); + return (float)r / ( (float)RAND_MAX + 1.0f ); } /** @@ -99,8 +99,8 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - a = round( 500.0*rand_float() ); - b = round( 500.0*rand_float() ); + a = round( 500.0f * rand_float() ); + b = round( 500.0f * rand_float() ); y = stdlib_base_gcdf( a, b ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c index b23af273b76c..b93ce69b59d5 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/c/example.c @@ -20,13 +20,13 @@ #include int main( void ) { - const float a[] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; - const float b[] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; + 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_gcdf( a[ i ], b[ i ] ); - printf( "gcd(%f, %f) = %f\n", a[ i ], b[ i ], out ); + printf( "gcdf(%f, %f) = %f\n", a[ i ], b[ i ], out ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js index 43f02a241324..f7db1685d12c 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/examples/index.js @@ -26,5 +26,5 @@ var b = discreteUniform( a.length, 0, 50 ); var i; for ( i = 0; i < a.length; i++ ) { - console.log( 'gcd(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); + console.log( 'gcdf(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); } From e7c7069a07c55e04896f0535b17a5e9719f42b2e Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:29:10 +0530 Subject: [PATCH 16/20] chore: update package descriptions --- lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt | 3 ++- .../@stdlib/math/base/special/gcdf/docs/types/index.d.ts | 2 +- .../base/special/gcdf/include/stdlib/math/base/special/gcdf.h | 2 +- .../@stdlib/math/base/special/gcdf/lib/binary_gcd.js | 2 +- .../@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js | 2 +- lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js | 2 +- lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt index 79e22abd3e7d..5efee3cba07f 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( a, b ) - Computes the greatest common divisor (gcd). + Computes the greatest common divisor (gcd) of two single-precision + floating point numbers. If both `a` and `b` are `0`, the function returns `0`. diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts index d1ba5dd09e08..2de00fcd4144 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Computes the greatest common divisor (gcd). +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers. * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h b/lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h index b4de6e898564..38eff6fc1da4 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -* Computes the greatest common divisor (gcd). +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers. */ float stdlib_base_gcdf( const float a, const float b ); diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js index c3f566d9133f..8ea085d31cb2 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Computes the greatest common divisor (gcd) using the binary GCD algorithm. +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers using the binary GCD algorithm. * * ## References * diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js index 97f4e4594490..94084faef2c9 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Computes the greatest common divisor (gcd) using the binary GCD algorithm and bitwise operations. +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers using the binary GCD algorithm and bitwise operations. * * ## References * diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js index 05ae074cdd34..49b29efae18a 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the greatest common divisor (gcd). +* Compute the greatest common divisor (gcd) of two single-precision floating point numbers. * * @module @stdlib/math/base/special/gcdf * diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js index fcdb6c0d4977..a764d094fb64 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js @@ -32,7 +32,7 @@ var largeIntegersf = require( './binary_gcd.js' ); // MAIN // /** -* Computes the greatest common divisor (gcd). +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers. * * @param {integer} a - first number * @param {integer} b - second number diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js index 3feba750317c..67ab26afffd5 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Computes the greatest common divisor (gcd). +* Computes the greatest common divisor (gcd) of two single-precision floating point numbers. * * @private * @param {number} a - first number From 604ada830741df3d26567a1831a9252d4efc28c5 Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:43:54 +0530 Subject: [PATCH 17/20] chore: typo in readme --- lib/node_modules/@stdlib/math/base/special/gcdf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md index 730f2de62dcc..28dfc89d568b 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md @@ -103,7 +103,7 @@ var b = discreteUniform( a.length, 0, 50 ); var i; for ( i = 0; i < a.length; i++ ) { - console.log( 'gcd(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); + console.log( 'gcdf(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); } ``` From 551140653d88c47b68318dc81ed3ceb543c0630a Mon Sep 17 00:00:00 2001 From: aayush0325 <96649223+aayush0325@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:14:31 +0530 Subject: [PATCH 18/20] feat: updated using fmodf --- .../@stdlib/math/base/special/gcdf/manifest.json | 6 +++--- .../@stdlib/math/base/special/gcdf/src/main.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json index 4f788a9be254..0909290a3c0d 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json @@ -38,7 +38,7 @@ "dependencies": [ "@stdlib/math/base/napi/binary", "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/special/fmod", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/ninf" @@ -56,7 +56,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/special/fmod", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/ninf" @@ -74,7 +74,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/special/fmod", + "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", "@stdlib/constants/float32/ninf" diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c index 710cc09dc98f..898b844e68ae 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c @@ -17,11 +17,11 @@ */ #include "stdlib/math/base/special/gcdf.h" -#include "stdlib/math/base/special/fmod.h" +#include "stdlib/math/base/special/fmodf.h" #include "stdlib/math/base/assert/is_nanf.h" #include "stdlib/math/base/assert/is_integerf.h" #include "stdlib/constants/float32/pinf.h" -#include "stdlib//constants/float32/ninf.h" +#include "stdlib/constants/float32/ninf.h" #include // 2^32 - 1 @@ -56,19 +56,19 @@ static float largeIntegersf( const float a, const float b ) { k = 1.0; // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... - while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 && stdlib_base_fmod( bc, 2.0 ) == 0.0 ) { + while ( stdlib_base_fmodf( ac, 2.0 ) == 0.0 && stdlib_base_fmodf( bc, 2.0 ) == 0.0 ) { ac /= 2.0; // right shift bc /= 2.0; // right shift k *= 2.0; // left shift } // Reduce `a` to an odd number... - while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 ) { + while ( stdlib_base_fmodf( ac, 2.0 ) == 0.0 ) { ac /= 2.0; // right shift } // Henceforth, `a` is always odd... while ( bc ) { // Remove all factors of 2 in `b`, as they are not common... - while ( stdlib_base_fmod( bc, 2.0 ) == 0.0 ) { + while ( stdlib_base_fmodf( bc, 2.0 ) == 0.0 ) { bc /= 2.0; // right shift } // `a` and `b` are both odd. Swap values such that `b` is the larger of the two values, and then set `b` to the difference (which is even)... From 3ef61a73625c5514181b57587ca7a342f0468ca3 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Nov 2024 09:58:43 -0500 Subject: [PATCH 19/20] chore: update copyright year Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js b/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js index b2be3c06f91d..16ff6914e5ca 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/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. From 9aaf1e33b0cae1b9f5308c385061808c843a14dd Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Nov 2024 10:06:57 -0500 Subject: [PATCH 20/20] refactor: load stdlib constant instead of redefining it Signed-off-by: Philipp Burckhardt --- .../@stdlib/math/base/special/gcdf/manifest.json | 9 ++++++--- .../@stdlib/math/base/special/gcdf/src/main.c | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json index 0909290a3c0d..de47933d8fd8 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/manifest.json @@ -41,7 +41,8 @@ "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/ninf" + "@stdlib/constants/float32/ninf", + "@stdlib/constants/int32/max" ] }, { @@ -59,7 +60,8 @@ "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/ninf" + "@stdlib/constants/float32/ninf", + "@stdlib/constants/int32/max" ] }, { @@ -77,7 +79,8 @@ "@stdlib/math/base/special/fmodf", "@stdlib/math/base/assert/is-integerf", "@stdlib/constants/float32/pinf", - "@stdlib/constants/float32/ninf" + "@stdlib/constants/float32/ninf", + "@stdlib/constants/int32/max" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c index 898b844e68ae..41667d05a8a0 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/src/main.c @@ -22,11 +22,9 @@ #include "stdlib/math/base/assert/is_integerf.h" #include "stdlib/constants/float32/pinf.h" #include "stdlib/constants/float32/ninf.h" +#include "stdlib/constants/int32/max.h" #include -// 2^32 - 1 -static const int32_t STDLIB_CONSTANT_INT32_MAX = 2147483647; - /** * Computes the greatest common divisor (gcd) using the binary GCD algorithm. *