]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Improve int64 -> double conversion
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 10 Dec 2016 12:14:45 +0000 (12:14 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 10 Dec 2016 12:28:08 +0000 (12:28 +0000)
src/libutil/util.c

index 3fc1c98bf1c985f319f58757081fe2c75cc1491c..36ca0cffcafeab96621ad94e801348b3cf0997e2 100644 (file)
@@ -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