Skip to content

Commit 163a3e7

Browse files
gunjjoshikgryte
andauthored
refactor: update benchmark, add f suffixes, missing spaces in math/base/special/gcdf
PR-URL: #3121 Ref: f8bcfd8 Private-ref: stdlib-js/todo#2301 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 3c5c933 commit 163a3e7

File tree

12 files changed

+84
-63
lines changed

12 files changed

+84
-63
lines changed

lib/node_modules/@stdlib/math/base/special/gcdf/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# gcdf
2222

23-
> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating point numbers.
23+
> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating-point numbers.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -44,7 +44,7 @@ var gcdf = require( '@stdlib/math/base/special/gcdf' );
4444

4545
#### gcdf( a, b )
4646

47-
Computes the [greatest common divisor][gcd] (gcd).
47+
Computes the [greatest common divisor][gcd] (gcd) of two single-precision floating-point numbers.
4848

4949
```javascript
5050
var v = gcdf( 48, 18 );
@@ -139,7 +139,7 @@ for ( i = 0; i < a.length; i++ ) {
139139

140140
#### stdlib_base_gcdf( a, b )
141141

142-
Computes the greatest common divisor (gcd).
142+
Computes the greatest common divisor (gcd) of two single-precision floating-point numbers.
143143

144144
```c
145145
float v = stdlib_base_gcdf( 48.0f, 18.0f );

lib/node_modules/@stdlib/math/base/special/gcdf/benchmark/c/native/benchmark.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
float a;
95-
float b;
96-
float y;
94+
float a[ 100 ];
95+
float b[ 100 ];
9796
double t;
97+
float y;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
a[ i ] = roundf( 500.0f * rand_float() );
102+
b[ i ] = roundf( 500.0f * rand_float() );
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
a = round( 500.0f * rand_float() );
103-
b = round( 500.0f * rand_float() );
104-
y = stdlib_base_gcdf( a, b );
107+
y = stdlib_base_gcdf( a[ i % 100 ], b[ i % 100 ] );
105108
if ( y != y ) {
106109
printf( "should not return NaN\n" );
107110
break;

lib/node_modules/@stdlib/math/base/special/gcdf/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( a, b )
33
Computes the greatest common divisor (gcd) of two single-precision
4-
floating point numbers.
4+
floating-point numbers.
55

66
If both `a` and `b` are `0`, the function returns `0`.
77

lib/node_modules/@stdlib/math/base/special/gcdf/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers.
22+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers.
2323
*
2424
* ## Notes
2525
*

lib/node_modules/@stdlib/math/base/special/gcdf/include/stdlib/math/base/special/gcdf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers.
30+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers.
3131
*/
3232
float stdlib_base_gcdf( const float a, const float b );
3333

lib/node_modules/@stdlib/math/base/special/gcdf/lib/binary_gcd.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers using the binary GCD algorithm.
22+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers using the binary GCD algorithm.
2323
*
2424
* ## References
2525
*
@@ -33,7 +33,7 @@
3333
* @returns {integer} greatest common divisor
3434
*
3535
* @example
36-
* var v = gcdf( 16777216.0, 65536.0 );
36+
* var v = gcdf( 16777216, 65536 );
3737
* // returns 65536
3838
*/
3939
function gcdf( a, b ) {
@@ -47,22 +47,26 @@ function gcdf( a, b ) {
4747
if ( b === 0 ) {
4848
return a;
4949
}
50+
5051
// Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`...
51-
while ( a%2 === 0 && b%2 === 0 ) {
52+
while ( a % 2 === 0 && b % 2 === 0 ) {
5253
a /= 2; // right shift
5354
b /= 2; // right shift
5455
k *= 2; // left shift
5556
}
57+
5658
// Reduce `a` to an odd number...
57-
while ( a%2 === 0 ) {
59+
while ( a % 2 === 0 ) {
5860
a /= 2; // right shift
5961
}
62+
6063
// Henceforth, `a` is always odd...
6164
while ( b ) {
6265
// Remove all factors of 2 in `b`, as they are not common...
63-
while ( b%2 === 0 ) {
66+
while ( b % 2 === 0 ) {
6467
b /= 2; // right shift
6568
}
69+
6670
// `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)...
6771
if ( a > b ) {
6872
t = b;
@@ -71,6 +75,7 @@ function gcdf( a, b ) {
7175
}
7276
b -= a; // b=0 iff b=a
7377
}
78+
7479
// Restore common factors of 2...
7580
return k * a;
7681
}

lib/node_modules/@stdlib/math/base/special/gcdf/lib/bitwise_binary_gcd.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers using the binary GCD algorithm and bitwise operations.
22+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers using the binary GCD algorithm and bitwise operations.
2323
*
2424
* ## References
2525
*
@@ -47,22 +47,26 @@ function gcdf( a, b ) {
4747
if ( b === 0 ) {
4848
return a;
4949
}
50+
5051
// Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`...
51-
while ( (a & 1) === 0 && (b & 1) === 0 ) {
52+
while ( ( a & 1 ) === 0 && ( b & 1 ) === 0 ) {
5253
a >>>= 1; // right shift
5354
b >>>= 1; // right shift
5455
k += 1;
5556
}
57+
5658
// Reduce `a` to an odd number...
57-
while ( (a & 1) === 0 ) {
59+
while ( ( a & 1 ) === 0 ) {
5860
a >>>= 1; // right shift
5961
}
62+
6063
// Henceforth, `a` is always odd...
6164
while ( b ) {
6265
// Remove all factors of 2 in `b`, as they are not common...
63-
while ( (b & 1) === 0 ) {
66+
while ( ( b & 1 ) === 0 ) {
6467
b >>>= 1; // right shift
6568
}
69+
6670
// `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)...
6771
if ( a > b ) {
6872
t = b;
@@ -71,6 +75,7 @@ function gcdf( a, b ) {
7175
}
7276
b -= a; // b=0 iff b=a
7377
}
78+
7479
// Restore common factors of 2...
7580
return a << k;
7681
}

lib/node_modules/@stdlib/math/base/special/gcdf/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Compute the greatest common divisor (gcd) of two single-precision floating point numbers.
22+
* Compute the greatest common divisor (gcd) of two single-precision floating-point numbers.
2323
*
2424
* @module @stdlib/math/base/special/gcdf
2525
*

lib/node_modules/@stdlib/math/base/special/gcdf/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var largeIntegersf = require( './binary_gcd.js' );
3232
// MAIN //
3333

3434
/**
35-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers.
35+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers.
3636
*
3737
* @param {integer} a - first number
3838
* @param {integer} b - second number

lib/node_modules/@stdlib/math/base/special/gcdf/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Computes the greatest common divisor (gcd) of two single-precision floating point numbers.
29+
* Computes the greatest common divisor (gcd) of two single-precision floating-point numbers.
3030
*
3131
* @private
3232
* @param {number} a - first number

0 commit comments

Comments
 (0)