shao.lo has asked for the wisdom of the Perl Monks concerning the following question:
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!***
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BigInt bug?
by davido (Cardinal) on Mar 07, 2012 at 07:05 UTC | |
|
Re: BigInt bug?
by tobyink (Canon) on Mar 07, 2012 at 06:46 UTC | |
by bitingduck (Deacon) on Mar 07, 2012 at 07:08 UTC | |
by lutok (Scribe) on Mar 07, 2012 at 11:06 UTC |