use Math::BigInt; my $n = 2; my $k = 0; my $x = Math::BigInt->new($n); my $z = $x->bnok($k); printf("$n choose $k = %d\n", $z); printf("$n choose $k = %d\n", $z->as_int()); printf("$n choose $k = %s\n", $z->bstr()); printf("$n choose $k = %d\n", $z->numify());
I'm guessing I'm doing something wrong because this just prints 2 choose 0 = 3. I'm pretty sure it should be 1.
my $n = 5; my $k = 2; my $x = Math::BigInt->new($n); my $z = $x->bnok($k); printf("$n choose $k = %d\n", $z);
The above correctly prints 5 choose 2 = 10. So, what am I doing wrong? Or is bnok() broken?? BTW..I tried BigFloat too...with same result.
***
THANKS to everyone that responded. I was indeed using an older verion (1.89_01). I use Ubuntu and I guess Math::BigInt comes as part of some other package. When I installed it directly via 'apt-get install libmath-bigint-perl' I now get version (1.993) which does indeed get the 2 choose 0 correct.
***
Thanks again for the responses!

In reply to BigInt bug? by shao.lo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.