I'm guessing I'm doing something wrong because this just prints 2 choose 0 = 3. I'm pretty sure it should be 1.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());
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.my $n = 5; my $k = 2; my $x = Math::BigInt->new($n); my $z = $x->bnok($k); printf("$n choose $k = %d\n", $z);
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |