Skip to content

Commit 6527d67

Browse files
authored
Math operations with explicit types (#185)
When called with explicit type we should return a result of that type.
1 parent 8ec1d35 commit 6527d67

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/ColorVectorSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ end
221221
eps(::Type{Gray{T}}) where {T} = Gray(eps(T))
222222

223223
for f in (:trunc, :floor, :round, :ceil)
224-
@eval $f(::Type{T}, g::Gray) where {T<:Integer} = Gray{T}($f(T, gray(g)))
224+
@eval $f(::Type{T}, g::Gray) where {T<:Integer} = $f(T, gray(g))
225225
end
226226

227227
for f in (:mod, :rem, :mod1)

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ ColorTypes.comp2(c::RGBA32) = alpha(c)
300300
for g in (Gray{N0f8}(0.4), Gray{N0f8}(0.6))
301301
for op in (:trunc, :floor, :round, :ceil)
302302
v = @eval $op(Bool, gray($g))
303-
@test @eval($op(Bool, $g)) === Gray(v)
303+
@test @eval($op(Bool, $g)) === v
304+
end
305+
end
306+
for g in (Gray(1.4), Gray(1.6))
307+
for op in (:trunc, :floor, :round, :ceil)
308+
v = @eval $op(Int, gray($g))
309+
@test @eval($op(Int, $g)) === v
304310
end
305311
end
306312
for (g1, g2) in ((Gray(0.4), Gray(0.3)), (Gray(N0f8(0.4)), Gray(N0f8(0.3))))

0 commit comments

Comments
 (0)