1 1.2 drochner /* $NetBSD: erand48_ieee754.c,v 1.2 2006/03/31 11:42:31 drochner Exp $ */ 2 1.1 drochner 3 1.1 drochner /* 4 1.1 drochner * Copyright (c) 1993 Martin Birgmeier 5 1.1 drochner * All rights reserved. 6 1.1 drochner * 7 1.1 drochner * You may redistribute unmodified or modified versions of this source 8 1.1 drochner * code provided that the above copyright notice and this and the 9 1.1 drochner * following conditions are retained. 10 1.1 drochner * 11 1.1 drochner * This software is provided ``as is'', and comes with no warranties 12 1.1 drochner * of any kind. I shall in no event be liable for anything that happens 13 1.1 drochner * to anyone/anything when using this software. 14 1.1 drochner */ 15 1.1 drochner 16 1.1 drochner #include <sys/cdefs.h> 17 1.1 drochner #if defined(LIBC_SCCS) && !defined(lint) 18 1.2 drochner __RCSID("$NetBSD: erand48_ieee754.c,v 1.2 2006/03/31 11:42:31 drochner Exp $"); 19 1.1 drochner #endif /* LIBC_SCCS and not lint */ 20 1.1 drochner 21 1.1 drochner #include "namespace.h" 22 1.1 drochner 23 1.1 drochner #include <assert.h> 24 1.1 drochner #include <machine/ieee.h> 25 1.1 drochner 26 1.1 drochner #include "rand48.h" 27 1.1 drochner 28 1.1 drochner #ifdef __weak_alias 29 1.1 drochner __weak_alias(erand48,_erand48) 30 1.1 drochner #endif 31 1.1 drochner 32 1.1 drochner double 33 1.1 drochner erand48(unsigned short xseed[3]) 34 1.1 drochner { 35 1.1 drochner union ieee_double_u u; 36 1.1 drochner 37 1.1 drochner _DIAGASSERT(xseed != NULL); 38 1.1 drochner 39 1.1 drochner __dorand48(xseed); 40 1.1 drochner u.dblu_dbl.dbl_sign = 0; 41 1.1 drochner u.dblu_dbl.dbl_exp = DBL_EXP_BIAS; /* so we get [1,2) */ 42 1.2 drochner u.dblu_dbl.dbl_frach = ((unsigned int)xseed[2] << 4) 43 1.1 drochner | ((unsigned int)xseed[1] >> 12); 44 1.1 drochner u.dblu_dbl.dbl_fracl = (((unsigned int)xseed[1] & 0x0fff) << 20) 45 1.2 drochner | ((unsigned int)xseed[0] << 4); 46 1.1 drochner return (u.dblu_d - 1); 47 1.1 drochner } 48