Re: bignum incompatible with looks_like_number() ???




"C B" <cb0@xxxxxxx> wrote in message news:cb0-AF4183.10300930062007@xxxxxxxxxxxxxxxxxxxxx
..
..

Please give some examples of how you imagine bignum is SUPPOSED to be
used.

Please include $x = 2**512+0.0 in your examples.


I don't find any problem with the above example - though I believe there might have been problems in the past when you tried to do that. If that was a problem at one stage, it now seems to have been fixed - if you add a fraction to Math::BigInt object that was created by bignum, then the Math::BigInt object is first converted to a Math::BigFloat object, so that the addition can take place. (Of course, if you're adding 0.0, bignum now recognises that the Math::BigInt object can stay as a Math::BigInt object, and 0 is simply added ... again I've a notion that bignum wasn't always that clever in the past.)

It has just occurred to me that in concentrating on this 'looks_like_number' compatibility, I've overlooked the possibility that if you remove the looks_like_number() stipulations from the code in Finance::Math::IRR, then it may well do exactly what you want anyway ... without the need to make any other amendments. Probably worth testing (if you haven't already).

Consider Foo.pm:
-------------------------------
package Foo;
use Scalar::Util qw(looks_like_number);

sub my_foo {
my $out = $_[0] + 1;
return $out;
}

sub my_bar {
die "Not a number" unless(looks_like_number($_[0]));
my $out = $_[0] + 1;
return $out;
}

1;
-------------------------------

And try.pl:
-------------------------------
use strict;
use warnings;
use bignum;
use Foo;

my $x = (2 ** 512) + 0.0;
print ref($x), "\n";
print $x, "\n";
print Foo::my_foo(2 ** 512), "\n";
print Foo::my_bar(2 ** 512), "\n";
-------------------------------

Foo::my_bar dies because the argument did not look like a number .... but if you remove that stipulation then there's no problem at all - Foo::my_bar() is quite capable of dealing with bignum objects despite the 'looks_like_number' red herring.

So the question is:
When Finance::Math::IRR stipulates that the argument has to look like a number, is that, too a red herring ? Or does Finance::Math::IRR have sound reasons for stipulating that the argument must look like a number ?

(Ok ... that might be 2 questions :-)

Btw, when I run the above script (try.pl) I get:
----------------------------------
Math::BigInt
13407807929942597099574024998205846127479365820592393377723561443721764030073546
976801874298166903427690031858186486050853753882811946569946433649006084096
13407807929942597099574024998205846127479365820592393377723561443721764030073546
976801874298166903427690031858186486050853753882811946569946433649006084097
Not a number at Foo.pm line 10.
----------------------------------

Cheers,
Rob

.