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

Add alias deg for ° #764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/src/defaultunits.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ The steradian, a unit of spherical angle. There are 4π sr in a sphere.

```
Unitful.°
Unitful.deg
```

The degree, a unit of angle. There are 360° in a circle.
Expand Down
5 changes: 5 additions & 0 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const AbsoluteScaleTemperature = Quantity{T, 𝚯, <:ScalarUnits} where T
\nThe degree, a unit of angle. There are 360° in a circle.
\nDimension: [`Unitful.NoDims`](@ref)."
@unit ° "°" Degree pi/180 false
" Unitful.deg
\nAlias for [`Unitful.°`](@ref).
\nThe degree, a unit of angle. There are 360 deg in a circle.
\nDimension: [`Unitful.NoDims`](@ref)."
const deg = °
# For numerical accuracy, specific to the degree
import Base: sind, cosd, tand, secd, cscd, cotd
for (_x,_y) in ((:sin,:sind), (:cos,:cosd), (:tan,:tand),
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Unitful:
ac,
mg, g, kg,
Ra, °F, °C, K,
rad, mrad, °,
rad, mrad, °, deg,
ms, s, minute, hr, d, yr, Hz,
J, A, N, mol, V, mJ, eV,
mW, W,
Expand Down Expand Up @@ -704,6 +704,7 @@ Base.:(<=)(x::Issue399, y::Issue399) = x.num <= y.num
@test zero(Quantity{Int, 𝐋}) isa Quantity{Int}
@test @inferred(π/2*u"rad" + 90u"°") ≈ π # Dimless quantities
@test @inferred(π/2*u"rad" - 90u"°") ≈ 0 # Dimless quantities
@test @inferred(90u"deg" - 90u"°") == 0
@test_throws DimensionError 1+1m # Dim mismatched
@test_throws DimensionError 1-1m
end
Expand Down Expand Up @@ -2288,6 +2289,10 @@ end
@test (1//2)Unitful.ϵ0 === (1//2)Unitful.ε0
@test Unitful.Å === Unitful.angstrom
@test 1.0Unitful.Å === 1.0Unitful.angstrom
@test Unitful.deg === Unitful.°
@test 2Unitful.° === 2Unitful.deg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test to ensure u"deg" also works?

@test u"deg" === u"°"
@test uparse("deg") === uparse("°")
end

module DocUnits
Expand Down