@@ -187,6 +187,32 @@ static double getFloat_closed_closed(const php_random_algo *algo, php_random_sta
187
187
}
188
188
}
189
189
190
+ static double getFloat_open_closed (const php_random_algo * algo , php_random_status * status , double min , double max )
191
+ {
192
+ double g = getFloat_gamma (min , max );
193
+ uint64_t hi = getFloat_ceilint (min , max , g );
194
+ uint64_t k = algo -> range (status , 0 , hi - 1 );
195
+
196
+ if (fabs (min ) <= fabs (max )) {
197
+ return max - k * g ;
198
+ } else {
199
+ return k == (hi - 1 ) ? max : min + (k + 1 ) * g ;
200
+ }
201
+ }
202
+
203
+ static double getFloat_open_open (const php_random_algo * algo , php_random_status * status , double min , double max )
204
+ {
205
+ double g = getFloat_gamma (min , max );
206
+ uint64_t hi = getFloat_ceilint (min , max , g );
207
+ uint64_t k = algo -> range (status , 1 , hi - 1 );
208
+
209
+ if (fabs (min ) <= fabs (max )) {
210
+ return max - k * g ;
211
+ } else {
212
+ return min + k * g ;
213
+ }
214
+ }
215
+
190
216
/* {{{ Generates a random float within [min, max).
191
217
*
192
218
* The algorithm used is the γ-section algorithm as published in:
@@ -230,6 +256,12 @@ PHP_METHOD(Random_Randomizer, getFloat)
230
256
if (zend_string_equals_literal (bounds_name , "ClosedClosed" )) {
231
257
RETURN_DOUBLE (getFloat_closed_closed (randomizer -> algo , randomizer -> status , min , max ));
232
258
}
259
+ if (zend_string_equals_literal (bounds_name , "OpenClosed" )) {
260
+ RETURN_DOUBLE (getFloat_open_closed (randomizer -> algo , randomizer -> status , min , max ));
261
+ }
262
+ if (zend_string_equals_literal (bounds_name , "OpenOpen" )) {
263
+ RETURN_DOUBLE (getFloat_open_open (randomizer -> algo , randomizer -> status , min , max ));
264
+ }
233
265
ZEND_UNREACHABLE ();
234
266
}
235
267
/* }}} */
0 commit comments