From 476a29ecff9cf6da94933286f117d9815feb43c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 Nov 2024 19:38:29 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 1 + .../is-prime/benchmark/c/native/benchmark.c | 9 +- base/assert/is-prime/manifest.json | 42 ++++++- base/assert/is-prime/src/main.c | 106 +++++++++--------- 4 files changed, 100 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc8e13b4..aa8422fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -284,6 +284,7 @@ A total of 5 people contributed to this release. Thank you to the following cont
+- [`e0790b9`](https://github.com/stdlib-js/stdlib/commit/e0790b9a98228e98b1442a5cd7e93cf2dbe3aa7c) - **refactor:** replace built-in with `fmod` in `math/base/assert/is-prime` [(#3124)](https://github.com/stdlib-js/stdlib/pull/3124) _(by Gunj Joshi, stdlib-bot)_ - [`72bf083`](https://github.com/stdlib-js/stdlib/commit/72bf083eb1bbc829eebbbff32f73fc2a202b2570) - **refactor:** update benchmarks and test fixtures in `math/base/special/ahavercosf` [(#3118)](https://github.com/stdlib-js/stdlib/pull/3118) _(by Gunj Joshi)_ - [`163a3e7`](https://github.com/stdlib-js/stdlib/commit/163a3e7fa2c7429f88b2dd69df42572f9ff0af9d) - **refactor:** update benchmark, add `f` suffixes, missing spaces in `math/base/special/gcdf` [(#3121)](https://github.com/stdlib-js/stdlib/pull/3121) _(by Gunj Joshi, Athan Reines)_ - [`3c5c933`](https://github.com/stdlib-js/stdlib/commit/3c5c933c86f7243e8872dcf3cb7548d0399b1b35) - **refactor:** update benchmarks and test fixtures in `math/base/special/ahaversinf` [(#3119)](https://github.com/stdlib-js/stdlib/pull/3119) _(by Gunj Joshi)_ diff --git a/base/assert/is-prime/benchmark/c/native/benchmark.c b/base/assert/is-prime/benchmark/c/native/benchmark.c index 544f57a96..e2ac36262 100644 --- a/base/assert/is-prime/benchmark/c/native/benchmark.c +++ b/base/assert/is-prime/benchmark/c/native/benchmark.c @@ -92,15 +92,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double t; bool b; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 200.0 * rand_double() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double() * 200.0 ); - b = stdlib_base_is_prime( x ); + b = stdlib_base_is_prime( x[ i % 100 ] ); if ( b != true && b != false ) { printf( "should return either true or false\n" ); break; diff --git a/base/assert/is-prime/manifest.json b/base/assert/is-prime/manifest.json index dcced9794..d4c3183b9 100644 --- a/base/assert/is-prime/manifest.json +++ b/base/assert/is-prime/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/main.c" ], @@ -35,7 +38,42 @@ "dependencies": [ "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/floor", - "@stdlib/constants/float64/max-safe-integer" + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/special/fmod" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/floor", + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/special/fmod" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/floor", + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/math/base/special/fmod" ] } ] diff --git a/base/assert/is-prime/src/main.c b/base/assert/is-prime/src/main.c index a49293f0e..efb4eabcb 100644 --- a/base/assert/is-prime/src/main.c +++ b/base/assert/is-prime/src/main.c @@ -20,8 +20,8 @@ #include "stdlib/math/base/special/sqrt.h" #include "stdlib/math/base/special/floor.h" #include "stdlib/constants/float64/max_safe_integer.h" +#include "stdlib/math/base/special/fmod.h" #include -#include static const double WHEEL_PRIMES[45] = { 11.0, 13.0, 17.0, 19.0, 23.0, 29.0, 31.0, 37.0, 41.0, 43.0, 47.0, 53.0, 59.0, 61.0, 67.0, 71.0, 73.0, 79.0, 83.0, 89.0, 97.0, @@ -54,7 +54,7 @@ bool stdlib_base_is_prime( const double x ) { return ( x > 1.0 ); // primes: 2.0, 3.0 } // Check whether the number is even... - if ( x > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER || ( fmod( x, 2.0 ) ) == 0.0 ) { + if ( x > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER || ( stdlib_base_fmod( x, 2.0 ) ) == 0.0 ) { return false; } // Check for small primes... @@ -62,15 +62,15 @@ bool stdlib_base_is_prime( const double x ) { return true; // primes: 5.0, 7.0 } // Check whether the number is evenly divisible by `3`... - if ( fmod( x, 3.0 ) == 0.0 ) { // TODO: replace fmod usage once we have a stdlib equivalent + if ( stdlib_base_fmod( x, 3.0 ) == 0.0 ) { return false; } // Check whether the number is evenly divisible by `5`... - if ( fmod( x, 5.0 ) == 0.0 ) { + if ( stdlib_base_fmod( x, 5.0 ) == 0.0 ) { return false; } // Check whether the number is evenly divisible by `7`... - if ( fmod( x, 7.0 ) == 0.0 ) { + if ( stdlib_base_fmod( x, 7.0 ) == 0.0 ) { return false; } // Check whether the number is a prime number in the wheel... @@ -83,54 +83,54 @@ bool stdlib_base_is_prime( const double x ) { N = stdlib_base_floor( stdlib_base_sqrt( x ) ); for ( i = 11; i <= N; i += 210 ) { if ( - fmod( x, i ) == 0.0 || // 11 - fmod( x, ( i + 2 ) ) == 0.0 || // 13 - fmod( x, ( i + 6 ) ) == 0.0 || // 17 - fmod( x, ( i + 8 ) ) == 0.0 || // 19 - fmod( x, ( i + 12 ) ) == 0.0 || // 23 - fmod( x, ( i + 18 ) ) == 0.0 || // 29 - fmod( x, ( i + 20 ) ) == 0.0 || // 31 - fmod( x, ( i + 26 ) ) == 0.0 || // 37 - fmod( x, ( i + 30 ) ) == 0.0 || // 41 - fmod( x, ( i + 32 ) ) == 0.0 || // 43 - fmod( x, ( i + 36 ) ) == 0.0 || // 47 - fmod( x, ( i + 42 ) ) == 0.0 || // 53 - fmod( x, ( i + 48 ) ) == 0.0 || // 59 - fmod( x, ( i + 50 ) ) == 0.0 || // 61 - fmod( x, ( i + 56 ) ) == 0.0 || // 67 - fmod( x, ( i + 60 ) ) == 0.0 || // 71 - fmod( x, ( i + 62 ) ) == 0.0 || // 73 - fmod( x, ( i + 68 ) ) == 0.0 || // 79 - fmod( x, ( i + 72 ) ) == 0.0 || // 83 - fmod( x, ( i + 78 ) ) == 0.0 || // 89 - fmod( x, ( i + 86 ) ) == 0.0 || // 97 - fmod( x, ( i + 90 ) ) == 0.0 || // 101 - fmod( x, ( i + 92 ) ) == 0.0 || // 103 - fmod( x, ( i + 96 ) ) == 0.0 || // 107 - fmod( x, ( i + 98 ) ) == 0.0 || // 109 - fmod( x, ( i + 102 ) ) == 0.0 || // 113 - fmod( x, ( i + 110 ) ) == 0.0 || // 121 (relatively prime) - fmod( x, ( i + 116 ) ) == 0.0 || // 127 - fmod( x, ( i + 120 ) ) == 0.0 || // 131 - fmod( x, ( i + 126 ) ) == 0.0 || // 137 - fmod( x, ( i + 128 ) ) == 0.0 || // 139 - fmod( x, ( i + 132 ) ) == 0.0 || // 143 (relatively prime) - fmod( x, ( i + 138 ) ) == 0.0 || // 149 - fmod( x, ( i + 140 ) ) == 0.0 || // 151 - fmod( x, ( i + 146 ) ) == 0.0 || // 157 - fmod( x, ( i + 152 ) ) == 0.0 || // 163 - fmod( x, ( i + 156 ) ) == 0.0 || // 167 - fmod( x, ( i + 158 ) ) == 0.0 || // 169 (relatively prime) - fmod( x, ( i + 162 ) ) == 0.0 || // 173 - fmod( x, ( i + 168 ) ) == 0.0 || // 179 - fmod( x, ( i + 170 ) ) == 0.0 || // 181 - fmod( x, ( i + 176 ) ) == 0.0 || // 187 (relatively prime) - fmod( x, ( i + 180 ) ) == 0.0 || // 191 - fmod( x, ( i + 182 ) ) == 0.0 || // 193 - fmod( x, ( i + 186 ) ) == 0.0 || // 197 - fmod( x, ( i + 188 ) ) == 0.0 || // 199 - fmod( x, ( i + 198 ) ) == 0.0 || // 209 (relatively prime) - fmod( x, ( i + 200 ) ) == 0.0 // 211 + stdlib_base_fmod( x, i ) == 0.0 || // 11 + stdlib_base_fmod( x, ( i + 2 ) ) == 0.0 || // 13 + stdlib_base_fmod( x, ( i + 6 ) ) == 0.0 || // 17 + stdlib_base_fmod( x, ( i + 8 ) ) == 0.0 || // 19 + stdlib_base_fmod( x, ( i + 12 ) ) == 0.0 || // 23 + stdlib_base_fmod( x, ( i + 18 ) ) == 0.0 || // 29 + stdlib_base_fmod( x, ( i + 20 ) ) == 0.0 || // 31 + stdlib_base_fmod( x, ( i + 26 ) ) == 0.0 || // 37 + stdlib_base_fmod( x, ( i + 30 ) ) == 0.0 || // 41 + stdlib_base_fmod( x, ( i + 32 ) ) == 0.0 || // 43 + stdlib_base_fmod( x, ( i + 36 ) ) == 0.0 || // 47 + stdlib_base_fmod( x, ( i + 42 ) ) == 0.0 || // 53 + stdlib_base_fmod( x, ( i + 48 ) ) == 0.0 || // 59 + stdlib_base_fmod( x, ( i + 50 ) ) == 0.0 || // 61 + stdlib_base_fmod( x, ( i + 56 ) ) == 0.0 || // 67 + stdlib_base_fmod( x, ( i + 60 ) ) == 0.0 || // 71 + stdlib_base_fmod( x, ( i + 62 ) ) == 0.0 || // 73 + stdlib_base_fmod( x, ( i + 68 ) ) == 0.0 || // 79 + stdlib_base_fmod( x, ( i + 72 ) ) == 0.0 || // 83 + stdlib_base_fmod( x, ( i + 78 ) ) == 0.0 || // 89 + stdlib_base_fmod( x, ( i + 86 ) ) == 0.0 || // 97 + stdlib_base_fmod( x, ( i + 90 ) ) == 0.0 || // 101 + stdlib_base_fmod( x, ( i + 92 ) ) == 0.0 || // 103 + stdlib_base_fmod( x, ( i + 96 ) ) == 0.0 || // 107 + stdlib_base_fmod( x, ( i + 98 ) ) == 0.0 || // 109 + stdlib_base_fmod( x, ( i + 102 ) ) == 0.0 || // 113 + stdlib_base_fmod( x, ( i + 110 ) ) == 0.0 || // 121 (relatively prime) + stdlib_base_fmod( x, ( i + 116 ) ) == 0.0 || // 127 + stdlib_base_fmod( x, ( i + 120 ) ) == 0.0 || // 131 + stdlib_base_fmod( x, ( i + 126 ) ) == 0.0 || // 137 + stdlib_base_fmod( x, ( i + 128 ) ) == 0.0 || // 139 + stdlib_base_fmod( x, ( i + 132 ) ) == 0.0 || // 143 (relatively prime) + stdlib_base_fmod( x, ( i + 138 ) ) == 0.0 || // 149 + stdlib_base_fmod( x, ( i + 140 ) ) == 0.0 || // 151 + stdlib_base_fmod( x, ( i + 146 ) ) == 0.0 || // 157 + stdlib_base_fmod( x, ( i + 152 ) ) == 0.0 || // 163 + stdlib_base_fmod( x, ( i + 156 ) ) == 0.0 || // 167 + stdlib_base_fmod( x, ( i + 158 ) ) == 0.0 || // 169 (relatively prime) + stdlib_base_fmod( x, ( i + 162 ) ) == 0.0 || // 173 + stdlib_base_fmod( x, ( i + 168 ) ) == 0.0 || // 179 + stdlib_base_fmod( x, ( i + 170 ) ) == 0.0 || // 181 + stdlib_base_fmod( x, ( i + 176 ) ) == 0.0 || // 187 (relatively prime) + stdlib_base_fmod( x, ( i + 180 ) ) == 0.0 || // 191 + stdlib_base_fmod( x, ( i + 182 ) ) == 0.0 || // 193 + stdlib_base_fmod( x, ( i + 186 ) ) == 0.0 || // 197 + stdlib_base_fmod( x, ( i + 188 ) ) == 0.0 || // 199 + stdlib_base_fmod( x, ( i + 198 ) ) == 0.0 || // 209 (relatively prime) + stdlib_base_fmod( x, ( i + 200 ) ) == 0.0 // 211 ) { return false; }