diff --git a/src/Unitful.jl b/src/Unitful.jl index badce2d0..0e10e990 100644 --- a/src/Unitful.jl +++ b/src/Unitful.jl @@ -14,7 +14,8 @@ end import Base: ==, <, <=, +, -, *, /, //, ^ import Base: show, convert import Base: abs, abs2, float, fma, muladd, inv, sqrt, cbrt -import Base: min, max, floor, ceil, log, log10, real, imag, conj +import Base: min, max, floor, ceil, real, imag, conj +import Base: exp, exp10, exp2, expm1, log, log10, log1p, log2 import Base: sin, cos, tan, cot, sec, csc, atan2, cis, vecnorm import Base: mod, rem, div, fld, cld, trunc, round, sign, signbit @@ -884,8 +885,9 @@ isnan(x::Quantity) = isnan(x.val) unsigned(x::Quantity) = Quantity(unsigned(x.val), unit(x)) -log(x::DimensionlessQuantity) = log(uconvert(NoUnits, x)) -log10(x::DimensionlessQuantity) = log10(uconvert(NoUnits, x)) +for f in (:exp, :exp10, :exp2, :expm1, :log, :log10, :log1p, :log2) + @eval ($f)(x::DimensionlessQuantity) = ($f)(uconvert(NoUnits, x)) +end real(x::Quantity) = Quantity(real(x.val), unit(x)) imag(x::Quantity) = Quantity(imag(x.val), unit(x)) diff --git a/test/runtests.jl b/test/runtests.jl index 1f697842..ddc324e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -509,6 +509,11 @@ end @test @inferred(cot(45°)) == 1 @test @inferred(atan2(m*sqrt(3),1m)) ≈ 60° end + @testset "> Exponentials and logarithms" begin + for f in (exp, exp10, exp2, expm1, log, log10, log1p, log2) + @test f(1.0 * u"m/dm") ≈ f(10) + end + end @testset "> Matrix inversion" begin @test inv([1 1; -1 1]u"nm") ≈ [0.5 -0.5; 0.5 0.5]u"nm^-1" end