## File: drand48.c

package info (click to toggle)
squid3 3.4.8-6
 `12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455` ``````#include "squid.h" /* borrowed from libc/misc/drand48.c in Linux libc-5.4.46 this quick * hack by Martin Hamilton to make Squid build on * Win32 with GNU-Win32 - sorry, folks! */ #if !HAVE_DRAND48 #define N 16 #define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1) #define LOW(x) ((unsigned)(x) & MASK) #define HIGH(x) LOW((x) >> N) #define MUL(x, y, z) { long l = (long)(x) * (long)(y); \ (z) = LOW(l); (z) = HIGH(l); } #define CARRY(x, y) ((long)(x) + (long)(y) > MASK) #define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y))) #define X0 0x330E #define X1 0xABCD #define X2 0x1234 #define A0 0xE66D #define A1 0xDEEC #define A2 0x5 #define C 0xB static void next(void); static unsigned x = {X0, X1, X2}, a = {A0, A1, A2}, c = C; double drand48(void); double drand48(void) { static double two16m = 1.0 / (1L << N); next(); return (two16m * (two16m * (two16m * x + x) + x)); } static void next(void) { unsigned p, q, r, carry0, carry1; MUL(a, x, p); ADDEQU(p, c, carry0); ADDEQU(p, carry0, carry1); MUL(a, x, q); ADDEQU(p, q, carry0); MUL(a, x, r); x = LOW(carry0 + carry1 + CARRY(p, r) + q + r + a * x + a * x + a * x); x = LOW(p + r); x = LOW(p); } #endif /* HAVE_DRAND48 */ ``````