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 28dfc89d568b..0118947319fc 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/README.md @@ -20,7 +20,7 @@ limitations under the License. # gcdf -> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating point numbers. +> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating-point numbers. @@ -44,7 +44,7 @@ var gcdf = require( '@stdlib/math/base/special/gcdf' ); #### gcdf( a, b ) -Computes the [greatest common divisor][gcd] (gcd). +Computes the [greatest common divisor][gcd] (gcd) of two single-precision floating-point numbers. ```javascript var v = gcdf( 48, 18 ); @@ -139,7 +139,7 @@ for ( i = 0; i < a.length; i++ ) { #### stdlib_base_gcdf( a, b ) -Computes the greatest common divisor (gcd). +Computes the greatest common divisor (gcd) of two single-precision floating-point numbers. ```c float v = stdlib_base_gcdf( 48.0f, 18.0f ); 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 db4620ff0947..3c8a1873acd8 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 @@ -91,17 +91,20 @@ static float rand_float( void ) { */ static double benchmark( void ) { double elapsed; - float a; - float b; - float y; + float a[ 100 ]; + float b[ 100 ]; double t; + float y; int i; + for ( i = 0; i < 100; i++ ) { + a[ i ] = roundf( 500.0f * rand_float() ); + b[ i ] = roundf( 500.0f * rand_float() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - a = round( 500.0f * rand_float() ); - b = round( 500.0f * rand_float() ); - y = stdlib_base_gcdf( a, b ); + y = stdlib_base_gcdf( a[ i % 100 ], b[ i % 100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 5efee3cba07f..6b48e4156ff1 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,7 +1,7 @@ {{alias}}( a, b ) Computes the greatest common divisor (gcd) of two single-precision - floating point numbers. + 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 2de00fcd4144..14e8d11f8642 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) of two single-precision floating point numbers. +* 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 38eff6fc1da4..d0138ebd0511 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) of two single-precision floating point numbers. +* 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 8ea085d31cb2..8010937ca9df 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) of two single-precision floating point numbers using the binary GCD algorithm. +* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers using the binary GCD algorithm. * * ## References * @@ -33,7 +33,7 @@ * @returns {integer} greatest common divisor * * @example -* var v = gcdf( 16777216.0, 65536.0 ); +* var v = gcdf( 16777216, 65536 ); * // returns 65536 */ function gcdf( a, b ) { @@ -47,22 +47,26 @@ function gcdf( a, 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 ) { + 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 ) { + 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 ) { + 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; @@ -71,6 +75,7 @@ function gcdf( a, b ) { } b -= a; // b=0 iff b=a } + // Restore common factors of 2... return k * a; } 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 94084faef2c9..35c50d409b47 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) of two single-precision floating point numbers 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 * @@ -47,22 +47,26 @@ function gcdf( a, 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 ) { + 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 ) { + 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 ) { + 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; @@ -71,6 +75,7 @@ function gcdf( a, b ) { } b -= a; // b=0 iff b=a } + // Restore common factors of 2... return a << k; } 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 49b29efae18a..b2d60657b996 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) of two single-precision floating point numbers. +* 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 a764d094fb64..47d75079e3df 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) of two single-precision floating point numbers. +* 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 67ab26afffd5..dc56388ddb6e 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) of two single-precision floating point numbers. +* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers. * * @private * @param {number} a - first number diff --git a/lib/node_modules/@stdlib/math/base/special/gcdf/package.json b/lib/node_modules/@stdlib/math/base/special/gcdf/package.json index ff2e1d434dd1..439eb761a61f 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcdf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/gcdf/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/gcdf", "version": "0.0.0", - "description": "Compute the greatest common divisor (gcd).", + "description": "Compute the greatest common divisor (gcd) of two single-precision floating-point numbers.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -76,7 +76,7 @@ "scaffold": { "$schema": "math/base@v1.0", "base_alias": "gcd", - "alias": "gcd", + "alias": "gcdf", "pkg_desc": "compute the greatest common divisor (gcd)", "desc": "computes the greatest common divisor (gcd)", "short_desc": "greatest common divisor (gcd)", @@ -87,8 +87,8 @@ "type": { "javascript": "integer", "jsdoc": "integer", - "c": "double", - "dtype": "float64" + "c": "float", + "dtype": "float32" }, "domain": [ { @@ -132,8 +132,8 @@ "type": { "javascript": "integer", "jsdoc": "integer", - "c": "double", - "dtype": "float64" + "c": "float", + "dtype": "float32" }, "domain": [ { @@ -177,8 +177,8 @@ "type": { "javascript": "number", "jsdoc": "number", - "c": "double", - "dtype": "float64" + "c": "float", + "dtype": "float32" } }, "keywords": [ 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 41667d05a8a0..efa96f204138 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 @@ -26,15 +26,15 @@ #include /** -* 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. * -* @param a first number -* @param b second number -* @return greatest common divisor +* @param a first number +* @param b second number +* @return greatest common divisor * * @example -* float out = largeIntegersf(16777216.0, 65536.0); -* // returns 65536.0 +* float out = largeIntegersf( 16777216.0f, 65536.0f ); +* // returns 65536.0f */ static float largeIntegersf( const float a, const float b ) { float ac; @@ -43,32 +43,35 @@ static float largeIntegersf( const float a, const float b ) { float t; // Simple cases: - if ( a == 0.0 ) { + if ( a == 0.0f ) { return b; } - if ( b == 0.0 ) { + if ( b == 0.0f ) { return a; } ac = a; bc = b; - k = 1.0; + k = 1.0f; // 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_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 + while ( stdlib_base_fmodf( ac, 2.0f ) == 0.0f && stdlib_base_fmodf( bc, 2.0f ) == 0.0f ) { + ac /= 2.0f; // right shift + bc /= 2.0f; // right shift + k *= 2.0f; // left shift } + // Reduce `a` to an odd number... - while ( stdlib_base_fmodf( ac, 2.0 ) == 0.0 ) { - ac /= 2.0; // right shift + while ( stdlib_base_fmodf( ac, 2.0f ) == 0.0f ) { + ac /= 2.0f; // right shift } + // Henceforth, `a` is always odd... while ( bc ) { // Remove all factors of 2 in `b`, as they are not common... - while ( stdlib_base_fmodf( bc, 2.0 ) == 0.0 ) { - bc /= 2.0; // right shift + while ( stdlib_base_fmodf( bc, 2.0f ) == 0.0f ) { + bc /= 2.0f; // 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; @@ -77,20 +80,21 @@ static float largeIntegersf( const float a, const float b ) { } 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. +* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers 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 +* float out = bitwisef( 48.0f, 18.0f ); +* // returns 6.0f */ static float bitwisef( const float a, const float b ) { int32_t ac; @@ -99,10 +103,10 @@ static float bitwisef( const float a, const float b ) { int32_t t; // Simple cases: - if ( a == 0.0 ) { + if ( a == 0.0f ) { return b; } - if ( b == 0.0 ) { + if ( b == 0.0f ) { return a; } ac = (int32_t)a; @@ -110,21 +114,24 @@ static float bitwisef( const float a, const float 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 ) { + 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 ) { + 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 ) { + 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; @@ -133,27 +140,28 @@ static float bitwisef( const float a, const float b ) { } bc -= ac; // b=0 iff b=a } + // Restore common factors of 2... return ac << k; } /** -* Computes the greatest common divisor (gcd). +* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers. * * @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 out = stdlib_base_gcdf( 48.0f, 18.0f ); +* // returns 6.0f */ 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 + return 0.0f / 0.0f; // NaN } if ( a == STDLIB_CONSTANT_FLOAT32_PINF || @@ -161,10 +169,10 @@ float stdlib_base_gcdf( const float a, const float b ) { a == STDLIB_CONSTANT_FLOAT32_NINF || b == STDLIB_CONSTANT_FLOAT32_NINF ) { - return 0.0/0.0; // NaN + return 0.0f / 0.0f; // NaN } if ( !( stdlib_base_is_integerf( a ) && stdlib_base_is_integerf( b ) ) ) { - return 0.0/0.0; // NaN + return 0.0f / 0.0f; // NaN } ac = a; bc = b;