Option to choose default angle units #2740
Replies: 15 comments
-
You can do |
Beta Was this translation helpful? Give feedback.
-
not really. It would be more convenient for me to use directly |
Beta Was this translation helpful? Give feedback.
-
It may be good indeed to reconsider adding support for config options deg//rad/grad. It's quite common for calculators, which is one of the cases where mathjs is often used. See also this topic where I explain my hesitation in this regard: #944 (comment)
|
Beta Was this translation helpful? Give feedback.
-
I couldn't understand why "it's so easy to make mistakes". When a user enters expression like "sin(34)" changing them like "sin(34 deg)" for every trigonometric function is hard because there might be nested trigonometric functions. It is also tiring for the eye. |
Beta Was this translation helpful? Give feedback.
-
I've made this mistake multiple times in my life doing some calculations with a calculator, and at some point thinking "whuut? there is something weird going on here", only to figure out that I was filling in values in degree whilst the calculator was set to rad or the other way around. It's a bit similar to implicit multiplication (like I do see the value of it though I'm not a fan of these kind of implicit things myself, I'm open to reconsider adding support for rad/deg/grad after all. |
Beta Was this translation helpful? Give feedback.
-
I wish this configuration support was ready. I am Working on a calculator plugin for a CBT system. Over here in Nigeria DEG is the default. I implemented my calculator with a simple evaluate(expression). Works like a charm except I can't set default angles. I think I need to understand that angles examples first. |
Beta Was this translation helpful? Give feedback.
-
@tobychidi I built a calculator https://github.com/canbax/hasap Here I make a topological sorting of math expressions and then change the angle units one by one https://github.com/canbax/hasap/blob/7d6a28aa1a757e6b536727b5fce2842e00a7f755/src/app/app.component.ts#L513 |
Beta Was this translation helpful? Give feedback.
-
TL;DR: The reason there is no "degree mode" in mathjs is that it is a very large amount of work, and it's not clear how to get everything consistent (or whether it's possible), and so the payoff has not been worth anyone's effort when it's pretty easy either to just write the units, define your own functions 'cosd' and 'sind' that take degrees, or use one of the other workarounds that have been posted in this issue. My full thoughts: I wanted to add that adding a configuration setting for "degree" input to trigonometric functions is not as straightforward as it might seem. In a wide-ranging math library, not only do you have to modify the behavior of the six basic trigonometric functions, but also their inverses. And since we have derivative, well, the derivative of the sine function of angles measured in degrees is not cosine, even if you mean cosine of angles in degrees, it's So you see, there are very good reasons why mathematics as a whole measures angles in radians, and so why a computer math package that tries to cover a broad range of topics also measures angles in radians. It is very much not just an arbitrary choice. In fact, I would say that mathjs goes farther than many general math packages in supporting degrees, by allowing expressions like |
Beta Was this translation helpful? Give feedback.
-
Thanks for your input Glen! On the one side I would love to make this configurable, on the other hand I want to stay away from it because of the complexities it involves. One idea could be to find a middle way: support configurable angle units for all the "basic" trigonometric functions (sin, cos, tan, asin, acos, atan, etc). And for other functions like the The current situation is also not 100% as I would want it, because it is not really symmetric. You can enter
I like that idea. On my keyboard the character |
Beta Was this translation helpful? Give feedback.
-
One more (wild?) idea: currently the mathjs repo offers two setups "full" and "plain number". I can imagine we would provide a new setup "calculator", which offers just basic arithmetic functions, implements this angle config option, and wraps the trigonometric functions to support the config option, like in the example https://mathjs.org/examples/browser/angle_configuration.html.html |
Beta Was this translation helpful? Give feedback.
-
Well the fact is that "rad" is precisely a unitless unit -- it has no dimension. So it should be that |
Beta Was this translation helpful? Give feedback.
-
I like this idea better than the guard one (it's easier to admit selectively than to weed out) especially if you're willing to have calculator mode not support complex numbers (so we don't have to worry about changing the behavior of |
Beta Was this translation helpful? Give feedback.
-
👍
Good point. Yeah so we could allow converting any number into a unit Deg, so |
Beta Was this translation helpful? Give feedback.
-
Scratch that, darn. What I said was mathematically reasonable, but it doesn't work in the presence of the unit system mathjs has: sin(tau/4) = sin((tau/4) rad) = sin(90 deg) = 1 and asin(1) = tau/4 and asin(1) = (tau/4) rad = 90 deg but 90 deg/secs = (tau/4 rad/secs) = 1/4 hertz whereas (tau/4) / secs = 1.57... hertz So the "pure number" tau/4 unfortuately does not work the same as the "angle" (tau/4) rad in all contexts :-( So the best we can do is is something like Incidentally, the conversion |
Beta Was this translation helpful? Give feedback.
-
wow 🤯 that makes sense. Well, yes, let's leave it up to the user to specify the unit |
Beta Was this translation helpful? Give feedback.
-
Thanks for this powerful library. I want to use
evaluate
function to compute math expressions.Certain operators like sin, cos use default unit radian. For example:
evaluate(sin(3.14/2))
gives 1. Can I change the default unit to the degree? e.g.evaluate(sin(90))
will give 1.I think there should be a config to set the default units used in calculations.
Beta Was this translation helpful? Give feedback.
All reactions