Skip to content

Commit 492c475

Browse files
deg2rad and rad2deg with "units" (#459)
* deg2rad and rad2deg * v1.9 * Update src/pkgdefaults.jl Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent 8d0db2a commit 492c475

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Unitful"
22
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
3-
version = "1.8.0"
3+
version = "1.9.0"
44

55
[deps]
66
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"

src/pkgdefaults.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ for (_x,_y) in ((:sin,:sind), (:cos,:cosd), (:tan,:tand),
7373
@eval ($_y)(x::Quantity{T, NoDims, typeof(°)}) where {T} = ($_y)(ustrip(x))
7474
end
7575

76+
# conversion between degrees and radians
77+
import Base: deg2rad, rad2deg
78+
deg2rad(d::Quantity{T, NoDims, typeof(°)}) where {T} = deg2rad(ustrip(°, d))u"rad"
79+
rad2deg(r::Quantity{T, NoDims, typeof(rad)}) where {T} = rad2deg(ustrip(rad, r))u"°"
80+
7681
# SI and related units
7782
@unit Hz "Hz" Hertz 1/s true
7883
@unit N "N" Newton 1kg*m/s^2 true

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ end
193193
@test 1u"rps" == 2π/s
194194
@test 1u"rpm" == 360°/minute
195195
@test 1u"rpm" == 2π/minute
196+
197+
# Issue 458:
198+
@test deg2rad(360°) 2π * rad
199+
@test rad2deg(2π * rad) 360°
196200
end
197201
end
198202
end

0 commit comments

Comments
 (0)