File tree Expand file tree Collapse file tree 12 files changed +84
-63
lines changed
lib/node_modules/@stdlib/math/base/special/gcdf
include/stdlib/math/base/special Expand file tree Collapse file tree 12 files changed +84
-63
lines changed Original file line number Diff line number Diff 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
5050var 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
145145float v = stdlib_base_gcdf( 48 .0f , 18 .0f );
Original file line number Diff line number Diff line change @@ -91,17 +91,20 @@ static float rand_float( void ) {
9191*/
9292static 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 ;
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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*
Original file line number Diff line number Diff 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*/
3232float stdlib_base_gcdf ( const float a , const float b );
3333
Original file line number Diff line number Diff line change 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*
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*/
3939function 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}
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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*
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments