]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/drand48.c
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
11 /* borrowed from libc/misc/drand48.c in Linux libc-5.4.46 this quick
12 * hack by Martin Hamilton <martinh@gnu.org> to make Squid build on
13 * Win32 with GNU-Win32 - sorry, folks! */
18 #define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1)
19 #define LOW(x) ((unsigned)(x) & MASK)
20 #define HIGH(x) LOW((x) >> N)
21 #define MUL(x, y, z) { long l = (long)(x) * (long)(y); \
22 (z)[0] = LOW(l); (z)[1] = HIGH(l); }
23 #define CARRY(x, y) ((long)(x) + (long)(y) > MASK)
24 #define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y)))
33 static void next(void);
34 static unsigned x
[3] = {X0
, X1
, X2
}, a
[3] = {A0
, A1
, A2
}, c
= C
;
41 static double two16m
= 1.0 / (1L << N
);
43 return (two16m
* (two16m
* (two16m
* x
[0] + x
[1]) + x
[2]));
49 unsigned p
[2], q
[2], r
[2], carry0
, carry1
;
52 ADDEQU(p
[0], c
, carry0
);
53 ADDEQU(p
[1], carry0
, carry1
);
55 ADDEQU(p
[1], q
[0], carry0
);
57 x
[2] = LOW(carry0
+ carry1
+ CARRY(p
[1], r
[0]) + q
[1] + r
[1] +
58 a
[0] * x
[2] + a
[1] * x
[1] + a
[2] * x
[0]);
59 x
[1] = LOW(p
[1] + r
[0]);
63 #endif /* HAVE_DRAND48 */