diff --git a/src/display.jl b/src/display.jl index 249ad93f..5dfc27f2 100644 --- a/src/display.jl +++ b/src/display.jl @@ -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", diff --git a/src/pkgdefaults.jl b/src/pkgdefaults.jl index 09a38d47..cb1788a0 100644 --- a/src/pkgdefaults.jl +++ b/src/pkgdefaults.jl @@ -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 @@ -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. @@ -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. @@ -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 @@ -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, diff --git a/src/units.jl b/src/units.jl index a66a047d..f6a3f89a 100644 --- a/src/units.jl +++ b/src/units.jl @@ -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}() @@ -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) diff --git a/src/user.jl b/src/user.jl index 78c6c8fc..bf58373f 100644 --- a/src/user.jl +++ b/src/user.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index b667079d..405167fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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 @@ -1916,6 +1916,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 + module DocUnits using Unitful using Unitful: 𝐋