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

Alex Vandiver
October 7, 2003 15:42
Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5
Message ID:
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)'

perldoc perlvar says:

       $#      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 "", 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. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About