develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5

From:
Alex Vandiver
Date:
October 7, 2003 15:42
Subject:
Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5
Message ID:
1065566465.16446.5.camel@supox
On Tue, 2003-10-07 at 17:41, Tels wrote:
> But why does 
> 
> 	perl -le "print +(81**3)**(1/3)"
> 
> print 81 and not 80.99999999999999?

$ perl -le '$#="%.16g"; print +(81**3)**(1/3)'
80.99999999999999

perldoc perlvar says:

       $OFMT
       $#      The output format for printed numbers.  This vari-
               able is a half-hearted attempt to emulate awk's
               OFMT variable.  There are times, however, when awk
               and Perl have differing notions of what counts as
               numeric.  The initial value is "%.ng", where n is
               the value of the macro DBL_DIG from your system's
               float.h.  This is different from awk's default
               OFMT setting of "%.6g", so you need to set $#
               explicitly to get awk's value.  (Mnemonic: # is
               the number sign.)

               Use of $# is deprecated.

 - Alex V.

-- 
Networking -- only one letter away from not working.




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About