Skip to content

Commit 2f7ff4a

Browse files
authored
chore: apply suggestions from code review
Signed-off-by: Philipp Burckhardt <[email protected]>
1 parent 1cea396 commit 2f7ff4a

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

lib/node_modules/@stdlib/stats/base/dists/uniform/median/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ for ( i = 0; i < 10; i++ ) {
161161

162162
#### stdlib_base_dists_uniform_median( a, b )
163163

164-
Returns the [median][median] of a [uniform][uniform-distribution] distribution with minimum value \( a \) and maximum value \( b \).
164+
Returns the [median][median] of a [uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
165165

166166
```c
167167
double out = stdlib_base_dists_uniform_median( 0.0, 1.0 );
@@ -170,8 +170,8 @@ double out = stdlib_base_dists_uniform_median( 0.0, 1.0 );
170170

171171
The function accepts the following arguments:
172172

173-
- **a**: `[in] double` minimum value.
174-
- **b**: `[in] double` maximum value.
173+
- **a**: `[in] double` minimum support.
174+
- **b**: `[in] double` maximum support.
175175

176176
```c
177177
double stdlib_base_dists_uniform_median( const double a, const double b );
@@ -200,15 +200,20 @@ double stdlib_base_dists_uniform_median( const double a, const double b );
200200
#include <stdlib.h>
201201
#include <stdio.h>
202202
203+
static double random_uniform( const double min, const double max ) {
204+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
205+
return min + ( v*(max-min) );
206+
}
207+
203208
int main( void ) {
204209
double a;
205210
double b;
206211
double y;
207212
int i;
208213
209214
for ( i = 0; i < 25; i++ ) {
210-
a = (double)( rand() % 10 );
211-
b = a + (double)( rand() % 10 + 1 ); // ensure b > a
215+
a = random_uniform( 0.0, 10.0 );
216+
b = random_uniform( a, 20.0 ); // ensure b > a
212217
y = stdlib_base_dists_uniform_median( a, b );
213218
printf( "a: %lf, b: %lf, Median(X;a,b): %lf\n", a, b, y );
214219
}

lib/node_modules/@stdlib/stats/base/dists/uniform/median/benchmark/c/benchmark.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ static double tic( void ) {
7474
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
7575
}
7676

77+
/**
78+
* Generates a random number on the interval [min,max).
79+
*
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
83+
*/
84+
static double random_uniform( const double min, const double max ) {
85+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
86+
return min + ( v*(max-min) );
87+
}
88+
7789
/**
7890
* Runs a benchmark.
7991
*
@@ -88,8 +100,8 @@ static double benchmark( void ) {
88100

89101
t = tic();
90102
for ( i = 0; i < ITERATIONS; i++ ) {
91-
a = ( (double)rand() / (double)RAND_MAX ) * 100.0; // Random lower bound between 0 and 100
92-
b = a + ( (double)rand() / (double)RAND_MAX ) * 100.0; // Random upper bound greater than a
103+
a = random_uniform( 0.0, 100.0 );
104+
b = random_uniform( a, 200.0 );
93105
y = stdlib_base_dists_uniform_median( a, b );
94106
if ( y != y ) {
95107
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/stats/base/dists/uniform/median/include/stdlib/stats/base/dists/uniform/median.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Returns the median of a uniform distribution with lower bound `a` and upper bound `b`.
30+
* Returns the median of a uniform distribution.
3131
*/
3232
double stdlib_base_dists_uniform_median( const double a, const double b );
3333

lib/node_modules/@stdlib/stats/base/dists/uniform/median/lib/native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ var addon = require( './../src/addon.node' );
2929
* Returns the median of a uniform distribution.
3030
*
3131
* @private
32-
* @param {number} a - lower bound
33-
* @param {number} b - upper bound
32+
* @param {number} a - minimum support
33+
* @param {number} b - maximum support
3434
* @returns {number} median
3535
*
3636
* @example

lib/node_modules/@stdlib/stats/base/dists/uniform/median/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
/**
2323
* Returns the median of a uniform distribution.
2424
*
25-
* @param a lower bound
26-
* @param b upper bound
25+
* @param a minimum support
26+
* @param b maximum support
2727
* @return median
2828
*
2929
* @example

0 commit comments

Comments
 (0)