Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Very small numbers

by belg4mit (Prior)
on Feb 09, 2004 at 16:13 UTC ( [id://327652]=note: print w/replies, xml ) Need Help??


in reply to Very small numbers

One thing you might try (though this may also fail due to floating point errors) is multiplying your number by a few hundred before taking the log. Then subtracting from the result to account for the initial magnification.
log(a*b) = log a + log b log10 1000 = 3 log10 6 = 0.77815125 log10 6000 = 3.77815125 ...
UPDATE: Although this makes me think we ought to have a Math::SmallRat and SmallFloat. PDL or Math::FixedPrecision might also work.

UPDATE: Apparently Math::BigFloat is just a bit of a slight misnomer. It's not just for BIG numbers. The Big imples a large number of bits assigned to store the number.

--
I'm not belgian but I play one on TV.

Replies are listed 'Best First'.
Re: Very small numbers
by Abigail-II (Bishop) on Feb 09, 2004 at 16:21 UTC
    Well, if your number is small enough that Perl thinks the number is 0, multiplying it with 100, or whatever number you choose, will not do you any good:
    $ perl -wle 'print log (10**-4950)' -11397.7067720196325 $ perl -wle 'print log (10**-4951)' Can't take log of 0 at -e line 1. $ perl -wle 'print log (10**-4951 * 100)' Can't take log of 0 at -e line 1.

    Abigail

Re^2: Very small numbers
by etj (Deacon) on Jun 23, 2022 at 16:16 UTC
    PDL unfortunately cannot help with this, since it (currently) only works with C types, in this case probably a double-precision floating point number. However, the techniques discussed elsewhere in this thread to avoid underflow (especially scaling) will work great to overcome that.
Re: Re: Very small numbers
by Win (Novice) on Feb 09, 2004 at 16:43 UTC
    Maths::BigFloat is not available via ppm.
      The name is Math::BigFloat, and it is included with perl (though if you have an old version of perl, you may want to update it since there have been bugfixes).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://327652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found