tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
406 stars 28 forks source link

trigonometric functions have confusing unit behavior #148

Closed xeniarose closed 2 months ago

xeniarose commented 12 months ago

The following in eval.rs clones the input units for all trig functions

https://github.com/tiffany352/rink-rs/blob/4a492c64f33f51a89a685d31365042d21cb4f0ed/core/src/runtime/eval.rs#L289-L348

this results in some confusing behavior when running trig functions with units

> sin(10 deg)
approx. 173.6481 milliradian (angle)
> atan2(5 ft, 2 ft)
approx. 1.190289 meter (length)

i think that the following behavior would make more sense:

if you think input unit constraints would be too much, implementing just the output unit changes would also be fine. i can make a PR for this if these changes are wanted

tiffany352 commented 2 months ago

Sorry it took so long to get around to this. I agree, this is a much better way to handle the units on these functions.