Skip to content

Commit b088cac

Browse files
committed
refactor: use stdlib fmod instead of built-in
1 parent 64a15d3 commit b088cac

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var fmod = require( '@stdlib/math/base/special/fmod' );
24+
2125
/**
2226
* Computes the greatest common divisor (gcd) using the binary GCD algorithm.
2327
*
@@ -48,19 +52,19 @@ function gcd( a, b ) {
4852
return a;
4953
}
5054
// 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 ) {
55+
while ( fmod( a, 2 ) === 0 && fmod( b, 2 ) === 0 ) {
5256
a /= 2; // right shift
5357
b /= 2; // right shift
5458
k *= 2; // left shift
5559
}
5660
// Reduce `a` to an odd number...
57-
while ( a%2 === 0 ) {
61+
while ( fmod( a, 2 ) === 0 ) {
5862
a /= 2; // right shift
5963
}
6064
// Henceforth, `a` is always odd...
6165
while ( b ) {
6266
// Remove all factors of 2 in `b`, as they are not common...
63-
while ( b%2 === 0 ) {
67+
while ( fmod( b, 2 ) === 0 ) {
6468
b /= 2; // right shift
6569
}
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)...

lib/node_modules/@stdlib/math/base/special/gcd/manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"dependencies": [
3939
"@stdlib/math/base/napi/binary",
4040
"@stdlib/math/base/assert/is-nan",
41+
"@stdlib/math/base/special/fmod",
4142
"@stdlib/math/base/assert/is-integer",
4243
"@stdlib/constants/float64/pinf",
4344
"@stdlib/constants/float64/ninf"
@@ -55,6 +56,7 @@
5556
"libpath": [],
5657
"dependencies": [
5758
"@stdlib/math/base/assert/is-nan",
59+
"@stdlib/math/base/special/fmod",
5860
"@stdlib/math/base/assert/is-integer",
5961
"@stdlib/constants/float64/pinf",
6062
"@stdlib/constants/float64/ninf"
@@ -72,6 +74,7 @@
7274
"libpath": [],
7375
"dependencies": [
7476
"@stdlib/math/base/assert/is-nan",
77+
"@stdlib/math/base/special/fmod",
7578
"@stdlib/math/base/assert/is-integer",
7679
"@stdlib/constants/float64/pinf",
7780
"@stdlib/constants/float64/ninf"

lib/node_modules/@stdlib/math/base/special/gcd/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/gcd.h"
20+
#include "stdlib/math/base/special/fmod.h"
2021
#include "stdlib/math/base/assert/is_nan.h"
2122
#include "stdlib/math/base/assert/is_integer.h"
2223
#include "stdlib/constants/float64/pinf.h"
2324
#include "stdlib//constants/float64/ninf.h"
2425
#include <stdint.h>
25-
#include <math.h>
2626

2727
// 2^63 - 1
2828
static const int64_t STDLIB_CONSTANT_INT64_MAX = 9223372036854775807;
@@ -56,19 +56,19 @@ static double largeIntegers( const double a, const double b ) {
5656
k = 1.0;
5757

5858
// Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`...
59-
while ( fmod( ac, 2.0 ) == 0.0 && fmod( bc, 2.0 ) == 0.0 ) {
59+
while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 && stdlib_base_fmod( bc, 2.0 ) == 0.0 ) {
6060
ac /= 2.0; // right shift
6161
bc /= 2.0; // right shift
6262
k *= 2.0; // left shift
6363
}
6464
// Reduce `a` to an odd number...
65-
while ( fmod( ac, 2.0 ) == 0.0 ) {
65+
while ( stdlib_base_fmod( ac, 2.0 ) == 0.0 ) {
6666
ac /= 2.0; // right shift
6767
}
6868
// Henceforth, `a` is always odd...
6969
while ( bc ) {
7070
// Remove all factors of 2 in `b`, as they are not common...
71-
while ( fmod( bc, 2.0 ) == 0.0 ) {
71+
while ( stdlib_base_fmod( bc, 2.0 ) == 0.0 ) {
7272
bc /= 2.0; // right shift
7373
}
7474
// `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)...

0 commit comments

Comments
 (0)