zsh-workers
 help / color / mirror / code / Atom feed
* erand48 in mathfunc.c
@ 2006-08-04  2:26 Peter A. Castro
  0 siblings, 0 replies; only message in thread
From: Peter A. Castro @ 2006-08-04  2:26 UTC (permalink / raw)
  To: zsh-workers

Greetings,
   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
fail.
   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
lately.

*** 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@fruitbat.org> or <Peter.Castro@oracle.com>
 	"Cats are just autistic Dogs" -- Dr. Tony Attwood


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-08-04  2:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-04  2:26 erand48 in mathfunc.c Peter A. Castro

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).