Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

erand48 in mathfunc.c

  I've finally had time to look into a problem under Cygwin concerning
the mathfunc module and rand48().  Up until now, these never worked under
Cygwin.  erand48() would always return "0.0" for the value, no matter
what seedbufptr contained, and thus Test/V03mathfunc.ztst would always
  It seems that some implementations of rand48() need the seed to be
initialized (ie: use seed48(s) before erand48(s)).  Or at least, the
implementation in newlib does.  In anycase, calling seed48(s) solves the
problem and allows erand48() to return real values.  I don't see the harm
in always calling it for seed initialization, so I've not ifdef'ed it.
  It would be interesting to know if other platforms either need this
initializion as well, or produce incorrect results if used.
  In anycase, see patch.  This is against 4.3.2.  I've not checked CVS

*** 4.3.2/zsh-4.3.2/Src/Modules/mathfunc.c	Tue Nov  1 02:20:24 2005
--- 4.3.2d/zsh-4.3.2/Src/Modules/mathfunc.c	Wed Aug  2 09:53:40 2006
*** 534,539 ****
--- 534,541 ----
  		seedbufptr[0] = (unsigned short)rand();
  		seedbufptr[1] = (unsigned short)rand();
  		seedbufptr[2] = (unsigned short)rand();
+		/* some implementations of rand48 need initialization */
+		seed48(seedbufptr);
  	    ret.type = MN_FLOAT;
  	    ret.u.d = erand48(seedbufptr);

Peter A. Castro <doctor@xxxxxxxxxxxx> or <Peter.Castro@xxxxxxxxxx>
	"Cats are just autistic Dogs" -- Dr. Tony Attwood

Messages sorted by: Reverse Date, Date, Thread, Author