File tree Expand file tree Collapse file tree 3 files changed +24
-18
lines changed
lib/node_modules/@stdlib/math/base/special/sinf/benchmark/c Expand file tree Collapse file tree 3 files changed +24
-18
lines changed Original file line number Diff line number Diff line change @@ -74,13 +74,15 @@ static double tic( void ) {
74
74
}
75
75
76
76
/**
77
- * Generates a random number on the interval [0,1 ).
77
+ * Generates a random number on the interval [min,max ).
78
78
*
79
- * @return random number
79
+ * @param min minimum value (inclusive)
80
+ * @param max maximum value (exclusive)
81
+ * @return random number
80
82
*/
81
- static float rand_float ( void ) {
82
- int r = rand ();
83
- return ( float ) r / ( ( float ) RAND_MAX + 1.0f );
83
+ static float random_uniform ( const float min , const float max ) {
84
+ float v = ( float ) rand () / ( ( float ) RAND_MAX + 1.0f );
85
+ return min + ( v * ( max - min ) );
84
86
}
85
87
86
88
/**
@@ -96,7 +98,7 @@ static double benchmark( void ) {
96
98
int i ;
97
99
98
100
for ( i = 0 ; i < 100 ; i ++ ) {
99
- x [ i ] = ( 20 .0f* rand_float () ) - 10.0f ;
101
+ x [ i ] = random_uniform ( -10 .0f, 10.0f ) ;
100
102
}
101
103
102
104
t = tic ();
Original file line number Diff line number Diff line change @@ -79,13 +79,15 @@ static double tic( void ) {
79
79
}
80
80
81
81
/**
82
- * Generates a random number on the interval [0,1 ).
82
+ * Generates a random number on the interval [min,max ).
83
83
*
84
- * @return random number
84
+ * @param min minimum value (inclusive)
85
+ * @param max maximum value (exclusive)
86
+ * @return random number
85
87
*/
86
- static float rand_float ( void ) {
87
- int r = rand ();
88
- return ( float ) r / ( ( float ) RAND_MAX + 1.0f );
88
+ static float random_uniform ( const float min , const float max ) {
89
+ float v = ( float ) rand () / ( ( float ) RAND_MAX + 1.0f );
90
+ return min + ( v * ( max - min ) );
89
91
}
90
92
91
93
/**
@@ -101,7 +103,7 @@ static double benchmark( void ) {
101
103
int i ;
102
104
103
105
for ( i = 0 ; i < 100 ; i ++ ) {
104
- x [ i ] = ( 20 .0f* rand_float () ) - 10.0f ;
106
+ x [ i ] = random_uniform ( -10 .0f, 10.0f ) ;
105
107
}
106
108
107
109
t = tic ();
Original file line number Diff line number Diff line change @@ -75,13 +75,15 @@ static double tic( void ) {
75
75
}
76
76
77
77
/**
78
- * Generates a random number on the interval [0,1 ).
78
+ * Generates a random number on the interval [min,max ).
79
79
*
80
- * @return random number
80
+ * @param min minimum value (inclusive)
81
+ * @param max maximum value (exclusive)
82
+ * @return random number
81
83
*/
82
- static float rand_float ( void ) {
83
- int r = rand ();
84
- return ( float ) r / ( ( float ) RAND_MAX + 1.0f );
84
+ static float random_uniform ( const float min , const float max ) {
85
+ float v = ( float ) rand () / ( ( float ) RAND_MAX + 1.0f );
86
+ return min + ( v * ( max - min ) );
85
87
}
86
88
87
89
/**
@@ -97,7 +99,7 @@ static double benchmark( void ) {
97
99
int i ;
98
100
99
101
for ( i = 0 ; i < 100 ; i ++ ) {
100
- x [ i ] = ( 20 .0f* rand_float () ) - 10.0f ;
102
+ x [ i ] = random_uniform ( -10 .0f, 10.0f ) ;
101
103
}
102
104
103
105
t = tic ();
You can’t perform that action at this time.
0 commit comments