diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2021-09-24 08:56:12 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-24 08:56:12 -0600 |
| commit | ea7b0e281a8d221c847abb2cd760cb067fa8543b (patch) | |
| tree | bfbce135560240a9c90d3a114940367af1848a0d /numpy | |
| parent | 0cf5bc092f801a4c004ecdb7d1061f46aaab4ff4 (diff) | |
| parent | d1ed2c2b1eecac38cc31a9cc2ad15c86fd520137 (diff) | |
| download | numpy-ea7b0e281a8d221c847abb2cd760cb067fa8543b.tar.gz | |
Merge pull request #19933 from WarrenWeckesser/random-use-expm1
MAINT: random: Use expm1 where appropriate.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/random/src/distributions/distributions.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/numpy/random/src/distributions/distributions.c b/numpy/random/src/distributions/distributions.c index 9bdfa9bea..adf4db4a7 100644 --- a/numpy/random/src/distributions/distributions.c +++ b/numpy/random/src/distributions/distributions.c @@ -452,7 +452,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) { @@ -463,7 +463,7 @@ double random_weibull(bitgen_t *bitgen_state, double a) { } double random_power(bitgen_t *bitgen_state, double a) { - return pow(1 - exp(-random_standard_exponential(bitgen_state)), 1. / a); + return pow(-expm1(-random_standard_exponential(bitgen_state)), 1. / a); } double random_laplace(bitgen_t *bitgen_state, double loc, double scale) { @@ -918,7 +918,7 @@ int64_t random_logseries(bitgen_t *bitgen_state, double p) { return 1; } U = next_double(bitgen_state); - q = 1.0 - exp(r * U); + q = -expm1(r * U); if (V <= q * q) { result = (int64_t)floor(1 + log(V) / log(q)); if ((result < 1) || (V == 0.0)) { |
