rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.79k stars 177 forks source link

Trigonometric functions in the basic math package should use radians, not degrees #343

Closed Kezii closed 3 years ago

Kezii commented 3 years ago

Why :sob: please consider exposing the api for working with radians directly

https://github.com/rhaiscript/rhai/blob/e22bb35f821bb5721f7d6edd37c5b12592d7ff4f/src/packages/math_basic.rs#L115

schungx commented 3 years ago

Well, Rhai is designed to be a scripting language so ease of use is a larger concern. Rhai is not intended for serious scientific calculations.

schungx commented 3 years ago

I'll add to_radians and to_degrees for floating point numbers if that helps...

Kezii commented 3 years ago

Well, Rhai is designed to be a scripting language so ease of use is a larger concern. Rhai is not intended for serious scientific calculations.

Well, Rust uses radians, rhai takes a lot from rust, and I expected it to work in the same way in that regard Also, lua, python, javascript, java and basically all languages provide trigonometric function with radians, and there's a reason for it, I would argue that "ease of use" is there with radians, using degrees makes no sense 99% of the times, outside hand calculations

Note: the user that downvoted my original post has nothing to do with rust or rhai, he did that when I linked this issue on a chat group, please ignore

schungx commented 3 years ago

You've got a point.

However, to change this default will mean breaking scripts out there.

But still, it can be done if it is deemed a high enough value.

I'll remove wont fix and leave this here for a while to see if others have an opinion. I'll also ask on Discord.

schungx commented 3 years ago

A less scientific answer to why I originally started with degrees is that I did a fair bit of modelling on Excel and it was easier (and makes the formulas look simpler) to work with a 360 circle than 2*PI(). The trig functions in Excel taking radians always forced me to go thru conversions, which annoyed me. But that is probably my own personal experience.

schungx commented 3 years ago

https://github.com/rhaiscript/rhai/pull/347 does the change to radians, plus change the exponentiation operator to **.