Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -53,7 +54,8 @@
"libpath": [],
"dependencies": [
"@stdlib/complex/float64/ctor",
"@stdlib/complex/float64/reim"
"@stdlib/complex/float64/reim",
"@stdlib/math/base/special/round"
]
},
{
Expand All @@ -68,7 +70,8 @@
"libpath": [],
"dependencies": [
"@stdlib/complex/float64/ctor",
"@stdlib/complex/float64/reim"
"@stdlib/complex/float64/reim",
"@stdlib/math/base/special/round"
]
}
]
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/cround/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "stdlib/math/base/special/cround.h"
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/complex/float64/reim.h"
#include <math.h>
#include "stdlib/math/base/special/round.h"

/**
* Rounds each component of a double-precision complex floating-point number to the nearest integer.
Expand Down Expand Up @@ -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 );
}