Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Use expm1(x) instead of exp(x) - 1 #15346

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/random/src/distributions/distributions.c
Expand Up @@ -448,7 +448,7 @@ double random_standard_cauchy(bitgen_t *bitgen_state) {
}

double random_pareto(bitgen_t *bitgen_state, double a) {
return exp(random_standard_exponential(bitgen_state) / a) - 1;
return expm1(random_standard_exponential(bitgen_state) / a);
}

double random_weibull(bitgen_t *bitgen_state, double a) {
Expand Down
4 changes: 4 additions & 0 deletions numpy/random/tests/test_smoke.py
Expand Up @@ -793,6 +793,10 @@ def test_default_is_pcg64(self):
# a deprecation cycle to move to a different function.
assert_(isinstance(self.rg.bit_generator, PCG64))

def test_expm1(self):
np.random.default_rng(12345)
assert_(np.random.default_rng(1e99) > 0.0)

gaurav1086 marked this conversation as resolved.
Show resolved Hide resolved
def test_seed(self):
np.random.default_rng()
np.random.default_rng(None)
Expand Down