JuliaPhysics / JuliaPhysics/Unitful.jl

`cosd` and radians

Open
#499 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

I would like to expose an interface where a user can specify an angle, with the default unit being degrees, but with the possibility to force radians if needed. For this, using `cosd` and `sind` in my function seems like the natural choice. Indeed, where the `cos` function means “cosine, with dimensionless numbers interpreted as radians”, I would expect `cosd` to mean “cosine, with dimensionless numbers interpreted as degrees”.

However, despite the fact that ` cos(1Unitful.rad)==cos(1) ≈ 0.54`, whereas `cos(1Unitful.°) ≈ 0.99984`, applying `cosd` to all three values returns the same value (0.99984). Inspecting with `@which` shows that `cosd(1Unitful.rad)` falls back to the `Base` definition, so this behaviour probably is not an explicit choice by `Unitful`. (Moreover, the fact that `cosd(1rad) == cosd(1°)` is deeply confusing, since these two angles are all but equal.)

So here is my suggestion: overload
```
Base.Math.cosd(u::Quantity{T,NoDims,typeof(rad)}) where{T} = cos(u)
```
(and likewise `sind`, `sincosd`)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the Base.Math.cosd dispatch for Unitful.Quantity values, using the proposed cosd method as the entry point. Check the corresponding sind and sincosd behavior as well. Done means radian quantities follow cos, while degree quantities retain degree-based behavior, with the three functions covered consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.