Skip to content

Commit

Permalink
Merge pull request #107 from ChrisRackauckas/patch-1
Browse files Browse the repository at this point in the history
add eps
  • Loading branch information
ajkeller34 authored Nov 21, 2017
2 parents 3254609 + aa625ef commit 2429f48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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
import Base: eps, mod, rem, div, fld, cld, trunc, round, sign, signbit
import Base: isless, isapprox, isinteger, isreal, isinf, isfinite, isnan
import Base: copysign, flipsign
import Base: prevfloat, nextfloat, maxintfloat, rat, step
Expand Down
3 changes: 3 additions & 0 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ isfinite(x::Quantity) = isfinite(x.val)
isinf(x::Quantity) = isinf(x.val)
isnan(x::Quantity) = isnan(x.val)

eps(x::T) where {T<:Quantity} = T(eps(x.val))
eps(x::Type{T}) where {T<:Quantity} = T(eps(Unitful.numtype(T)))

unsigned(x::Quantity) = Quantity(unsigned(x.val), unit(x))

for f in (:exp, :exp10, :exp2, :expm1, :log, :log10, :log1p, :log2)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ end
@test !isapprox(1.0u"m", 1.1u"m"; atol=50u"mm")
@test isapprox(1.0u"m", 1.1u"m"; rtol=0.2)
@test !isapprox(1.0u"m", 1.1u"m"; rtol=0.05)

# Test eps
@test eps(1.0u"s") == eps(1.0)u"s"
@test eps(typeof(1.0u"s")) == eps(Float64)u"s"

# Test promotion behavior
@test !isapprox(1.0u"m", 1.0u"s")
Expand Down

0 comments on commit 2429f48

Please sign in to comment.