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.
20
20
21
21
# gcdf
22
22
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.
24
24
25
25
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26
26
@@ -44,7 +44,7 @@ var gcdf = require( '@stdlib/math/base/special/gcdf' );
44
44
45
45
#### gcdf( a, b )
46
46
47
- Computes the [ greatest common divisor] [ gcd ] (gcd).
47
+ Computes the [ greatest common divisor] [ gcd ] (gcd) of two single-precision floating-point numbers .
48
48
49
49
``` javascript
50
50
var v = gcdf ( 48 , 18 );
@@ -139,7 +139,7 @@ for ( i = 0; i < a.length; i++ ) {
139
139
140
140
#### stdlib_base_gcdf( a, b )
141
141
142
- Computes the greatest common divisor (gcd).
142
+ Computes the greatest common divisor (gcd) of two single-precision floating-point numbers .
143
143
144
144
``` c
145
145
float 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 ) {
91
91
*/
92
92
static double benchmark ( void ) {
93
93
double elapsed ;
94
- float a ;
95
- float b ;
96
- float y ;
94
+ float a [ 100 ];
95
+ float b [ 100 ];
97
96
double t ;
97
+ float y ;
98
98
int i ;
99
99
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
+
100
105
t = tic ();
101
106
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 ] );
105
108
if ( y != y ) {
106
109
printf ( "should not return NaN\n" );
107
110
break ;
Original file line number Diff line number Diff line change 1
1
2
2
{{alias}}( a, b )
3
3
Computes the greatest common divisor (gcd) of two single-precision
4
- floating point numbers.
4
+ floating- point numbers.
5
5
6
6
If both `a` and `b` are `0`, the function returns `0`.
7
7
Original file line number Diff line number Diff line change 19
19
// TypeScript Version: 4.1
20
20
21
21
/**
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.
23
23
*
24
24
* ## Notes
25
25
*
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ extern "C" {
27
27
#endif
28
28
29
29
/**
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.
31
31
*/
32
32
float stdlib_base_gcdf ( const float a , const float b );
33
33
Original file line number Diff line number Diff line change 19
19
'use strict' ;
20
20
21
21
/**
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.
23
23
*
24
24
* ## References
25
25
*
33
33
* @returns {integer } greatest common divisor
34
34
*
35
35
* @example
36
- * var v = gcdf( 16777216.0 , 65536.0 );
36
+ * var v = gcdf( 16777216, 65536 );
37
37
* // returns 65536
38
38
*/
39
39
function gcdf ( a , b ) {
@@ -47,22 +47,26 @@ function gcdf( a, b ) {
47
47
if ( b === 0 ) {
48
48
return a ;
49
49
}
50
+
50
51
// 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 ) {
52
53
a /= 2 ; // right shift
53
54
b /= 2 ; // right shift
54
55
k *= 2 ; // left shift
55
56
}
57
+
56
58
// Reduce `a` to an odd number...
57
- while ( a % 2 === 0 ) {
59
+ while ( a % 2 === 0 ) {
58
60
a /= 2 ; // right shift
59
61
}
62
+
60
63
// Henceforth, `a` is always odd...
61
64
while ( b ) {
62
65
// Remove all factors of 2 in `b`, as they are not common...
63
- while ( b % 2 === 0 ) {
66
+ while ( b % 2 === 0 ) {
64
67
b /= 2 ; // right shift
65
68
}
69
+
66
70
// `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)...
67
71
if ( a > b ) {
68
72
t = b ;
@@ -71,6 +75,7 @@ function gcdf( a, b ) {
71
75
}
72
76
b -= a ; // b=0 iff b=a
73
77
}
78
+
74
79
// Restore common factors of 2...
75
80
return k * a ;
76
81
}
Original file line number Diff line number Diff line change 19
19
'use strict' ;
20
20
21
21
/**
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.
23
23
*
24
24
* ## References
25
25
*
@@ -47,22 +47,26 @@ function gcdf( a, b ) {
47
47
if ( b === 0 ) {
48
48
return a ;
49
49
}
50
+
50
51
// 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 ) {
52
53
a >>>= 1 ; // right shift
53
54
b >>>= 1 ; // right shift
54
55
k += 1 ;
55
56
}
57
+
56
58
// Reduce `a` to an odd number...
57
- while ( ( a & 1 ) === 0 ) {
59
+ while ( ( a & 1 ) === 0 ) {
58
60
a >>>= 1 ; // right shift
59
61
}
62
+
60
63
// Henceforth, `a` is always odd...
61
64
while ( b ) {
62
65
// Remove all factors of 2 in `b`, as they are not common...
63
- while ( ( b & 1 ) === 0 ) {
66
+ while ( ( b & 1 ) === 0 ) {
64
67
b >>>= 1 ; // right shift
65
68
}
69
+
66
70
// `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)...
67
71
if ( a > b ) {
68
72
t = b ;
@@ -71,6 +75,7 @@ function gcdf( a, b ) {
71
75
}
72
76
b -= a ; // b=0 iff b=a
73
77
}
78
+
74
79
// Restore common factors of 2...
75
80
return a << k ;
76
81
}
Original file line number Diff line number Diff line change 19
19
'use strict' ;
20
20
21
21
/**
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.
23
23
*
24
24
* @module @stdlib /math/base/special/gcdf
25
25
*
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ var largeIntegersf = require( './binary_gcd.js' );
32
32
// MAIN //
33
33
34
34
/**
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.
36
36
*
37
37
* @param {integer } a - first number
38
38
* @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' );
26
26
// MAIN //
27
27
28
28
/**
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.
30
30
*
31
31
* @private
32
32
* @param {number } a - first number
You can’t perform that action at this time.
0 commit comments