Decimal places and huge fractions.

E

Eoin Mcloughlin

I have a perl script for calculating sequences that use numbers like
1/5908979186 however, I need to get more accuracy than the usual 15
decimal places, is this a limitation of 32-bit machines or is it
possible to use more decimal places?
Has something already been written to do this? If not, what would one
have to do enable it?
 
C

Chris Crandell

Eoin Mcloughlin said:
I have a perl script for calculating sequences that use numbers like
1/5908979186 however, I need to get more accuracy than the usual 15
decimal places, is this a limitation of 32-bit machines or is it
possible to use more decimal places?
Has something already been written to do this? If not, what would one
have to do enable it?

If you need more precision, then 32 or 64 or .... becomes an issue.
One possible solution is to do the arithmetic in string form which bypasses
the machine limitation. It requires special functions for doing the string
arithmetic but
I have to guess it's been done ... somewhere. (ie once upon a time for a
class we
did at least the easier add, subtract, multiply ....maybe divide)
There is a time cost, of course.

Regards....
 
J

Jim Gibson

Eoin Mcloughlin said:
I have a perl script for calculating sequences that use numbers like
1/5908979186 however, I need to get more accuracy than the usual 15
decimal places, is this a limitation of 32-bit machines or is it
possible to use more decimal places?
Has something already been written to do this? If not, what would one
have to do enable it?

Check out Math::BigInt (I have not used it). Try

perldoc Math::BigInt

for info.

FYI: This newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
J

Jürgen Exner

Eoin said:
I have a perl script for calculating sequences that use numbers like
1/5908979186 however, I need to get more accuracy than the usual 15
decimal places,

More accuracy? Are you doing some astronomic calculations or iterative
metorological forcasts or nuclear physics or something like that?
Ususally 10 valid digits (as in your example) are more than any measuring
equipment can possibly provide.

However, if you really have a need for higher accuracy then you may want to
invest some time in learning about computer numerics and how those work.
There is much more to it then just using a module with a higher number of
digits and if you are not aware of the potential pitfalls then you are
likely to be bitten sooner or later.

jue
 
E

Eoin Mcloughlin

A bunch people wrote:

More accuracy? Are you doing some astronomic calculations or iterative
metorological forcasts or nuclear physics or something like that?
Well, not quite but there are sequences with unusual numbers in them...
Math::BigInt and Math::BigRat
Math::BigFloat worked just fine...

Thanks people... Great help. Everything is fine to 300-odd decimal
places, which will do for now...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top