*BSD News Article 21653


Return to BSD News archive

Xref: sserve comp.os.386bsd.misc:1136 comp.os.386bsd.questions:5486
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!saimiri.primate.wisc.edu!caen!math.ohio-state.edu!cs.utexas.edu!uunet!email.tuwien.ac.at!ntkupc1.tuwien.ac.at!not-for-mail
From: martin@ntkupc1.tuwien.ac.at (Martin Birgmeier)
Newsgroups: comp.os.386bsd.misc,comp.os.386bsd.questions
Subject: Re: new math library for *BSD ?
Date: 30 Sep 1993 08:41:13 +0100
Organization: Dept. of Comm. Engr., Tech. Univ. of Vienna, Austria
Lines: 453
Message-ID: <28e2ip$b5@ntkupc1.tuwien.ac.at>
References: <CE49wF.n4J@latcs1.lat.oz.au>
NNTP-Posting-Host: ntkupc1.tuwien.ac.at

In article <CE49wF.n4J@latcs1.lat.oz.au>,
M.C. Wong <wongm@latcs1.lat.oz.au> wrote:
>Hi,
>  Sorry if this question has been answered before. I would like to
>get a new math lib (libm.a) that includes the following for *BSD :
>drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, 
>lcong48. 
>
>  Does such lib exist anywhere in the net ?
>
>  Thanks in advance and email replies please!
[...]

Since I'm so proud of my work I'll post anyways :-)

============================== cut here ==============================
*** /usr/src/lib/libc/stdlib/Makefile.inc.RAND48_ORIG	Mon Mar 22 15:40:23 1993
--- /usr/src/lib/libc/stdlib/Makefile.inc	Mon Apr 19 11:38:58 1993
***************
*** 6,12 ****
  SRCS+=	abort.c atexit.c atoi.c atol.c bsearch.c calloc.c div.c exit.c \
  	getenv.c getopt.c heapsort.c labs.c ldiv.c malloc.c multibyte.c \
  	putenv.c qsort.c radixsort.c rand.c random.c setenv.c strtol.c \
! 	strtoul.c system.c
  
  .if   (${MACHINE} == "hp300")
  SRCS+=	abs.s atof.c
--- 6,14 ----
  SRCS+=	abort.c atexit.c atoi.c atol.c bsearch.c calloc.c div.c exit.c \
  	getenv.c getopt.c heapsort.c labs.c ldiv.c malloc.c multibyte.c \
  	putenv.c qsort.c radixsort.c rand.c random.c setenv.c strtol.c \
! 	strtoul.c system.c \
! 	_rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \
! 	mrand48.c nrand48.c seed48.c srand48.c
  
  .if   (${MACHINE} == "hp300")
  SRCS+=	abs.s atof.c
*** /usr/src/lib/libc/stdlib/srand48.c.RAND48_ORIG	Mon Apr 19 11:30:12 1993
--- /usr/src/lib/libc/stdlib/srand48.c	Mon Apr 19 11:36:54 1993
***************
*** 0 ****
--- 1,30 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ extern unsigned short _rand48_mult[3];
+ extern unsigned short _rand48_add;
+ 
+ void
+ srand48(long seed)
+ {
+ 	_rand48_seed[0] = RAND48_SEED_0;
+ 	_rand48_seed[1] = (unsigned short) seed;
+ 	_rand48_seed[2] = (unsigned short) (seed >> 16);
+ 	_rand48_mult[0] = RAND48_MULT_0;
+ 	_rand48_mult[1] = RAND48_MULT_1;
+ 	_rand48_mult[2] = RAND48_MULT_2;
+ 	_rand48_add = RAND48_ADD;
+ }
*** /usr/src/lib/libc/stdlib/seed48.c.RAND48_ORIG	Mon Apr 19 11:30:12 1993
--- /usr/src/lib/libc/stdlib/seed48.c	Mon Apr 19 11:36:52 1993
***************
*** 0 ****
--- 1,36 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ extern unsigned short _rand48_mult[3];
+ extern unsigned short _rand48_add;
+ 
+ unsigned short *
+ seed48(unsigned short xseed[3])
+ {
+ 	static unsigned short sseed[3];
+ 
+ 	sseed[0] = _rand48_seed[0];
+ 	sseed[1] = _rand48_seed[1];
+ 	sseed[2] = _rand48_seed[2];
+ 	_rand48_seed[0] = xseed[0];
+ 	_rand48_seed[1] = xseed[1];
+ 	_rand48_seed[2] = xseed[2];
+ 	_rand48_mult[0] = RAND48_MULT_0;
+ 	_rand48_mult[1] = RAND48_MULT_1;
+ 	_rand48_mult[2] = RAND48_MULT_2;
+ 	_rand48_add = RAND48_ADD;
+ 	return sseed;
+ }
*** /usr/src/lib/libc/stdlib/rand48.h.RAND48_ORIG	Mon Apr 19 11:30:12 1993
--- /usr/src/lib/libc/stdlib/rand48.h	Mon Apr 19 11:36:12 1993
***************
*** 0 ****
--- 1,30 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #ifndef _RAND48_H_
+ #define _RAND48_H_
+ 
+ #include <math.h>
+ #include <stdlib.h>
+ 
+ void		_dorand48 __P((unsigned short[3]));
+ 
+ #define	RAND48_SEED_0	(0x330e)
+ #define	RAND48_SEED_1	(0xabcd)
+ #define	RAND48_SEED_2	(0x1234)
+ #define	RAND48_MULT_0	(0xe66d)
+ #define	RAND48_MULT_1	(0xdeec)
+ #define	RAND48_MULT_2	(0x0005)
+ #define	RAND48_ADD	(0x000b)
+ 
+ #endif /* _RAND48_H_ */
*** /usr/src/lib/libc/stdlib/nrand48.c.RAND48_ORIG	Mon Apr 19 11:30:12 1993
--- /usr/src/lib/libc/stdlib/nrand48.c	Mon Apr 19 11:36:46 1993
***************
*** 0 ****
--- 1,21 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ long
+ nrand48(unsigned short xseed[3])
+ {
+ 	_dorand48(xseed);
+ 	return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1);
+ }
*** /usr/src/lib/libc/stdlib/mrand48.c.RAND48_ORIG	Mon Apr 19 11:30:12 1993
--- /usr/src/lib/libc/stdlib/mrand48.c	Mon Apr 19 11:36:44 1993
***************
*** 0 ****
--- 1,23 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ 
+ long
+ mrand48(void)
+ {
+ 	_dorand48(_rand48_seed);
+ 	return ((long) _rand48_seed[2] << 16) + (long) _rand48_seed[1];
+ }
*** /usr/src/lib/libc/stdlib/lrand48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/lrand48.c	Mon Apr 19 11:36:41 1993
***************
*** 0 ****
--- 1,23 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ 
+ long
+ lrand48(void)
+ {
+ 	_dorand48(_rand48_seed);
+ 	return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
+ }
*** /usr/src/lib/libc/stdlib/lcong48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/lcong48.c	Mon Apr 19 11:36:38 1993
***************
*** 0 ****
--- 1,30 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ extern unsigned short _rand48_mult[3];
+ extern unsigned short _rand48_add;
+ 
+ void
+ lcong48(unsigned short p[7])
+ {
+ 	_rand48_seed[0] = p[0];
+ 	_rand48_seed[1] = p[1];
+ 	_rand48_seed[2] = p[2];
+ 	_rand48_mult[0] = p[3];
+ 	_rand48_mult[1] = p[4];
+ 	_rand48_mult[2] = p[5];
+ 	_rand48_add = p[6];
+ }
*** /usr/src/lib/libc/stdlib/jrand48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/jrand48.c	Mon Apr 19 11:36:35 1993
***************
*** 0 ****
--- 1,21 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ long
+ jrand48(unsigned short xseed[3])
+ {
+ 	_dorand48(xseed);
+ 	return ((long) xseed[2] << 16) + (long) xseed[1];
+ }
*** /usr/src/lib/libc/stdlib/erand48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/erand48.c	Mon Apr 19 11:36:31 1993
***************
*** 0 ****
--- 1,23 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ double
+ erand48(unsigned short xseed[3])
+ {
+ 	_dorand48(xseed);
+ 	return ldexp((double) xseed[0], -48) +
+ 	       ldexp((double) xseed[1], -32) +
+ 	       ldexp((double) xseed[2], -16);
+ }
*** /usr/src/lib/libc/stdlib/drand48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/drand48.c	Mon Apr 19 11:36:26 1993
***************
*** 0 ****
--- 1,22 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ extern unsigned short _rand48_seed[3];
+ 
+ double
+ drand48(void)
+ {
+ 	return erand48(_rand48_seed);
+ }
*** /usr/src/lib/libc/stdlib/_rand48.c.RAND48_ORIG	Mon Apr 19 11:30:11 1993
--- /usr/src/lib/libc/stdlib/_rand48.c	Mon Apr 19 11:36:20 1993
***************
*** 0 ****
--- 1,46 ----
+ /*
+  * Copyright (c) 1993 Martin Birgmeier
+  * All rights reserved.
+  *
+  * You may redistribute unmodified or modified versions of this source
+  * code provided that the above copyright notice and this and the
+  * following conditions are retained.
+  *
+  * This software is provided ``as is'', and comes with no warranties
+  * of any kind. I shall in no event be liable for anything that happens
+  * to anyone/anything when using this software.
+  */
+ 
+ #include "rand48.h"
+ 
+ unsigned short _rand48_seed[3] = {
+ 	RAND48_SEED_0,
+ 	RAND48_SEED_1,
+ 	RAND48_SEED_2
+ };
+ unsigned short _rand48_mult[3] = {
+ 	RAND48_MULT_0,
+ 	RAND48_MULT_1,
+ 	RAND48_MULT_2
+ };
+ unsigned short _rand48_add = RAND48_ADD;
+ 
+ void
+ _dorand48(unsigned short xseed[3])
+ {
+ 	unsigned long accu;
+ 	unsigned short temp[2];
+ 
+ 	accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
+ 	 (unsigned long) _rand48_add;
+ 	temp[0] = (unsigned short) accu;	/* lower 16 bits */
+ 	accu >>= sizeof(unsigned short) * 8;
+ 	accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
+ 	 (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
+ 	temp[1] = (unsigned short) accu;	/* middle 16 bits */
+ 	accu >>= sizeof(unsigned short) * 8;
+ 	accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
+ 	xseed[0] = temp[0];
+ 	xseed[1] = temp[1];
+ 	xseed[2] = (unsigned short) accu;
+ }
*** /usr/src/include/stdlib.h.RAND48_ORIG	Mon Mar 22 15:40:30 1993
--- /usr/src/include/stdlib.h	Mon Apr 19 11:33:32 1993
***************
*** 95,100 ****
--- 95,111 ----
  int	 mbtowc __P((wchar_t *, const char *, size_t));
  size_t	 wcstombs __P((char *, const wchar_t *, size_t));
  
+ /* don't ask me where to put these -- MB XXX */
+ double		drand48	__P((void));
+ double		erand48	__P((unsigned short[3]));
+ long		lrand48	__P((void));
+ long		nrand48	__P((unsigned short[3]));
+ long		mrand48	__P((void));
+ long		jrand48	__P((unsigned short[3]));
+ void		srand48	__P((long));
+ unsigned short *seed48	__P((unsigned short[3]));
+ void		lcong48	__P((unsigned short[7]));
+ 
  #ifndef _ANSI_SOURCE
  void	 cfree __P((void *));
  int	 putenv __P((const char *));
*** /usr/include/stdlib.h.RAND48_ORIG	Mon Mar 22 15:40:30 1993
--- /usr/include/stdlib.h	Mon Apr 19 11:34:13 1993
***************
*** 95,100 ****
--- 95,111 ----
  int	 mbtowc __P((wchar_t *, const char *, size_t));
  size_t	 wcstombs __P((char *, const wchar_t *, size_t));
  
+ /* don't ask me where to put these -- MB XXX */
+ double		drand48	__P((void));
+ double		erand48	__P((unsigned short[3]));
+ long		lrand48	__P((void));
+ long		nrand48	__P((unsigned short[3]));
+ long		mrand48	__P((void));
+ long		jrand48	__P((unsigned short[3]));
+ void		srand48	__P((long));
+ unsigned short *seed48	__P((unsigned short[3]));
+ void		lcong48	__P((unsigned short[7]));
+ 
  #ifndef _ANSI_SOURCE
  void	 cfree __P((void *));
  int	 putenv __P((const char *));
============================== cut here ==============================

It might not patch w/o manual changes since these patches are for an
old version of 386bsd, but the code itself should be o.k. - I tested
it against a sun's output.

Cheers,

Martin
-- 
Martin Birgmeier
Technical University of Vienna                      mbirgmei@email.tuwien.ac.at