Re: bignum incompatible with looks_like_number() ???




"C B" <cb0@xxxxxxx> wrote in message news:cb0-1D13A6.09170627062007@xxxxxxxxxxxxxxxxxxxxx
..
..

my call looks like this:
$result = xirr(%HashOfDatesAndCashflows, precision => 0.000001);

This works fine, except that I'm getting answers that are a little off
numerically.

That would probably be because decimal fractions like 0.000001 cannot be represented with complete accuracy in the internal binary form that computers use (irrespective of the number of bits of precision that have been allocated).


So, in my main .pl file, I added the line:
use bignum;

Which resulted in an error message:
ERROR: precision is not a valid number at /Users/cb/main.pl line 189

After digging around, I discovered that Finance::Math::IRR calls
looks_like_number($x) where $x is set to the value of the precision hash
key.

Sure enough, the debugger reveals that I'm calling xirr with:

'precision' => bless( {
'_m' => [1],
'_es' => '-',
'_e' => [6],
'sign' => '+'
}, 'Math::BigFloat' )

which SHOULD pass the looks_like_number test, but it doesn't.

No - it's a Math::BigFloat object, which looks nothing like a number to (both me and) Scalar::Util::looks_like_number().

I guess the basic issue is that Math::Finance::IRR is not built to handle Math::BigFloat objects.

Cheers,
Rob

.



Relevant Pages

  • Re: Floating-point arithmetic in CL
    ... |> I would conjecture based on those two runs the number ... |> of exactly representable decimal fractions of n digits ... |> is (probably regardless of FP precision) ... The n digit decimal fractions are all the numbers of the form x/10^n ...
    (comp.lang.lisp)
  • Re: [PHP] Unexpected result in floor function
    ... This has to do with the floating point precision. ... It is quite usual that simple decimal fractions like 0.1 or 0.7 cannot be ... PHP version is 4.2.2. ...
    (php.general)
  • Re: Problems adding floats
    ... >> The problem is actually that you don't understand how floating point ... > Precision is not the issue; ... > conforming to expectations about decimal fractions and, more importantly, ... The rounding rules for float and double are stringently defined, ...
    (comp.lang.java.programmer)