File tree Expand file tree Collapse file tree 4 files changed +24
-15
lines changed
lib/node_modules/@stdlib/math/base/special/cround Expand file tree Collapse file tree 4 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -90,20 +90,23 @@ static double rand_double( void ) {
9090*/
9191static double benchmark ( void ) {
9292 double elapsed ;
93- double re ;
94- double im ;
93+ double re [ 100 ] ;
94+ double im [ 100 ] ;
9595 double t ;
9696 int i ;
9797
9898 double complex z ;
9999 double complex y ;
100100
101+ for ( i = 0 ; i < 100 ; i ++ ) {
102+ re [ i ] = ( 1000.0 * rand_double () ) - 500.0 ;
103+ im [ i ] = ( 1000.0 * rand_double () ) - 500.0 ;
104+ }
105+
101106 t = tic ();
102107 for ( i = 0 ; i < ITERATIONS ; i ++ ) {
103- re = ( 1000.0 * rand_double () ) - 500.0 ;
104- im = ( 1000.0 * rand_double () ) - 500.0 ;
105- z = re + im * I ;
106- y = round ( creal (z ) ) + round ( cimag (z ) )* I ;
108+ z = re [ i % 100 ] + im [ i % 100 ]* I ;
109+ y = round ( creal ( z ) ) + round ( cimag ( z ) )* I ;
107110 if ( y != y ) {
108111 printf ( "should not return NaN\n" );
109112 break ;
Original file line number Diff line number Diff line change @@ -93,19 +93,22 @@ static double rand_double( void ) {
9393*/
9494static double benchmark ( void ) {
9595 double elapsed ;
96+ double v [ 100 ];
9697 double re ;
9798 double im ;
9899 double t ;
99- double v ;
100100 int i ;
101101
102102 stdlib_complex128_t x ;
103103 stdlib_complex128_t y ;
104104
105+ for ( i = 0 ; i < 100 ; i ++ ) {
106+ v [ i ] = ( 1000.0 * rand_double () ) - 500.0 ;
107+ }
108+
105109 t = tic ();
106110 for ( i = 0 ; i < ITERATIONS ; i ++ ) {
107- v = ( 1000.0 * rand_double () ) - 500.0 ;
108- x = stdlib_complex128 ( v , v );
111+ x = stdlib_complex128 ( v [ i % 100 ], v [ i % 100 ] );
109112 y = stdlib_base_cround ( x );
110113 stdlib_complex128_reim ( y , & re , & im );
111114 if ( re != re ) {
Original file line number Diff line number Diff line change 3838 "dependencies" : [
3939 " @stdlib/math/base/napi/unary" ,
4040 " @stdlib/complex/float64/ctor" ,
41- " @stdlib/complex/float64/reim"
41+ " @stdlib/complex/float64/reim" ,
42+ " @stdlib/math/base/special/round"
4243 ]
4344 },
4445 {
5354 "libpath" : [],
5455 "dependencies" : [
5556 " @stdlib/complex/float64/ctor" ,
56- " @stdlib/complex/float64/reim"
57+ " @stdlib/complex/float64/reim" ,
58+ " @stdlib/math/base/special/round"
5759 ]
5860 },
5961 {
6870 "libpath" : [],
6971 "dependencies" : [
7072 " @stdlib/complex/float64/ctor" ,
71- " @stdlib/complex/float64/reim"
73+ " @stdlib/complex/float64/reim" ,
74+ " @stdlib/math/base/special/round"
7275 ]
7376 }
7477 ]
Original file line number Diff line number Diff line change 1919#include "stdlib/math/base/special/cround.h"
2020#include "stdlib/complex/float64/ctor.h"
2121#include "stdlib/complex/float64/reim.h"
22- #include < math.h>
22+ #include "stdlib/ math/base/special/round.h"
2323
2424/**
2525* 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 ) {
4848
4949 stdlib_complex128_reim ( z , & re , & im );
5050
51- re = round ( re ); // TODO: replace with stdlib function once available
52- im = round ( im ); // TODO: replace with stdlib function once available
51+ re = stdlib_base_round ( re );
52+ im = stdlib_base_round ( im );
5353 return stdlib_complex128 ( re , im );
5454}
You can’t perform that action at this time.
0 commit comments