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

Remove unnecessary code related to encoding of μ #511

Merged
merged 4 commits into from
Jan 26, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const prefixdict = Dict(
-15 => "f",
-12 => "p",
-9 => "n",
-6 => "μ", # tab-complete \mu, not option-m on a Mac!
-6 => "μ",
-3 => "m",
-2 => "c",
-1 => "d",
Expand Down
15 changes: 5 additions & 10 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const ha = Unitful.FreeUnits{(Unitful.Unit{:Are, 𝐋^2}(2, 1//1),), 𝐋^2}()
\nDimension: 𝐋^3.
\nSee Also: [`Unitful.cm`](@ref)."
@unit L "L" Liter m^3//1000 true
for p in (:y, :z, :a, :f, :p, :n, :μ, :µ, :m, :c, :d,
for p in (:y, :z, :a, :f, :p, :n, :μ, :m, :c, :d,
Symbol(""), :da, :h, :k, :M, :G, :T, :P, :E, :Z, :Y)
Core.eval(Unitful, :(const $(Symbol(p,:l)) = $(Symbol(p,:L))))
end
Expand Down Expand Up @@ -388,15 +388,14 @@ const c0 = 299_792_458*m/s # exact
\nA quantity representing the vacuum permeability constant, defined as 4π × 10^-7 H / m.
\nDimension: 𝐋 𝐌 𝐈^-2 𝐓^-2.
\nSee also: [`Unitful.H`](@ref), [`Unitful.m`](@ref)."
const μ0 = 4π*(1//10)^7*H/m # exact (but gets promoted to Float64...)
const µ0 = μ0 # magnetic constant
const μ0 = 4π*(1//10)^7*H/m # exact (but gets promoted to Float64...), magnetic constant
" Unitful.ε0
Unitful.ϵ0
\nA quantity representing the vacuum permittivity constant, defined as 1 / (μ0 × c^2).
\nDimension: 𝐈^2 𝐓^4 𝐋^-3 𝐌^-1.
\nSee also: [`Unitful.μ0`](@ref), [`Unitful.c`](@ref)."
const ɛ0 = 1/(μ0*c^2) # exact, electric constant; changes here may affect
@doc @doc(ɛ0) const ϵ0 = ɛ0 # test of issue 79.
const ε0 = 1/(μ0*c^2) # exact, electric constant; changes here may affect
@doc @doc(ε0) const ϵ0 = ε0 # test of issue 79.
" Unitful.Z0
\nA quantity representing the impedance of free space, a constant defined as μ0 × c.
\nDimension: 𝐋^2 𝐌 𝐈^-2 𝐓^-3.
Expand Down Expand Up @@ -455,7 +454,6 @@ const mp = 1.672_621_923_69e-27*kg # (51) proton rest mass
\nDimension: 𝐈 𝐋^2.
\nSee also: [`Unitful.q`](@ref), [`Unitful.ħ`](@ref), [`Unitful.me`](@ref)."
const μB = q*ħ/(2*me) # Bohr magneton
const µB = μB
" Unitful.Na
\nA quantity representing Avogadro's constant, defined as exactly
6.022,140,76 × 10^23 / mol.
Expand Down Expand Up @@ -682,8 +680,6 @@ earth, a unit of acceleration, defined by standard to be exactly 9.806,65 m / s^
@logunit dBΩ "dBΩ" Decibel 1Ω
@logunit dBS "dBS" Decibel 1S

const dBµV = dBμV # different character encoding of μ

# TODO: some more dimensions?
isrootpower_dim(::typeof(dimension(W))) = false
isrootpower_dim(::typeof(dimension(V))) = true
Expand All @@ -706,8 +702,7 @@ isrootpower_dim(::typeof(dimension(J))) = false
# - Candela conflicts with `Base.cd` so it is not brought in (issue #102)
# - Degrees: °

# The following line has two different character encodings for μ
const si_prefixes = (:y, :z, :a, :f, :p, :n, :μ, :µ, :m, :c, :d,
const si_prefixes = (:y, :z, :a, :f, :p, :n, :μ, :m, :c, :d,
Symbol(""), :da, :h, :k, :M, :G, :T, :P, :E, :Z, :Y)

const si_no_prefix = (:m, :s, :A, :K, :g, :mol, :rad, :sr, :Hz, :N, :Pa, #:cd,
Expand Down
6 changes: 3 additions & 3 deletions src/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
sort!(linunits, by=x->tens(x))
sort!(linunits, by=x->name(x))

# [m,m,cm,cm^2,cm^3,nm,m^4,µs,µs^2,s]
# [m,m,cm,cm^2,cm^3,nm,m^4,μs,μs^2,s]
# reordered as:
# [nm,cm,cm^2,cm^3,m,m,m^4,µs,µs^2,s]
# [nm,cm,cm^2,cm^3,m,m,m^4,μs,μs^2,s]

# Collect powers of a given unit into `c`
c = Vector{Unit}()
Expand All @@ -46,7 +46,7 @@
end
end
# results in:
# [nm,cm^6,m^6,µs^3,s]
# [nm,cm^6,m^6,μs^3,s]

d = (c...,)
f = mapreduce(dimension, *, d; init=NoDims)
Expand Down
8 changes: 0 additions & 8 deletions src/user.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,6 @@ macro prefixed_unit_symbols(symb,name,user_dimension,basefactor,autodocs=false)
push!(expr.args, ea)
end

# These lines allow for μ to be typed with option-m on a Mac.
s = Symbol(:µ, symb)
u = :($Unit{$n, $user_dimension}(-6,1//1))
push!(expr.args, quote
$(basefactors_expr(__module__, n, basefactor))
const global $s = $FreeUnits{($u,), $dimension($u), $nothing}()
end)

esc(expr)
end

Expand Down
23 changes: 21 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ end
@test uconvert(g, 1*FixedUnits(kg)) == 1000g # manual conversion okay
@test (1kg, 2g, 3mg, missing) .|> g === (1000g, 2g, (3//1000)g, missing)
# Issue 79:
@test isapprox(upreferred(Unitful.ɛ0), 8.85e-12u"F/m", atol=0.01e-12u"F/m")
@test isapprox(upreferred(Unitful.ε0), 8.85e-12u"F/m", atol=0.01e-12u"F/m")
# Issue 261:
@test 1u"rps" == 360°/s
@test 1u"rps" == 2π/s
Expand Down Expand Up @@ -695,7 +695,7 @@ end

@test @inferred(sinh(0.0rad)) == 0.0
@test @inferred(sinh(1J/N/m) + cosh(1rad)) ≈ MathConstants.e
@test @inferred(tanh(1m/1µm)) == 1
@test @inferred(tanh(1m/1μm)) == 1
@test @inferred(csch(0.0°)) == Inf
@test @inferred(sech(0K/Ra)) == 1
@test @inferred(coth(1e3m*mm^-1)) == 1
Expand Down Expand Up @@ -1849,6 +1849,25 @@ end
end
end

@testset "Encoding" begin
# Julia treats µ (U+00B5) and μ (U+03BC) as the same
@test Unitful.µ0 === Unitful.μ0
@test Unitful.µm === Unitful.μm
@test Unitful.dBµV === Unitful.dBμV
@test u"µ0" === u"μ0"
@test u"µm" === u"μm"
@test u"dBµV" === u"dBμV"
@test uparse("µ0") === uparse("μ0")
@test uparse("µm") === uparse("μm")
@test uparse("dBµV") === uparse("dBμV")
@test @doc(Unitful.µm) == @doc(Unitful.μm)
# Julia treats ɛ (U+025B) and ε (U+03B5) as the same
@test Unitful.ɛ0 === Unitful.ε0
@test u"ɛ0" === u"ε0"
@test uparse("ɛ0") === uparse("ε0")
@test @doc(Unitful.ɛ0) == @doc(Unitful.ε0)
end

Comment on lines +1852 to +1870
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I’m not convinced we need these tests. We could just remove them.

module DocUnits
using Unitful
using Unitful: 𝐋
Expand Down