summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2015-02-13 11:32:35 +0100
committerteor <teor2345@gmail.com>2015-05-06 18:05:16 +1000
commitdad5eb7e1f3c92974c7bcaaea325a05233a27494 (patch)
treea80bcfcbf8204e7230aeb93302472585b9ebe62b /src/common/util.c
parentb3832e0b7f95e8082acce1be6505179d38f30d14 (diff)
downloadtor-dad5eb7e1f3c92974c7bcaaea325a05233a27494.tar.gz
tor-dad5eb7e1f3c92974c7bcaaea325a05233a27494.zip
Tweak teor's and dgoulet's #13192 patches.
- Rewrite changes file. - Avoid float comparison with == and use <= instead. - Add teor's tor_llround(trunc(...)) back to silence clang warnings. - Replace tt_assert() with tt_i64_op() and friends. - Fix whitespace and a comment.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 3e680d2d9e..d8da8b1161 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -546,26 +546,26 @@ sample_laplace_distribution(double mu, double b, double p)
/* This is the "inverse cumulative distribution function" from:
* http://en.wikipedia.org/wiki/Laplace_distribution */
- if (p == 0.0) {
+ if (p <= 0.0) {
/* Avoid taking log(0.0) == -INFINITY, as some processors or compiler
* options can cause the program to trap. */
return INT64_MIN;
}
- result = mu - b * (p > 0.5 ? 1.0 : -1.0)
- * tor_mathlog(1.0 - 2.0 * fabs(p - 0.5));
+ result = mu - b * (p > 0.5 ? 1.0 : -1.0)
+ * tor_mathlog(1.0 - 2.0 * fabs(p - 0.5));
if (result >= INT64_MAX)
return INT64_MAX;
else if (result <= INT64_MIN)
return INT64_MIN;
else
- return (int64_t) result;
+ return tor_llround(trunc(result));
}
/** Add random noise between INT64_MIN and INT64_MAX coming from a Laplace
* distribution with mu = 0 and b = <b>delta_f</b>/<b>epsilon</b> to
* <b>signal</b> based on the provided <b>random</b> value in [0.0, 1.0[.
- * The epislon value must be between ]0.0, 1.0]. delta_f must be greater
+ * The epsilon value must be between ]0.0, 1.0]. delta_f must be greater
* than 0. */
int64_t
add_laplace_noise(int64_t signal, double random, double delta_f,