Skip to content

Commit

Permalink
Merge pull request #71 from giordano/exponential
Browse files Browse the repository at this point in the history
DimensionlessQuantity methods for exp, exp10, exp2, expm1, log1p, log2
  • Loading branch information
ajkeller34 authored Mar 28, 2017
2 parents 630e45c + c5ce3cb commit 94006dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94006dd

Please sign in to comment.