Using mean with units throws error in evaluate function
See original GitHub issueUsing a calculation like this:
var calculation = "mean(5km,10km)";
math.evaluate(calculation);
results in the following error:
Cannot calculate mean, unexpected type of argument (type: Unit, value: {"mathjs":"Unit","value":5,"unit":"km","fixPrefix":false})
It is because of the units, because the line
var calculation = "mean(5,10)";
works perfectly fine.
I tested the same with functions like sum, max, min, median and mode and there it works fine with units. With mean, however it does not, which looks like a bug. Using mathjs 6.2.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
IFERROR function - Microsoft Support
You can use the IFERROR function to trap and handle errors in a formula. IFERROR returns a value you specify if a formula...
Read more >Mocha / Chai expect.to.throw not catching thrown errors
You have to pass a function to expect . Like this: expect(model.get.bind(model, 'z')).to.throw('Property does not exist in model schema.
Read more >Measurements and Error Analysis - WebAssign
This average is generally the best estimate of the "true" value (unless the data set is skewed by one or more outliers which...
Read more >Solved: Error This can happen when a measure formula refer...
The problem is that measures are calculated over the entire data set unless otherwise given a filter context. So the error message in...
Read more >Uncertainties and Error Propagation
Derivation: We will assume that the uncertainties are arranged so as to make z as far from its true value as possible. Average...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, @clintonc!
@Chris1234567899, if you mean
round(6.35 cm)
or something, that’s not supported because we don’t want the results of expressions to change based on what units they’re written in:It’s even more problematic when the argument to
round(...)
is an expression itself with various units, then there’s no telling which unit it will be expressed in when it is passed toround
.Edit: For example, what should
round(1 in + 1 cm)
return?I’d like to work on this (and related matters); I’ve got working code and tests, so I can make a PR later today.