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

Thread Previous | Thread Next
From:
Tels
Date:
October 7, 2003 14:40
Subject:
Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5
Message ID:
200310072341.47898@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

On Tuesday 07 October 2003 20:42, you wrote:
> On Tue, Oct 07, 2003 at 08:12:13PM +0200, Tels <perl_dummy@bloodgate.com> 
wrote:
> > Oh, something fishy is going on:
> >
> >       print $x->[0] ** (1 / $n->[0]), "\n";
> >       $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
> >       print $x->[0],"\n";
> >
> > This produces for $x == [ 81 **3 ] and $n == [3] the following output:
> >
> > 	81
> > 	80
> >
> > Huh?!? This is with Perl v5.8.0...
>
> $ perl -we'printf "%.16g\n", (81**3)**(1/3)'
> 80.99999999999999

But why does 

	perl -le "print +(81**3)**(1/3)"

print 81 and not 80.99999999999999? perldoc print only says that it will print 
"a string or list of strings" but doesn't mention how print creates the 
strings. I guess it uses sprintf ("%.0f") or something internally when it 
sees a scalar containing a float, but I couldn't find the place where is 
documented how print converts floats to a string. (I am not saying that it 
isn't in the doc - I just don't know where to look for it. Where is 
perlgoogle when you need it...) At least the print surprised me. But it is 
not hard to suprise simpletons like me :)

Also interesting to note is:

	te@null:~> perl -Mbignum -le 'print +(81 ** 3) ** (1/3)'
	80.99999999999999999999999999999999999996
	te@null:~> perl -Mbignum=a,50 -le 'print +(81 ** 3) ** (1/3)'
	81.000000000000000000000000000000000000000000000002

Bevor I blame Perl's math returning wonky results, I should check my own
code :-)

Thank you again for your time and bearing with me,

Tels

- -- 
 Signed on Tue Oct  7 23:31:35 2003 with key 0x93B84C15.
 Visit my photo gallery at http://bloodgate.com/photos/
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Where shall I put you? Under H, like Hot, Sexy Mama?"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP4MzGncLPEOTuEwVAQGUtgf8CaT4r2bbqVPvgZHJXCNXOLss9O2VoQXf
QdDZvA7KQDLkcIzsjdaQcGUXteuCwTqB7kScEUrd877RUpm0rZBCdP67ys5Y3j0s
QW4Pz1oB/961bjj4htIgIK6+LHm9L2AMeXm73CxiwYyBwd98iEvpBjEqLBAdJhas
IvSMXb9wg66cnXGvDx8fKbgofIi34eTMvn4ZQYMQu3ohxO15HdTl9fOXerSv3hFo
sH5l9XwmTL4wYfKvnqxjwxwW1hhaio02qpWrAf7ubliCZBlZVgnTa+fN4LrISP6d
x5KtrOliiPiiTUdLH6kvN4UVOyNwnidohmf6Wlg8qsjYicfxfq9ipg==
=gFmb
-----END PGP SIGNATURE-----


Thread Previous | Thread Next


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