Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/gcdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] = round( 500.0f * rand_float() );
b[ i ] = round( 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
15 changes: 10 additions & 5 deletions lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 ) {
Expand All @@ -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;
Expand All @@ -71,6 +75,7 @@ function gcdf( a, b ) {
}
b -= a; // b=0 iff b=a
}

// Restore common factors of 2...
return k * a;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -71,6 +75,7 @@ function gcdf( a, b ) {
}
b -= a; // b=0 iff b=a
}

// Restore common factors of 2...
return a << k;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions lib/node_modules/@stdlib/math/base/special/gcdf/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -76,9 +76,9 @@
"scaffold": {
"$schema": "math/[email protected]",
"base_alias": "gcd",
"alias": "gcd",
"pkg_desc": "compute the greatest common divisor (gcd)",
"desc": "computes the greatest common divisor (gcd)",
"alias": "gcdf",
"pkg_desc": "compute the greatest common divisor (gcd) of two single-precision floating-point numbers",
"desc": "computes the greatest common divisor (gcd) of two single-precision floating-point numbers",
"short_desc": "greatest common divisor (gcd)",
"parameters": [
{
Expand All @@ -87,8 +87,8 @@
"type": {
"javascript": "integer",
"jsdoc": "integer",
"c": "double",
"dtype": "float64"
"c": "float",
"dtype": "float32"
},
"domain": [
{
Expand Down Expand Up @@ -132,8 +132,8 @@
"type": {
"javascript": "integer",
"jsdoc": "integer",
"c": "double",
"dtype": "float64"
"c": "float",
"dtype": "float32"
},
"domain": [
{
Expand Down Expand Up @@ -177,8 +177,8 @@
"type": {
"javascript": "number",
"jsdoc": "number",
"c": "double",
"dtype": "float64"
"c": "float",
"dtype": "float32"
}
},
"keywords": [
Expand Down
Loading
Loading