Skip to content

Commit 99e6c3e

Browse files
committed
random: Clean up the implementation of Randomizer::getFloat()
1 parent 4c24fce commit 99e6c3e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

ext/random/randomizer.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,9 @@ PHP_METHOD(Random_Randomizer, nextFloat)
130130
}
131131
/* }}} */
132132

133-
/* {{{ Generates a random float within [min, max).
133+
/* {{{ Generates a random float within a configurable interval.
134134
*
135-
* The algorithm used is the γ-section algorithm as published in:
136-
*
137-
* Drawing Random Floating-Point Numbers from an Interval. Frédéric
138-
* Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022.
139-
* https://doi.org/10.1145/3503512
135+
* This method uses the γ-section algorithm by Frédéric Goualard.
140136
*/
141137
PHP_METHOD(Random_Randomizer, getFloat)
142138
{
@@ -169,32 +165,30 @@ PHP_METHOD(Random_Randomizer, getFloat)
169165
}
170166

171167
RETURN_DOUBLE(php_random_gammasection_closed_open(randomizer->algo, randomizer->status, min, max));
172-
}
173-
if (zend_string_equals_literal(bounds_name, "ClosedClosed")) {
168+
} else if (zend_string_equals_literal(bounds_name, "ClosedClosed")) {
174169
if (UNEXPECTED(max < min)) {
175170
zend_argument_value_error(2, "must be greater than or equal to argument #1 ($min)");
176171
RETURN_THROWS();
177172
}
178173

179174
RETURN_DOUBLE(php_random_gammasection_closed_closed(randomizer->algo, randomizer->status, min, max));
180-
}
181-
if (zend_string_equals_literal(bounds_name, "OpenClosed")) {
175+
} else if (zend_string_equals_literal(bounds_name, "OpenClosed")) {
182176
if (UNEXPECTED(max <= min)) {
183177
zend_argument_value_error(2, "must be greater than argument #1 ($min)");
184178
RETURN_THROWS();
185179
}
186180

187181
RETURN_DOUBLE(php_random_gammasection_open_closed(randomizer->algo, randomizer->status, min, max));
188-
}
189-
if (zend_string_equals_literal(bounds_name, "OpenOpen")) {
182+
} else if (zend_string_equals_literal(bounds_name, "OpenOpen")) {
190183
if (UNEXPECTED(max <= min)) {
191184
zend_argument_value_error(2, "must be greater than argument #1 ($min)");
192185
RETURN_THROWS();
193186
}
194187

195188
RETURN_DOUBLE(php_random_gammasection_open_open(randomizer->algo, randomizer->status, min, max));
189+
} else {
190+
ZEND_UNREACHABLE();
196191
}
197-
ZEND_UNREACHABLE();
198192
}
199193
/* }}} */
200194

0 commit comments

Comments
 (0)