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 ) {
90
90
*/
91
91
static double benchmark ( void ) {
92
92
double elapsed ;
93
- double re ;
94
- double im ;
93
+ double re [ 100 ] ;
94
+ double im [ 100 ] ;
95
95
double t ;
96
96
int i ;
97
97
98
98
double complex z ;
99
99
double complex y ;
100
100
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
+
101
106
t = tic ();
102
107
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 ;
107
110
if ( y != y ) {
108
111
printf ( "should not return NaN\n" );
109
112
break ;
Original file line number Diff line number Diff line change @@ -93,19 +93,22 @@ static double rand_double( void ) {
93
93
*/
94
94
static double benchmark ( void ) {
95
95
double elapsed ;
96
+ double v [ 100 ];
96
97
double re ;
97
98
double im ;
98
99
double t ;
99
- double v ;
100
100
int i ;
101
101
102
102
stdlib_complex128_t x ;
103
103
stdlib_complex128_t y ;
104
104
105
+ for ( i = 0 ; i < 100 ; i ++ ) {
106
+ v [ i ] = ( 1000.0 * rand_double () ) - 500.0 ;
107
+ }
108
+
105
109
t = tic ();
106
110
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 ] );
109
112
y = stdlib_base_cround ( x );
110
113
stdlib_complex128_reim ( y , & re , & im );
111
114
if ( re != re ) {
Original file line number Diff line number Diff line change 38
38
"dependencies" : [
39
39
" @stdlib/math/base/napi/unary" ,
40
40
" @stdlib/complex/float64/ctor" ,
41
- " @stdlib/complex/float64/reim"
41
+ " @stdlib/complex/float64/reim" ,
42
+ " @stdlib/math/base/special/round"
42
43
]
43
44
},
44
45
{
53
54
"libpath" : [],
54
55
"dependencies" : [
55
56
" @stdlib/complex/float64/ctor" ,
56
- " @stdlib/complex/float64/reim"
57
+ " @stdlib/complex/float64/reim" ,
58
+ " @stdlib/math/base/special/round"
57
59
]
58
60
},
59
61
{
68
70
"libpath" : [],
69
71
"dependencies" : [
70
72
" @stdlib/complex/float64/ctor" ,
71
- " @stdlib/complex/float64/reim"
73
+ " @stdlib/complex/float64/reim" ,
74
+ " @stdlib/math/base/special/round"
72
75
]
73
76
}
74
77
]
Original file line number Diff line number Diff line change 19
19
#include "stdlib/math/base/special/cround.h"
20
20
#include "stdlib/complex/float64/ctor.h"
21
21
#include "stdlib/complex/float64/reim.h"
22
- #include < math.h>
22
+ #include "stdlib/ math/base/special/round.h"
23
23
24
24
/**
25
25
* 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 ) {
48
48
49
49
stdlib_complex128_reim ( z , & re , & im );
50
50
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 );
53
53
return stdlib_complex128 ( re , im );
54
54
}
You can’t perform that action at this time.
0 commit comments