From: Robert Dober Date: 2006-09-02T06:49:03+09:00 Subject: Re: Happy Numbers (#93) ------=_Part_91491_15144879.1157147317160 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/1/06, Paul Lutus wrote: > > James Edward Gray II wrote: > > / ... > > > #!/usr/bin/env ruby -w > > > > > > n^p =3D e^(log(n)*p) > > where "e" =3D base of natural logarithms, "log" =3D base e logarithm. > > So it seems there's at least one multiply no matter what one does. So, fo= r > n^2, it's hard to see how n * n could be slower, for either integers or > floats. I was quite surprised at first too, however, the interpreter knows how to treat n ** 2, it does not in a sense know how to treat n * n, it treats it as n * m, replace n with literals in the above tests e.g. 4_710_815 * 4_710_815 and 4_710_815 ** 2 and run the benchmark again, you will be much happier with the result ;) Cheers But ... in this case, it is. > > -- > Paul Lutus > http://www.arachnoid.com > > --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_91491_15144879.1157147317160--