aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-10 12:14:45 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-10 12:28:08 +0000
commita32d867f9f22bd5da802e1d808d67a1b99aac075 (patch)
treec013b60d932aa23c9b90cd4c5f3292227bd0cc08
parented436833f401c99e9be28fa82f02c5a2957c31c1 (diff)
downloadrspamd-a32d867f9f22bd5da802e1d808d67a1b99aac075.tar.gz
rspamd-a32d867f9f22bd5da802e1d808d67a1b99aac075.zip
[Minor] Improve int64 -> double conversion
-rw-r--r--src/libutil/util.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 3fc1c98bf..36ca0cffc 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2320,15 +2320,13 @@ rspamd_hash_seed (void)
}
static inline gdouble
-rspamd_double_from_int64 (guint64 rnd_int)
+rspamd_double_from_int64 (guint64 x)
{
- double res;
- const double transform_bias = 2.2204460492503130808472633361816e-16;
-
- res = rnd_int >> 12;
- res *= transform_bias;
+ const union { guint i; double d; } u = {
+ .i = G_GUINT64_CONSTANT(0x3FF) << 52 | x >> 12
+ };
- return res;
+ return u.d - 1.0;
}
gdouble