this means HA expects radiant not angles, who the heck did this in the core? someone needs to make a Doku for the sin cos tan functions in HA, namely that they expect radiant instead of what every other calculator on this planet expects.
@nickrout your right, radiant, not angles. @avd706 the factor for radiant to angle is different than the one you quoted, where did you get that number from? (i had to first look it up too…)
that ones working correctly (near enough at least, so it does not matter any m ore, I aimed for 5 digit behind the decimal point on 80% then googled the factor and found it to be correct.
{% for x in range(0, 91, 10) -%}
{% set r = x * 2 * pi / 360 %} {# this would also work: {% set r = x * 0.017453293 %} #}
{% set y = tan(r) %}
{{ x }}° {{ y | round(5) }} {{ r | round(3) }}
{%- endfor %}
so after this short distraction, that took me half a day to figure out that it was not my code that was wrong, but HA to do something that is unexpected, I now lost my whole code and will start from scratch.
The conversion is 2pi / 360. And radians are the standard in pretty much all technical, physical and mathematical fields, they’re also the standard for trigonometric functions in pretty much every programming language, including Python. So using it in templating makes perfect sense.
too bad one could not declare 2 posts as solution, since the one from nickrout was right, but he did not give any explanation or hint, I have marked my own post with the explanation and the corrected code as the solution.
@HeyImAlex thanks for the clarification, I do see why it is the way it is.
I modified my code that is marked as the solution with your input to
{% set r = x * 2 * pi / 360 %}
I can honestly say, I haven’t ever used radiant in all my life. And any scientific calculator I used could be switched to rad, thats ture, but did never have rad out of the box as the input for sin cos or tan…
But since now I know how to treat HA, Ill wont make that error again.
shortened formulas wont help most folk understand the issue, as most folks would not have shortened formulas since they left school.
While I highly appreciate the correction, since I learn to better use English, a language that is not my native tongue, Tangens is Latin, and therefore always correct as its the origin. did not research for rad, though.
I do understand why it is the way it is in HA. And I even concur. On the contrary, Im pretty sure if you ask folks what to put behind the “tan” function (or any other of the triangle functions) or what rad is, most folk would give you a blank star as an answer and the rest would put an angel behind the tan function, as that is what most calculators they have worked with would expect. And you probably get 1-2% of folks who use it on a regular base and give the right answer to rad and ask if the tan function is on a calculator or a coding language / scientific use.
And I think one of the key success reasons of HA is, to be doable by most folk and mostly in GUI, and behave in a way even an below average person can handle the setup and operation. So in this instance, as we both agree, a good documentation of this scientific behavior of HA, where it clearly deviates from the behavior what most folks would expect, is required and I will make a suggestion to the docs as you recommended.
you are clearly right, I apologize to all I may have offended. I got carried away with my frustration for seeing funny results from a complex (all in one integrated) formula that was indeed correct aside from the rad thing and not finding any hint as to why my system did give back different results than my calculator or excel had. The Intel memory bug from decades ago comes to mind you look at the difference in results and think WTF did I just do wrong and start taking your formula apart, one by one… Loosing a days worth of formula and code development due to a stupid copy paste error did not improve my mode either.