Path: utzoo!utgpu!cunews!cognos!alanm From: alanm@cognos.UUCP (Alan Myrvold) Newsgroups: comp.lang.perl Subject: Re: 3.041? (Because str.c formats to 20 digits) Message-ID: <9060@cognos.UUCP> Date: 19 Nov 90 16:52:21 GMT References: <1990Nov16.150010.7185@squirrel.mh.nl> Reply-To: alanm@cognos.UUCP (Alan Myrvold) Distribution: comp Organization: Cognos Inc., Ottawa, Canada Lines: 42 In article <1990Nov16.150010.7185@squirrel.mh.nl> Johan Vromans writes: >On DECsystem/Ultrix 4.0, perl 3.0 pl 41: > > 0+$] returns 3.0409999999999999 ... This nastiness is due to the discrepancy between : - the precision with which floating point numbers are converted to strings in perl's str.c (20 digits) and - the precision with which floating point numbers are stored on the system (usually ~15.9 decimal digits) The nastiness could be removed by changing str.c thusly : 183c183 < gcvt(str->str_u.str_nval,20,s); --- > gcvt(str->str_u.str_nval,15,s); 190c190 < (void)sprintf(s,"%.20g",str->str_u.str_nval); --- > (void)sprintf(s,"%.15g",str->str_u.str_nval); 16 digits would probably work for most constants, but it would be nice if print 49*(1/49),"\n"; displayed 1, and (on my system) this requires 15, not 16 digits to sprintf. Why the choice of 20 digits??? I dunno. 15 or 16 would make most sense for most floating point implementations. - Alan --- Alan Myrvold 3755 Riverside Dr. uunet!mitel!cunews!cognos!alanm Cognos Incorporated P.O. Box 9707 alanm@cognos.uucp (613) 738-1440 x5530 Ottawa, Ontario CANADA K1G 3Z4