Skip to content

Commit 1288e7e

Browse files
authored
refactor: use stdlib_base_fmod instead of built-in in math/base/special/gcd
PR-URL: #2815 --------- Signed-off-by: Gunj Joshi <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 0ab9fc7 commit 1288e7e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

+3
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

+4-4
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)