Rules DSL cannot do math

Hey,

strange problem, maybe I need some math lessons.
When i try to calculate some cos… there is something wrong.

This

var Number SunAngle = SunElevation.state as Number
logInfo("SundAngle", SunAngle + "")
SunAngle = Math::cos(SunAngle.doubleValue())
logInfo("Cos SunAngle",  SunAngle + "")

gives as a Result:

2025-07-01 20:11:43.508 [INFO ] [.openhab.core.model.script.SundAngle] - 10.413343240575136
2025-07-01 20:11:43.509 [INFO ] [enhab.core.model.script.Cos SunAngle] - -0.5498887588069448

Sun Elevation is from the Astro Binding.

cos(10) should not be under zero…

Best Regars
Alex

Math::cos(x) expect x as radians.
So cos(10) = -0.8 results in a negativ value.

If you want cos(x) from x as angle you have to convert x in radians before:
Math::toRadians()

Thanks, seems like 35° made me forget about radians :smiley:

And you don’t mean the angle, but the temperature :grinning_face: