Skip to content
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
1 change: 1 addition & 0 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Base: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, at
sinpi, cospi, sinc, cosc, cis, cispi, sincos
import Base: eps, mod, rem, div, fld, cld, divrem, trunc, round, sign, signbit
import Base: isless, isapprox, isinteger, isreal, isinf, isfinite, isnan
import Base: iseven, isodd
import Base: copysign, flipsign
import Base: prevfloat, nextfloat, maxintfloat, rat, step
import Base: length, float, last, one, oneunit, zero, range
Expand Down
6 changes: 4 additions & 2 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ end
_dimerr(f) = error("$f can only be well-defined for dimensionless ",
"numbers. For dimensionful numbers, different input units yield physically ",
"different results.")
isinteger(x::AbstractQuantity) = _dimerr(isinteger)
isinteger(x::DimensionlessQuantity) = isinteger(uconvert(NoUnits, x))
for f in [:isinteger, :iseven, :isodd]
@eval $f(x::AbstractQuantity) = _dimerr($f)
@eval $f(x::DimensionlessQuantity) = $f(uconvert(NoUnits, x))
end

_rounderr() = error("specify the type of the quantity to convert to ",
"when rounding quantities. Example: round(typeof(1u\"m\"), 137u\"cm\").")
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,20 @@ Base.:(<=)(x::Issue399, y::Issue399) = x.num <= y.num
@test_throws ErrorException isinteger(1.0m)
@test isinteger(1.4m/mm)
@test !isinteger(1.4mm/m)
@test_throws ErrorException iseven(1.0m)
@test iseven(2rad)
@test !iseven(1rad)
if hasmethod(iseven, (Float64,))
@test iseven(0.5m/mm)
@test !iseven(0.125m/mm)
end
@test_throws ErrorException isodd(1.0m)
@test isodd(1rad)
@test !isodd(2rad)
if hasmethod(isodd, (Float64,))
@test isodd(0.125m/mm)
@test !isodd(0.5m/mm)
end
@test isfinite(1.0m)
@test !isfinite(Inf*m)
@test isnan(NaN*m)
Expand Down
Loading