Xref: utzoo comp.sys.att:10542 unix-pc.bugs:150 Path: utzoo!utgpu!watserv1!watmath!uunet!wuarchive!julius.cs.uiuc.edu!apple!portal!cup.portal.com!thad From: thad@cup.portal.com (Thad P Floryan) Newsgroups: comp.sys.att,unix-pc.bugs Subject: Re: problem with using double and drand48 Message-ID: <34597@cup.portal.com> Date: 6 Oct 90 21:16:02 GMT References: <279@geocub.greco-prog.fr> Organization: The Portal System (TM) Lines: 48 lath@geocub.greco-prog.fr (Laurent Lathieyre) in <279@geocub.greco-prog.fr> writes: here a piece of C code which provides some strange results : double d; printf("%f\n",drand(48)); d=drand48(); printf("%f\n",d); output: 0.899854 1071863078.000000 according to the manual section 3, drand48() is supposed to return a double type value in [0.0,1.0]... Since you have the manual (or at least section 3), look at ``INTRO(3)'' which mentions you should ``#include '' in which is contained a declaration for "drand48()" as its proper double type (at least on most systems; on some, the assertion for drand48() is missing from math.h). Barring that, using an ANSI-compliant C compiler with forced prototypes will cause drand48() to be properly declared. Also, the lint library /usr/lib/llib-lc has "double drand48(){return (0.0);}" Barring the use or presence of any of the above on your system, if you change your program to: double d, drand48(); printf("%f\n", drand48()); d=drand48(); printf("%f\n", d); you'll find the expected results displayed. BTW, there is NO 'drand(48)' as in your posted example. As a general note, when you have the manual(s) and you see a function's synopsis per: ``datatype functionname()'' that means that you must explicitly declare the functionname as "datatype" if you choose not to use the appropriate *.h file or if the function is not so defined in the *.h file. Thad Floryan [ thad@cup.portal.com (OR) ..!sun!portal!cup.portal.com!thad ]