mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Fixing IntegerOverflow on Composition. Updated tests as well.
This commit is contained in:
parent
ff73f26132
commit
c3f051ee8b
@ -57,7 +57,7 @@ module.exports = function (math) {
|
||||
if (k.gt(n)) {
|
||||
throw new TypeError('k must be less than n in function composition');
|
||||
}
|
||||
return math.combinations(n-1,k-1);
|
||||
return math.combinations(n.minus(1), k.minus(1));
|
||||
} else {
|
||||
throw new TypeError('Integer values are expected in composition')
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ describe('composition', function() {
|
||||
it('should calculate the composition of n items taken k at a time with BigNumbers', function(){
|
||||
assert.equal(composition(math.bignumber(7), math.bignumber(5)), math.bignumber(15));
|
||||
assert.equal(composition(math.bignumber(70), math.bignumber(3)), math.bignumber(2346));
|
||||
assert.equal(composition(math.bignumber(56), math.bignumber(11)), math.bignumber(29248649430));
|
||||
});
|
||||
|
||||
it('should not work with non-integer and negative input', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user