Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deg2rad and rad2deg with "units" #459

Merged
merged 4 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Unitful"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.8.0"
version = "1.9.0"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down
5 changes: 5 additions & 0 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ for (_x,_y) in ((:sin,:sind), (:cos,:cosd), (:tan,:tand),
@eval ($_y)(x::Quantity{T, NoDims, typeof(°)}) where {T} = ($_y)(ustrip(x))
end

# conversion between degrees and radians
import Base: deg2rad, rad2deg
deg2rad(d::Quantity{T, NoDims, typeof(°)}) where {T} = deg2rad(ustrip(d))u"rad"
rad2deg(r::Quantity{T, NoDims, typeof(rad)}) where {T} = rad2deg(ustrip(r))u"°"
JeffFessler marked this conversation as resolved.
Show resolved Hide resolved

# SI and related units
@unit Hz "Hz" Hertz 1/s true
@unit N "N" Newton 1kg*m/s^2 true
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ end
@test 1u"rps" == 2π/s
@test 1u"rpm" == 360°/minute
@test 1u"rpm" == 2π/minute

# Issue 458:
@test deg2rad(360°) ≈ 2π * rad
@test rad2deg(2π * rad) ≈ 360°
end
end
end
Expand Down