diff --git a/lib/node_modules/@stdlib/math/base/special/gcd/README.md b/lib/node_modules/@stdlib/math/base/special/gcd/README.md index 1461e850c76..4d3b901cefc 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/gcd/README.md @@ -183,14 +183,14 @@ double stdlib_base_gcd( const double a, const double b ); #include int main( void ) { - const double a = { 24.0, 32.0, 48.0, 116.0, 33.0 }; - const double b = { 12.0, 6.0, 15.0, 52.0, 22.0 }; - + const double a[ 5 ] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const double b[ 5 ] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; + double out; int i; for ( i = 0; i < 5; i++ ) { - out = stdlib_base_gcd( a, b ); - printf( "gcd(%lf, %lf) = %lf\n", a, b, out ); + out = stdlib_base_gcd( a[ i ], b[ i ] ); + printf( "gcd(%lf, %lf) = %lf\n", a[ i ], b[ i ], out ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/gcd/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/gcd/benchmark/c/native/benchmark.c index 8832bf59796..859c8707e2b 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcd/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/gcd/benchmark/c/native/benchmark.c @@ -102,8 +102,8 @@ double benchmark() { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - a = ( 50.0*rand_double() ); - b = ( 50.0*rand_double() ); + a = round( 500.0*rand_double() ); + b = round( 500.0*rand_double() ); y = stdlib_base_gcd( a, b ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/gcd/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/gcd/examples/c/example.c index a728b28eb5c..6e60d22933b 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcd/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/gcd/examples/c/example.c @@ -21,15 +21,13 @@ #include int main( void ) { - double out; - double a; - double b; - int i; + const double a[ 5 ] = { 24.0, 32.0, 48.0, 116.0, 33.0 }; + const double b[ 5 ] = { 12.0, 6.0, 15.0, 52.0, 22.0 }; - for ( i = 0; i < 100; i++ ) { - a = ( ( (double)rand() / (double)RAND_MAX ) * 1000.0 ); - b = ( ( (double)rand() / (double)RAND_MAX ) * 500.0 ); - out = stdlib_base_gcd( a, b ); - printf( "gcd(%lf, %lf) = %lf\n", a, b, out ); - } + double out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_gcd( a[ i ], b[ i ] ); + printf( "gcd(%lf, %lf) = %lf\n", a[ i ], b[ i ], out ); + } } diff --git a/lib/node_modules/@stdlib/math/base/special/gcd/manifest.json b/lib/node_modules/@stdlib/math/base/special/gcd/manifest.json index 9c0bada7a68..5923f5a8913 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcd/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/gcd/manifest.json @@ -40,8 +40,7 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-integer", "@stdlib/constants/float64/pinf", - "@stdlib//constants/float64/ninf", - "@stdlib/constants/int32/max" + "@stdlib/constants/float64/ninf" ] }, { @@ -58,8 +57,7 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-integer", "@stdlib/constants/float64/pinf", - "@stdlib//constants/float64/ninf", - "@stdlib/constants/int32/max" + "@stdlib/constants/float64/ninf" ] }, { @@ -76,8 +74,7 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-integer", "@stdlib/constants/float64/pinf", - "@stdlib//constants/float64/ninf", - "@stdlib/constants/int32/max" + "@stdlib/constants/float64/ninf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/gcd/src/main.c b/lib/node_modules/@stdlib/math/base/special/gcd/src/main.c index a23a0d4577b..2118e5d4c08 100644 --- a/lib/node_modules/@stdlib/math/base/special/gcd/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/gcd/src/main.c @@ -21,8 +21,10 @@ #include "stdlib/math/base/assert/is_integer.h" #include "stdlib/constants/float64/pinf.h" #include "stdlib//constants/float64/ninf.h" -#include "stdlib/constants/int32/max.h" #include +#include + +static const int64_t STDLIB_CONSTANT_INT64_MAX = 9223372036854775807; /** * Computes the greatest common divisor (gcd) using the binary GCD algorithm. @@ -37,36 +39,36 @@ */ double largeIntegers( const double a, const double b ) { - int64_t ac; - int64_t bc; - int64_t k; - int64_t t; + double ac; + double bc; + double k; + double t; - ac = (int64_t)a; - bc = (int64_t)b; - k = 1; + ac = a; + bc = b; + k = 1.0; // Simple cases: - if ( ac == 0 ) { + if ( a == 0.0 ) { return b; } - if ( bc == 0 ) { + if ( b == 0.0 ) { return a; } // Reduce `a` and/or `b` to odd numbers and keep track of the greatest power of 2 dividing both `a` and `b`... - while ( ac%2 == 0 && bc%2 == 0 ) { - ac /= 2; // right shift - bc /= 2; // right shift - k *= 2; // left shift + while ( fmod( ac, 2.0 ) == 0.0 && fmod( bc, 2.0 ) == 0.0 ) { + ac /= 2.0; // right shift + bc /= 2.0; // right shift + k *= 2.0; // left shift } // Reduce `a` to an odd number... - while ( ac%2 == 0 ) { - ac /= 2; // right shift + while ( fmod( ac, 2.0 ) == 0.0 ) { + ac /= 2.0; // right shift } // Henceforth, `a` is always odd... while ( bc ) { // Remove all factors of 2 in `b`, as they are not common... - while ( bc%2 == 0 ) { - bc /= 2; // right shift + while ( fmod( bc, 2.0 ) == 0.0 ) { + bc /= 2.0; // right shift } // `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)... if ( ac > bc ) { @@ -147,7 +149,6 @@ double bitwise( const double a, const double b ) { * double out = stdlib_base_gcd( 48.0, 18.0 ); * // returns 6.0 */ - double stdlib_base_gcd( const double a, const double b ) { double ac; double bc; @@ -174,7 +175,7 @@ double stdlib_base_gcd( const double a, const double b ) { if ( bc < 0 ) { bc = -bc; } - if ( ac <= STDLIB_CONSTANT_INT32_MAX && bc <= STDLIB_CONSTANT_INT32_MAX ) { + if ( ac <= STDLIB_CONSTANT_INT64_MAX && bc <= STDLIB_CONSTANT_INT64_MAX ) { return bitwise( ac, bc ); } return largeIntegers( ac, bc );