[comp.lang.perl] 3.041?

jv@mh.nl (Johan Vromans) (11/16/90)

On DECsystem/Ultrix 4.0, perl 3.0 pl 41:

    0+$] returns 3.0409999999999999 ...

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

urlichs@smurf.sub.org (Matthias Urlichs) (11/19/90)

In comp.lang.perl, article <1990Nov16.150010.7185@squirrel.mh.nl>,
  Johan Vromans <jv@mh.nl> writes:
< On DECsystem/Ultrix 4.0, perl 3.0 pl 41:
< 
<     0+$] returns 3.0409999999999999 ...
< 
Same here (A/UX 2.0).

-- 
Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330)   \o)/

alanm@cognos.UUCP (Alan Myrvold) (11/20/90)

In article <1990Nov16.150010.7185@squirrel.mh.nl> Johan Vromans <jv@mh.nl> 
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       

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/20/90)

In article <&$7fg2.0&2@smurf.sub.org> urlichs@smurf.sub.org (Matthias Urlichs) writes:
: In comp.lang.perl, article <1990Nov16.150010.7185@squirrel.mh.nl>,
:   Johan Vromans <jv@mh.nl> writes:
: < On DECsystem/Ultrix 4.0, perl 3.0 pl 41:
: < 
: <     0+$] returns 3.0409999999999999 ...
: < 
: Same here (A/UX 2.0).

This shouldn't surprise you, considering that 1/1000 is not exactly
representable in base two.  I thought about this when implementing it,
and decided it was okay because $] >= 3.041 is still true.  (This is
because 3.041 is also represented internally as 3.0409999999...)

If you want to print $] numerically, say printf("%5.3f",$]).

Larry

tneff@bfmny0.BFM.COM (Tom Neff) (11/20/90)

Yeah but roundoff error in the VERSION NUMBER is bogus.  Can't you force
$] to have the string attribute and stay exactly "3.041"?

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/25/90)

In article <16047@bfmny0.BFM.COM> tneff@bfmny0.BFM.COM (Tom Neff) writes:
: Yeah but roundoff error in the VERSION NUMBER is bogus.  Can't you force
: $] to have the string attribute and stay exactly "3.041"?

Not and stay compatible with what $] currently means in a string context.

Larry

jv@mh.nl (Johan Vromans) (11/25/90)

In article <10523@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
   In article <16047@bfmny0.BFM.COM> tneff@bfmny0.BFM.COM (Tom Neff) writes:
   : Yeah but roundoff error in the VERSION NUMBER is bogus.  Can't you force
   : $] to have the string attribute and stay exactly "3.041"?

   Not and stay compatible with what $] currently means in a string context.

I, who started this thread, can live with $version = sprintf("%.3f",$]). 

On the other hand, one could consider an array @] that contains the
two integer values ($][$[] == 3 and $][1+$[] == 41), but I doubt if it
is worth the trouble.

	Johan

-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------