question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using mean with units throws error in evaluate function

See original GitHub issue

Using 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:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericman314commented, Oct 3, 2019

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:

equal(6.35 cm, 2.5 in) // true
equal(round(6.35 cm), round(2.5 in)) // false

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 to round.

Edit: For example, what should round(1 in + 1 cm) return?

1reaction
clintonccommented, Oct 2, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found