Replies: 5 comments
-
In the expression parser you could do
The equivalent in plain javascript is: function radToDeg(x) {
return math.divide(math.multiply(x, math.unit('rad')), math.unit('deg'))
} Or something like: function radToDeg(x) {
return math.unit(x, 'rad').toNumeric('deg')
} |
Beta Was this translation helpful? Give feedback.
-
Okay, but we don't want a dedicated function for this? Such that you can simply call |
Beta Was this translation helpful? Give feedback.
-
Yeah, if there is need for it we can consider it. So far you're the first asking about it :). It's indeed quite a common util function for working with angles. The idea of using units instead of converting numbers yourself is that you can simply do |
Beta Was this translation helpful? Give feedback.
-
You are totally correct that unit issues made rockets crash in the past. But I would prefer to have a simple accesible function for that. I think as well that it is a common util function, which I normally use quiet often in the field of control engineering and digital signal processing. If it is okay I will create those two functions and submit a PR. |
Beta Was this translation helpful? Give feedback.
-
Yes I'm ok with that. I agree that its a very common/handy util function. |
Beta Was this translation helpful? Give feedback.
-
As a first contribution to the project, I thought I would implement
rad2deg
anddeg2rad
. However, then I found out mathjs has a unit module. But how does that exactly work? Let say I have a variablex
, which I know is in radians, did not explicitly specify it, but I want to convert it to degrees? How can I achieve this? Is there a oneliner? Something likef.unit.to('deg','rad')
? In addition, does the result also store the unit in the new variable? Because frankly I do not care about it and most likely it makes all operations after slower, because it takes the unit into account when doing calculations?Beta Was this translation helpful? Give feedback.
All reactions