jimav has asked for the wisdom of the Perl Monks concerning the following question:

Is there something about log(0.5) which is a mathematical singularity?
use bugnum; say log(0.5);
Gives: Can't locate object method "_log" via package "Math::BigInt" at /home/jima/perl5/lib/perl5/Math/BigFloat.pm line 5737.

Any other value works, such as

say log(0.5000000000000000000000000000000000000000000001); say log(0.4999999999999999999999999999999999999999999999);
(which both print '-0.6931471805599453094172321214581765680755')

Replies are listed 'Best First'.
Re: log(0.5) with bignum blows up
by talexb (Chancellor) on Jan 04, 2024 at 02:59 UTC

    Hmm .. I suppose you want Math::BigNum and not the unknown bugnum module.

    And .. after that, this module does have log functions ..

    ... $x->blog(); # logarithm of $x to base e (Euler's number) $x->blog($base); # logarithm of $x to base $base (e.g., base 2) $x->bexp(); # calculate e ** $x where e is Euler's number $x->bilog2(); # log2($x) rounded down to nearest int $x->bilog10(); # log10($x) rounded down to nearest int $x->bclog2(); # log2($x) rounded up to nearest int $x->bclog10(); # log19($x) rounded up to nearest int ...
    The log functions are called blog.

    If I run this ..

    tab@music4:~/Pianoforte/Perlmonks 21:54:45 $ cat !$ cat 11156670.pl #!/usr/bin/perl use strict; use warnings; # use Math::BigNum; { print "Log of .5 is " . log(0.5) . "\n"; } tab@music4:~/Pianoforte/Perlmonks 21:54:51 $ ./11156670.pl Log of .5 is -0.693147180559945 tab@music4:~/Pianoforte/Perlmonks 21:54:57 $
    .. I get a good value. That presumably uses Perl's built in log function.

    I can strongly recommend a complete, self-contained example that shows the output .. this will help you solve things faster.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Re: log(0.5) with bignum blows up
by Anonymous Monk on Jan 04, 2024 at 08:21 UTC

    I've had the same error message, for a short while, but after upgrading (note previous versions):

    --> Working on bignum Fetching http://www.cpan.org/authors/id/P/PJ/PJACKLAM/bignum-0.67.tar. +gz ... OK Configuring bignum-0.67 ... OK ==> Found dependencies: Math::BigRat --> Working on Math::BigRat Fetching http://www.cpan.org/authors/id/P/PJ/PJACKLAM/Math-BigInt-2.00 +3001.tar.gz ... OK Configuring Math-BigInt-2.003001 ... OK Building and testing Math-BigInt-2.003001 ... OK Successfully installed Math-BigInt-2.003001 (upgraded from 0.2614) Building and testing bignum-0.67 ... OK Successfully installed bignum-0.67 (upgraded from 0.51) 2 distributions installed

    there is no error afterwards. The previous versions mentioned are not part of Perl standard distribution (no error with unpacked original Perl), but perhaps installed some time ago. Now I have erroneous versions overwritten and, honestly, no desire to dig/debug further.