Article View: comp.unix.programmer
Article #3549Re: Can erand48 really generate a 1.0?
From: Shing-Fat Fred Ma
Date: Fri, 07 Mar 2003 04:23
Date: Fri, 07 Mar 2003 04:23
51 lines
3083 bytes
3083 bytes
Andrew Gierth wrote: > The following message is a courtesy copy of an article > that has been posted to comp.unix.programmer as well. > > [bogus groups comp.gcc.help,comp.math.num-analysis dropped] > > >>>>> "Fred" == Fred Ma <fma@doe.carleton.ca> writes: > > Fred> Hello, I'm using gcc's erand48. On solaris8, the man page > Fred> header says SunOS5.8, while on cygwin, it says NEWLIB. Both > Fred> pages say that the range of random numbers is the closed range > Fred> [0.0,1.0]. However, "many people" have said on various web > Fred> pages that the values lie in the range [0.0,1.0) i.e. doesn't > Fred> include 1.0. > > The standards say [0.0,1.0) is the correct range. Hi, Andrew, Just wondering if you could clarify the standard you're referring to. Reason I ask is because I'm told that erand48 is not part of the C standard. That's why I'm not posting to the C newsgroup. > > > Fred> So I wonder if anyone knows for sure whether the random number > Fred> spans the closed range, or semiopen (latter case). I mean know > Fred> for sure, because suspicions abound (I have my own suspicions > Fred> that the semiopen range is correct because the integer > Fred> counterparts in this family of random generators always goes up > Fred> to +/-( 2**31 - 1 ), whereas I suspect the floating point > Fred> versions just normalize the integer version by 2**31. > > not quite. The '48' in the name of the function may give you a clue > here; all 48 bits of the generated value are used as the mantissa of > the floating-point result (after normalization). (This can't round up > to 1.0 with IEEE format, which has more than 48 bits of precision; the > lower order bits are left as 0.) > > -- > Andrew. > > comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/> -- Fred Ma, fma@doe.carleton.ca Carleton University, Dept. of Electronics 1125 Colonel By Drive, Ottawa, Ontario Canada, K1S 5B6
Technical Details
Message-ID:
<3E681EC6.5C3983A7@doe.carleton.ca>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!torn!cunews!not-for-mailReferences:
<3E67F733.B26801FD@doe.carleton.ca> <87n0k7sush.fsf@erlenstar.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,fb356e03a291e1e4 X-Google-Attributes: gid11318c,public X-Google-Thread: 107079,8ae001fa56b91764 X-Google-Attributes: gid107079,public X-Google-Thread: fc89c,772ea27ce7480c6b X-Google-Attributes: gidfc89c,public X-Google-ArrivalTime: 2003-03-06 20:30:20 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!torn!cunews!not-for-mail From: Shing-Fat Fred Ma <fma@doe.carleton.ca> Newsgroups: comp.unix.programmer,sci.math.num-analysis,gnu.gcc.help Subject: Re: Can erand48 really generate a 1.0? Date: 7 Mar 2003 04:23:35 GMT Organization: Carleton University, Ottawa, Canada Lines: 54 Message-ID: <3E681EC6.5C3983A7@doe.carleton.ca> References: <3E67F733.B26801FD@doe.carleton.ca> <87n0k7sush.fsf@erlenstar.demon.co.uk> NNTP-Posting-Host: malawi.doe.carleton.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.77 [en] (X11; U; SunOS 5.8 sun4u) X-Accept-Language: en To: Andrew Gierth <andrew@erlenstar.demon.co.uk>