From 7708be4adf7bb948f847dfe2b26dae3a67422e80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 Nov 2024 20:55:33 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 1 + base/special/cround/benchmark/c/benchmark.c | 15 +++++++++------ .../special/cround/benchmark/c/native/benchmark.c | 9 ++++++--- base/special/cround/manifest.json | 9 ++++++--- base/special/cround/src/main.c | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f79fe6a4..a1db49364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -356,6 +356,7 @@ A total of 5 people contributed to this release. Thank you to the following cont
+- [`35ea456`](https://github.com/stdlib-js/stdlib/commit/35ea456c3f527fda8c717b5f31deccb6ba9e44d2) - **refactor:** use `stdlib_base_round` instead of builtin in `math/base/special/cround` [(#3216)](https://github.com/stdlib-js/stdlib/pull/3216) _(by Gunj Joshi)_ - [`7e2c16b`](https://github.com/stdlib-js/stdlib/commit/7e2c16b05d85b9d25c21626d4cbce381fcfe5d32) - **refactor:** remove unused header, update benchmarks in `math/base/special/croundf` [(#3217)](https://github.com/stdlib-js/stdlib/pull/3217) _(by Gunj Joshi)_ - [`c660c70`](https://github.com/stdlib-js/stdlib/commit/c660c705bb3478f4fb6cb818c9b1d3429e8a6774) - **chore:** use correct `Makefile` and update benchmarks in `math/base/special/csch` [(#3209)](https://github.com/stdlib-js/stdlib/pull/3209) _(by Gunj Joshi)_ - [`b6a2b0b`](https://github.com/stdlib-js/stdlib/commit/b6a2b0b27dc8cc1e9fc02d9679a3ce468cf49b9d) - **docs:** update namespace table of contents [(#3192)](https://github.com/stdlib-js/stdlib/pull/3192) _(by stdlib-bot, Philipp Burckhardt)_ diff --git a/base/special/cround/benchmark/c/benchmark.c b/base/special/cround/benchmark/c/benchmark.c index bdf1b168c..2626de420 100644 --- a/base/special/cround/benchmark/c/benchmark.c +++ b/base/special/cround/benchmark/c/benchmark.c @@ -90,20 +90,23 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double re; - double im; + double re[ 100 ]; + double im[ 100 ]; double t; int i; double complex z; double complex y; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0 * rand_double() ) - 500.0; + im[ i ] = ( 1000.0 * rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = re + im*I; - y = round( creal(z) ) + round( cimag(z) )*I; + z = re[ i % 100 ] + im[ i % 100 ]*I; + y = round( creal( z ) ) + round( cimag( z ) )*I; if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/base/special/cround/benchmark/c/native/benchmark.c b/base/special/cround/benchmark/c/native/benchmark.c index 5167e3338..1e234ad55 100644 --- a/base/special/cround/benchmark/c/native/benchmark.c +++ b/base/special/cround/benchmark/c/native/benchmark.c @@ -93,19 +93,22 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; + double v[ 100 ]; double re; double im; double t; - double v; int i; stdlib_complex128_t x; stdlib_complex128_t y; + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1000.0 * rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - v = ( 1000.0*rand_double() ) - 500.0; - x = stdlib_complex128( v, v ); + x = stdlib_complex128( v[ i % 100 ], v[ i % 100 ] ); y = stdlib_base_cround( x ); stdlib_complex128_reim( y, &re, &im ); if ( re != re ) { diff --git a/base/special/cround/manifest.json b/base/special/cround/manifest.json index 00d5fd64f..a07a9d35a 100644 --- a/base/special/cround/manifest.json +++ b/base/special/cround/manifest.json @@ -38,7 +38,8 @@ "dependencies": [ "@stdlib/math/base/napi/unary", "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim" + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/round" ] }, { @@ -53,7 +54,8 @@ "libpath": [], "dependencies": [ "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim" + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/round" ] }, { @@ -68,7 +70,8 @@ "libpath": [], "dependencies": [ "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim" + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/round" ] } ] diff --git a/base/special/cround/src/main.c b/base/special/cround/src/main.c index 125eda864..3e8ffb2ee 100644 --- a/base/special/cround/src/main.c +++ b/base/special/cround/src/main.c @@ -19,7 +19,7 @@ #include "stdlib/math/base/special/cround.h" #include "stdlib/complex/float64/ctor.h" #include "stdlib/complex/float64/reim.h" -#include +#include "stdlib/math/base/special/round.h" /** * Rounds each component of a double-precision complex floating-point number to the nearest integer. @@ -48,7 +48,7 @@ stdlib_complex128_t stdlib_base_cround( const stdlib_complex128_t z ) { stdlib_complex128_reim( z, &re, &im ); - re = round( re ); // TODO: replace with stdlib function once available - im = round( im ); // TODO: replace with stdlib function once available + re = stdlib_base_round( re ); + im = stdlib_base_round( im ); return stdlib_complex128( re, im ); }