fkleon / math-expressions

A library for parsing and evaluating mathematical expressions, supporting real numbers, vectors, and basic interval arithmetic.
https://pub.dev/packages/math_expressions
MIT License
100 stars 34 forks source link

Using degrees for sin(),cos() and tan() #33

Open AmirHosein-Gharaati opened 4 years ago

AmirHosein-Gharaati commented 4 years ago

Is it possible to use degrees for sin,cos and tan ?

sin(90) = 1

I figured out we can just use radian...

fkleon commented 4 years ago

Hi

Correct, as you figured out, it's currently only possible to use radians on all trigonometric functions. I'll update the documentation for the next version to state this explicitly.

Hence you'd have to do the conversion from degree to radians in your application.

While input in degrees could be supported directly in this library (either by introducing a specific degree notation that the parser understands, or a second set of function definitions), I'm not sure there is much value since the conversions are pretty trivial.

AmirHosein-Gharaati commented 4 years ago

How can I change the parser, to use degrees entirely, instead of radian?

fkleon commented 4 years ago

Three options:

I think the first option is most flexible and could be toggled via a configuration option for the parser.

danger-ahead commented 2 years ago

I think the first option is most flexible and could be toggled via a configuration option for the parser.

Went through the codebase. Can you explain in detail how can I achieve this?

pyzworld commented 1 month ago

javascript popular math.js I find this expression very useful.

js code: math.evaluate('sin(45 deg) ^ 2') // 0.5