Home | History | Annotate | Line # | Download | only in stdlib
erand48.c revision 1.9
      1  1.9  drochner /*	$NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $	*/
      2  1.4     perry 
      3  1.1    brezak /*
      4  1.1    brezak  * Copyright (c) 1993 Martin Birgmeier
      5  1.1    brezak  * All rights reserved.
      6  1.1    brezak  *
      7  1.1    brezak  * You may redistribute unmodified or modified versions of this source
      8  1.1    brezak  * code provided that the above copyright notice and this and the
      9  1.1    brezak  * following conditions are retained.
     10  1.1    brezak  *
     11  1.1    brezak  * This software is provided ``as is'', and comes with no warranties
     12  1.1    brezak  * of any kind. I shall in no event be liable for anything that happens
     13  1.1    brezak  * to anyone/anything when using this software.
     14  1.1    brezak  */
     15  1.1    brezak 
     16  1.8     lukem #include <sys/cdefs.h>
     17  1.8     lukem #if defined(LIBC_SCCS) && !defined(lint)
     18  1.9  drochner __RCSID("$NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $");
     19  1.8     lukem #endif /* LIBC_SCCS and not lint */
     20  1.8     lukem 
     21  1.3       jtc #include "namespace.h"
     22  1.5     lukem 
     23  1.5     lukem #include <assert.h>
     24  1.9  drochner #include <math.h>
     25  1.5     lukem 
     26  1.1    brezak #include "rand48.h"
     27  1.3       jtc 
     28  1.3       jtc #ifdef __weak_alias
     29  1.7   mycroft __weak_alias(erand48,_erand48)
     30  1.3       jtc #endif
     31  1.1    brezak 
     32  1.1    brezak double
     33  1.1    brezak erand48(unsigned short xseed[3])
     34  1.1    brezak {
     35  1.5     lukem 
     36  1.5     lukem 	_DIAGASSERT(xseed != NULL);
     37  1.5     lukem 
     38  1.2       jtc 	__dorand48(xseed);
     39  1.1    brezak 	return ldexp((double) xseed[0], -48) +
     40  1.1    brezak 	       ldexp((double) xseed[1], -32) +
     41  1.1    brezak 	       ldexp((double) xseed[2], -16);
     42  1.1    brezak }
     43