Adriano Ferreira wrote:
But the multiplication operator (*) is smarter and does an upgrade
from integer to floating point when needed, (possibly) increasing the
range of the correct results.

Adriano.


What JeeBee has stumbled across is a field of study called Numerical Analysis. For a brief introduction see http://en.wikipedia.org/wiki/Numerical_analysis

You are correct in that the multiplication operator automatically converts from integer to float for large values of $p but JeeBee needs an integer algorithm. For example, he uses ($p-1) % 3, which is only defined for non-negative integers. The problem is for large values of $p, $p == $p - 1. This is because floats only store a fixed number of digits. For example, if it stores 3 digits and $p = 1_000_000, then $p-1 is 1.000e6 - 1 or 1.000e6. The one's column has dropped off the bottom; it is too small to be recorded in the float.

I recommend that JeeBee takes his algorithm to a mailing list on Numerical Analysis. They will have a lot more experience with the foibles of computers doing simple arithmetic.


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to