Option to choose default angle units
See original GitHub issueThanks 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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Application.DefaultAngleUnits property (Visio) | Microsoft Learn
The DefaultAngleUnits property corresponds to the value shown in the Angle box under Display on the Advanced tab of the Visio Options dialog...
Read more >Allow the user to set the default units for curves...
I always enter the Delta Angle in Degrees Minutes Seconds (dms) units so I am constantly having to change this setting for every...
Read more >About direction measuring systems and units—Help
The editing tools use decimal degrees as their default units of angular measure. You can choose from the following direction measurement units: decimal...
Read more >To Specify the Drawing Units | AutoCAD Architecture 2021
Click Utilities Drawing Setup. Click the Units tab. Specifying default units options for the current drawing. Under Drawing Units, select the ...
Read more >Radians Default Unit for Angle Measurement with Arc Length ...
https://www.youtube.com/@MathematicsTutor Radian Measurements: ...
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
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
(π/180)*cosine
. So you have to be very careful to change the derivative operation as well, for all affected functions. And what about polar coordinates? If angles are measured in degrees, all of the polar coordinate functions have to change their behavior as well. And since the exponential function for complex numbers is closely connected with trigonometric functions (exp(ia) = cos a + i sin a), the exponential function has to change its behavior too (euler’s formula becomese^(180*i) + 1 = 0
, for example). And that means that the power and log functions have to change also, so that they are consistent with exp. In fact, the majority of all mathematical operations on complex numbers have to change. I am not actually 100% certain there is a fully consistent set of mathematical operations on real and complex numbers in which one “measures angles in degrees.” I think it can be done, but there are many many details that would need tracking down.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
cos(30 deg)
. Now that unicode is essentially universal, would it help to also supportcos(30°)
? That would be quite easy and I would be glad to do it if it would be helpful.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.