mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

Unexpected behavior with math.add and math.multiply with >2 parameters

Open yaodub opened this issue 9 years ago • 4 comments

I'm seeing the following errors when I try to use math.add with more than 2 non-scalar parameters.

math.add(1, 2, 3);	//OK
math.add([1,1], [2,2], [3,3]); //TypeError: Too many arguments in function add (expected: 2, actual: 3)
math.add(0, 0, [1,1], [2,2], [3,3]); //OK
math.multiply(2, 3, 4);	// OK
math.multiply([3,3], [3,3], [4,4]); // TypeError: Too many arguments in function add (expected: 2, actual: 3)
math.multiply(1, 1, [2,2], [3,3], [4,4]); // OK

The problem seems that adding three Arrays triggers the "Array, Array" filter whose handler only accepts two parameters.

By adding scalar values in front, I get around the "Array, Array" filter to the "any, any, ...any" filter which allows for multiple parameters.

yaodub avatar Oct 10 '17 07:10 yaodub

Thanks for reporting, this should indeed just work.

josdejong avatar Oct 10 '17 18:10 josdejong

I'd like to work on this 😃

iamnapo avatar Oct 16 '17 20:10 iamnapo

Thanks for your offer @iamnapo, that would be great!

josdejong avatar Oct 16 '17 20:10 josdejong

This should be fixed in v3.16.5, thanks again @iamnapo for the help in tracing down the issue

josdejong avatar Oct 18 '17 18:10 josdejong