Re: Ask for recommended module for precise number
- From: "Tom" <chi.lun@xxxxxxxxx>
- Date: 24 Jan 2006 19:55:14 -0800
Hi Sisyphus,
Thanks a lots for your pointers to those useful library.
I think I did not describe my question well. In fact, I am getting
trouble into some VERY SMALL number which are close to zero. Consider
two number: "a" is 2^(-100) and "b" is 2^(-99). Then, "a/b" is 0.1.
It seems that BigFloat does not work for very small number as follows:
=============================================================
use Math::BigFloat;
use Carp;
my $x = new Math::BigFloat(0.1);
foreach my $i (0..100) {
confess ("It become zero at $i-th iteration") if ($x == 0);
$x = $x * $x;
printf "$i: %.5f\n", $x;
}
=============================================================
The $x in the above program become "0.0" if using original PERL
operations but become "1.0" (wrong number) if using Math::BigFloat.
As I am dealing with values of joint probabilities density, some values
are very very small. Currently I use log() to handle those problems but
it will introduce some errors if I need to do operations (e.g.,
addition) in the real space.
I have a try in GMP after reading your post, but it still convert to
"0.0" after a 10 times of mulitplication of "0.1".
Tom
Sisyphus wrote:
> I think " multiplications and divisions of very small and big numbers"
> implies "multiple precision arithmetic" - and there are a number of modules
> that handle multiple precision arithmetic. These include the Math::Big*
> modules (as already mentioned), Math::GMP, Math::Pari and Math::MPFR (to
> name a few more).
>
> However, I don't think that any of those modules performs multiple precision
> arithmetic (or, in your terms,"multiplications and divisions of very small
> and big numbers") by automatically converting "the number into log space"
> (or exp space, ftm).
>
> Seems to me that log() and exp() suffer from not being able to precisely
> represent many numbers.
>
> For example, the modules mentioned above can all represent *exactly* the
> value
> ''12345678902345678901234567890234567890234567811111190555555555555555555555
> 5555555555552345678901234567890234567890234567890234567890123456789023456789
> 0"
>
> How do you represent *exactly* that value by using log() and/or exp() ?
>
> Cheers,
> Rob
.
- Follow-Ups:
- Re: Ask for recommended module for precise number
- From: harryfmudd [AT] comcast [DOT] net
- Re: Ask for recommended module for precise number
- References:
- Ask for recommended module for precise number
- From: Tom
- Re: Ask for recommended module for precise number
- From: Sisyphus
- Ask for recommended module for precise number
- Prev by Date: LWP::UserAgent and HTTP_ACCEPT
- Next by Date: Re: Ask for recommended module for precise number
- Previous by thread: Re: Ask for recommended module for precise number
- Next by thread: Re: Ask for recommended module for precise number
- Index(es):